Release #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release_type: | |
| description: 'Release type' | |
| required: true | |
| type: choice | |
| options: | |
| - bugfix | |
| - feature | |
| - major | |
| env: | |
| CARGO_TERM_COLOR: always | |
| PAGES_URL: "https://oposs.github.io/edaptor" | |
| jobs: | |
| version: | |
| name: Bump Version | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| tag: ${{ steps.version.outputs.tag }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Verify main branch | |
| run: | | |
| if [ "${{ github.ref }}" != "refs/heads/main" ]; then | |
| echo "::error::Releases must be created from the main branch" | |
| exit 1 | |
| fi | |
| - name: Calculate new version | |
| id: version | |
| run: | | |
| LATEST=$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' | sort -V | tail -1 || echo "v0.0.0") | |
| if [ -z "$LATEST" ]; then | |
| LATEST="v0.0.0" | |
| fi | |
| MAJOR=$(echo "$LATEST" | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\1/') | |
| MINOR=$(echo "$LATEST" | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\2/') | |
| PATCH=$(echo "$LATEST" | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\3/') | |
| case "${{ inputs.release_type }}" in | |
| major) | |
| NEW_VERSION="$((MAJOR+1)).0.0" | |
| ;; | |
| feature) | |
| NEW_VERSION="${MAJOR}.$((MINOR+1)).0" | |
| ;; | |
| bugfix) | |
| NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH+1))" | |
| ;; | |
| esac | |
| echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT | |
| echo "tag=v${NEW_VERSION}" >> $GITHUB_OUTPUT | |
| echo "New version: ${NEW_VERSION}" | |
| - name: Update Cargo.toml version | |
| run: | | |
| sed -i 's/^version = ".*"/version = "${{ steps.version.outputs.version }}"/' Cargo.toml | |
| - name: Update CHANGES.md | |
| run: | | |
| DATE=$(date +%Y-%m-%d) | |
| VERSION="${{ steps.version.outputs.version }}" | |
| perl -i -0777 -pe ' | |
| s/## Unreleased\n+(### New\n(.*?))?(\n### Changed\n(.*?))?(\n### Fixed\n(.*?))?\n+(?=##|\z)/ | |
| "## Unreleased\n\n### New\n\n### Changed\n\n### Fixed\n\n" . | |
| "## '"$VERSION"' - '"$DATE"'\n" . | |
| ($2 ? "\n### New\n$2" : "") . | |
| ($4 ? "\n### Changed\n$4" : "") . | |
| ($6 ? "\n### Fixed\n$6" : "") . | |
| "\n" | |
| /se' CHANGES.md | |
| - name: Commit and tag | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add Cargo.toml CHANGES.md | |
| git commit -m "Release ${{ steps.version.outputs.tag }}" | |
| git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}" | |
| git push origin main --tags | |
| build-binaries: | |
| name: Build ${{ matrix.target }} | |
| needs: version | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| include: | |
| - target: x86_64-unknown-linux-musl | |
| os: ubuntu-latest | |
| archive: tar.gz | |
| cross: true | |
| rustflags: "-C target-feature=+crt-static" | |
| - target: aarch64-unknown-linux-musl | |
| os: ubuntu-latest | |
| archive: tar.gz | |
| cross: true | |
| rustflags: "-C target-feature=+crt-static" | |
| - target: x86_64-unknown-illumos | |
| os: ubuntu-latest | |
| archive: tar.gz | |
| cross: true | |
| rustflags: "" | |
| - target: x86_64-apple-darwin | |
| os: macos-latest | |
| archive: tar.gz | |
| - target: aarch64-apple-darwin | |
| os: macos-latest | |
| archive: tar.gz | |
| - target: x86_64-pc-windows-msvc | |
| os: windows-latest | |
| archive: zip | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.version.outputs.tag }} | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install cross (Linux musl, illumos) | |
| if: matrix.cross | |
| run: cargo install cross --git https://github.com/cross-rs/cross | |
| - name: Build binary | |
| run: | | |
| if [ "${{ matrix.cross }}" = "true" ]; then | |
| RUSTFLAGS="${{ matrix.rustflags }}" cross build --release --target ${{ matrix.target }} | |
| else | |
| cargo build --release --target ${{ matrix.target }} | |
| fi | |
| shell: bash | |
| - name: Create archive (Unix) | |
| if: matrix.archive == 'tar.gz' | |
| run: | | |
| mkdir -p dist | |
| BINARY="target/${{ matrix.target }}/release/edaptor" | |
| ARCHIVE="edaptor-${{ needs.version.outputs.version }}-${{ matrix.target }}.tar.gz" | |
| mkdir -p staging/edaptor | |
| cp "$BINARY" staging/edaptor/ | |
| cp -r examples staging/edaptor/ 2>/dev/null || true | |
| cp README.md staging/edaptor/ | |
| cp LICENSE staging/edaptor/ | |
| tar -czvf "dist/${ARCHIVE}" -C staging edaptor | |
| echo "ARCHIVE=${ARCHIVE}" >> $GITHUB_ENV | |
| shell: bash | |
| - name: Create archive (Windows) | |
| if: matrix.archive == 'zip' | |
| run: | | |
| mkdir dist | |
| $BINARY = "target/${{ matrix.target }}/release/edaptor.exe" | |
| $ARCHIVE = "edaptor-${{ needs.version.outputs.version }}-${{ matrix.target }}.zip" | |
| mkdir staging/edaptor | |
| Copy-Item $BINARY staging/edaptor/ | |
| Copy-Item -Recurse examples staging/edaptor/ -ErrorAction SilentlyContinue | |
| Copy-Item README.md staging/edaptor/ | |
| Copy-Item LICENSE staging/edaptor/ | |
| Compress-Archive -Path staging/edaptor -DestinationPath "dist/$ARCHIVE" | |
| echo "ARCHIVE=$ARCHIVE" >> $env:GITHUB_ENV | |
| shell: pwsh | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: edaptor-${{ matrix.target }} | |
| path: dist/* | |
| create-release: | |
| name: Create GitHub Release | |
| needs: [version, build-binaries] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.version.outputs.tag }} | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| pattern: edaptor-* | |
| merge-multiple: true | |
| - name: Extract release notes | |
| id: changelog | |
| run: | | |
| VERSION="${{ needs.version.outputs.version }}" | |
| NOTES=$(sed -n "/^## ${VERSION}/,/^## [0-9]/p" CHANGES.md | sed '$d') | |
| echo "$NOTES" > release-notes.md | |
| echo "Release notes:" | |
| cat release-notes.md | |
| - name: List artifacts | |
| run: ls -la artifacts/ | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ needs.version.outputs.tag }} | |
| name: edaptor ${{ needs.version.outputs.tag }} | |
| body_path: release-notes.md | |
| files: artifacts/* | |
| fail_on_unmatched_files: true | |
| draft: false | |
| prerelease: false | |
| build-docs: | |
| name: Build Release Documentation | |
| needs: version | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.version.outputs.tag }} | |
| - name: Install mdBook and plugins | |
| run: | | |
| mkdir -p ~/bin | |
| curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.5.2/mdbook-v0.5.2-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C ~/bin | |
| curl -sSL https://github.com/badboy/mdbook-mermaid/releases/download/v0.17.0/mdbook-mermaid-v0.17.0-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C ~/bin | |
| echo "$HOME/bin" >> $GITHUB_PATH | |
| - name: Setup mermaid assets | |
| run: mdbook-mermaid install docs | |
| - name: Build documentation | |
| working-directory: docs | |
| run: mdbook build | |
| - name: Upload docs artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: docs-release | |
| path: docs/book | |
| retention-days: 1 | |
| deploy-docs: | |
| name: Deploy Release Documentation | |
| needs: [version, build-docs, create-release] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| sparse-checkout: .github/scripts | |
| - name: Download docs artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: docs-release | |
| path: new-docs | |
| - name: Mirror existing GitHub Pages | |
| run: | | |
| mkdir -p site | |
| wget --mirror --no-parent --no-host-directories \ | |
| --directory-prefix=site \ | |
| --reject="index.html?*" \ | |
| --execute robots=off \ | |
| --quiet \ | |
| "$PAGES_URL/" 2>/dev/null || echo "No existing site to mirror" | |
| find site -name "*.tmp" -delete 2>/dev/null || true | |
| find site -name "index.html\?*" -delete 2>/dev/null || true | |
| echo "Existing site contents:" | |
| ls -la site/edaptor/ 2>/dev/null || echo "(empty or no edaptor dir)" | |
| - name: Add new version to site | |
| run: | | |
| VERSION="${{ needs.version.outputs.tag }}" | |
| mkdir -p "site/edaptor/$VERSION" | |
| cp -r new-docs/* "site/edaptor/$VERSION/" | |
| echo "Added version $VERSION" | |
| - name: Update versions and redirect | |
| run: | | |
| chmod +x .github/scripts/manage-doc-versions.sh | |
| .github/scripts/manage-doc-versions.sh site/edaptor cull | |
| .github/scripts/manage-doc-versions.sh site/edaptor update-json | |
| .github/scripts/manage-doc-versions.sh site/edaptor generate-redirect | |
| - name: Show final site structure | |
| run: | | |
| echo "Final site structure:" | |
| ls -la site/edaptor/ | |
| echo "" | |
| echo "versions.json:" | |
| cat site/edaptor/versions.json | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v4 | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: site/edaptor | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |