Release bgit v0.3.6 #19
Workflow file for this run
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 (tag) | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| permissions: | |
| contents: write | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| build: | |
| name: Build ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| steps: | |
| - name: Check out repository code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install Rust toolchain | |
| uses: actions-rust-lang/setup-rust-toolchain@v1 | |
| - name: Install cross (Linux-only) | |
| if: matrix.os == 'ubuntu-latest' | |
| uses: taiki-e/install-action@v2 | |
| with: | |
| tool: cross | |
| - name: Verify tag matches Cargo.toml version (Unix) | |
| if: runner.os != 'Windows' | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| TAG_NAME="${{ github.ref_name }}" # e.g., v0.3.1 | |
| TAG_VER="${TAG_NAME#v}" | |
| CARGO_VER=$(grep -E '^version\s*=\s*"' Cargo.toml | head -n1 | sed -E 's/.*"([^"]+)".*/\1/') | |
| echo "Tag: $TAG_NAME | Version in Cargo.toml: $CARGO_VER" | |
| if [ "$TAG_VER" != "$CARGO_VER" ]; then | |
| echo "Tag ($TAG_NAME) does not match Cargo.toml version ($CARGO_VER)." >&2 | |
| exit 1 | |
| fi | |
| - name: Verify tag matches Cargo.toml version (Windows) | |
| if: runner.os == 'Windows' | |
| shell: pwsh | |
| run: | | |
| $ErrorActionPreference = 'Stop' | |
| $TagName = '${{ github.ref_name }}' | |
| $TagVer = $TagName.TrimStart('v') | |
| $line = Select-String -Path Cargo.toml -Pattern '^version\s*=\s*"' | Select-Object -First 1 | |
| if (-not $line) { throw 'Could not find version in Cargo.toml' } | |
| $CargoVer = ($line.Line -replace '.*"([^"]+)".*', '$1') | |
| "Tag: $TagName | Version in Cargo.toml: $CargoVer" | Write-Host | |
| if ($TagVer -ne $CargoVer) { | |
| throw "Tag ($TagName) does not match Cargo.toml version ($CargoVer)." | |
| } | |
| - name: Build (release) | |
| run: cargo build --locked --release | |
| - name: Build extra targets (Linux musl via cross) | |
| if: matrix.os == 'ubuntu-latest' | |
| run: | | |
| set -eux | |
| export PKG_CONFIG_ALLOW_CROSS=1 | |
| export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=gcc | |
| cross build --locked --release --target x86_64-unknown-linux-musl | |
| - name: Package artifact (Unix Linux host) | |
| if: matrix.os == 'ubuntu-latest' | |
| run: | | |
| set -eux | |
| TAG_NAME="${{ github.ref_name }}" # e.g., v0.3.1 | |
| BIN_NAME="bgit" | |
| ART_DIR="dist" | |
| mkdir -p "$ART_DIR" | |
| # Binary path | |
| BIN_PATH="target/release/${BIN_NAME}" | |
| test -x "$BIN_PATH" | |
| ARCH=$(uname -m) | |
| ARCHIVE_NAME="${BIN_NAME}-${TAG_NAME}-${{ matrix.os }}-${ARCH}.tar.gz" | |
| tar -C target/release -czf "$ART_DIR/$ARCHIVE_NAME" "$BIN_NAME" | |
| # Checksums | |
| (cd "$ART_DIR"; if command -v sha256sum >/dev/null 2>&1; then sha256sum "$ARCHIVE_NAME" > "$ARCHIVE_NAME.sha256"; else shasum -a 256 "$ARCHIVE_NAME" > "$ARCHIVE_NAME.sha256"; fi) | |
| - name: Package artifact (Linux musl) | |
| if: matrix.os == 'ubuntu-latest' | |
| run: | | |
| set -eux | |
| TAG_NAME="${{ github.ref_name }}" # e.g., v0.3.1 | |
| BIN_NAME="bgit" | |
| ART_DIR="dist" | |
| mkdir -p "$ART_DIR" | |
| BIN_PATH="target/x86_64-unknown-linux-musl/release/${BIN_NAME}" | |
| test -x "$BIN_PATH" | |
| ARCHIVE_NAME="${BIN_NAME}-${TAG_NAME}-${{ matrix.os }}-x86_64-musl.tar.gz" | |
| tar -C target/x86_64-unknown-linux-musl/release -czf "$ART_DIR/$ARCHIVE_NAME" "$BIN_NAME" | |
| (cd "$ART_DIR"; sha256sum "$ARCHIVE_NAME" > "$ARCHIVE_NAME.sha256") | |
| - name: Package artifact (macOS host) | |
| if: matrix.os == 'macos-latest' | |
| run: | | |
| set -eux | |
| TAG_NAME="${{ github.ref_name }}" # e.g., v0.3.1 | |
| BIN_NAME="bgit" | |
| ART_DIR="dist" | |
| mkdir -p "$ART_DIR" | |
| BIN_PATH="target/release/${BIN_NAME}" | |
| test -x "$BIN_PATH" | |
| ARCH=$(uname -m) | |
| ARCHIVE_NAME="${BIN_NAME}-${TAG_NAME}-${{ matrix.os }}-${ARCH}.tar.gz" | |
| tar -C target/release -czf "$ART_DIR/$ARCHIVE_NAME" "$BIN_NAME" | |
| (cd "$ART_DIR"; shasum -a 256 "$ARCHIVE_NAME" > "$ARCHIVE_NAME.sha256") | |
| - name: Package artifact (Windows) | |
| if: runner.os == 'Windows' | |
| shell: pwsh | |
| run: | | |
| $ErrorActionPreference = 'Stop' | |
| $Tag = '${{ github.ref_name }}' | |
| $Bin = 'bgit.exe' | |
| $ArtDir = 'dist' | |
| New-Item -ItemType Directory -Force -Path $ArtDir | Out-Null | |
| $BinPath = Join-Path 'target\release' $Bin | |
| if (-Not (Test-Path $BinPath)) { throw "Binary not found: $BinPath" } | |
| $Arch = $env:PROCESSOR_ARCHITECTURE | |
| $Archive = "bgit-$Tag-${{ matrix.os }}-$Arch.zip" | |
| Compress-Archive -Path $BinPath -DestinationPath (Join-Path $ArtDir $Archive) -Force | |
| # sha256 | |
| $sha = (Get-FileHash (Join-Path $ArtDir $Archive) -Algorithm SHA256).Hash.ToLower() | |
| Set-Content -Path (Join-Path $ArtDir "$Archive.sha256") -Value "$sha $Archive" | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: bgit-${{ github.ref_name }}-${{ matrix.os }} | |
| path: | | |
| dist/* | |
| if-no-files-found: error | |
| release: | |
| name: Create GitHub Release | |
| needs: [build] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Extract release notes from CHANGELOG.md | |
| id: changelog | |
| run: | | |
| set -euo pipefail | |
| TAG_NAME="${{ github.ref_name }}" # e.g., v0.3.1 | |
| echo "Preparing release notes for $TAG_NAME" | |
| # Extract section starting at header '## vX.Y.Z' (optionally with date) until next '## ' | |
| # Keep heading in the notes | |
| awk -v tag="$TAG_NAME" ' | |
| $0 ~ "^##[[:space:]]+" tag "([[:space:](]|$)" {flag=1; next} # match tag header and skip it | |
| flag && $0 ~ /^##[[:space:]]/ {flag=0} | |
| flag {print} | |
| ' CHANGELOG.md > RELEASE_NOTES.md || true | |
| if [ ! -s RELEASE_NOTES.md ]; then | |
| echo "Could not find changelog section for $TAG_NAME. Using fallback notes." >&2 | |
| printf "# %s\n\nSee CHANGELOG.md for details." "$TAG_NAME" > RELEASE_NOTES.md | |
| fi | |
| echo "notes_path=RELEASE_NOTES.md" >> "$GITHUB_OUTPUT" | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: bgit-${{ github.ref_name }}-* | |
| path: artifacts | |
| merge-multiple: true | |
| - name: List artifacts | |
| run: | | |
| ls -lah artifacts || true | |
| - name: Prepare release files dir | |
| run: | | |
| set -eux | |
| mkdir -p release | |
| cp -v artifacts/* release/ | |
| - name: Generate aggregate checksums (RELEASES.txt) | |
| run: | | |
| set -eux | |
| cd release | |
| rm -f RELEASES.txt | |
| if command -v sha256sum >/dev/null 2>&1; then | |
| for f in *.{tar.gz,zip}; do [ -f "$f" ] && sha256sum "$f" >> RELEASES.txt; done | |
| else | |
| for f in *.{tar.gz,zip}; do [ -f "$f" ] && shasum -a 256 "$f" >> RELEASES.txt; done | |
| fi | |
| - name: Create GitHub Release and upload assets | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| draft: false | |
| prerelease: false | |
| tag_name: ${{ github.ref_name }} | |
| name: ${{ github.ref_name }} | |
| body_path: ${{ steps.changelog.outputs.notes_path }} | |
| files: | | |
| release/* | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |