name: Release
on:
push:
tags:
- 'v*.*.*'
env:
CARGO_TERM_COLOR: always
jobs:
test:
name: Test before release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Setup Git (required for tests)
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
- name: Run tests
run: cargo test --verbose
- name: Build release binary for integration tests
run: cargo build --release
- name: Make integration test script executable
run: chmod +x ./integration_test.sh
- name: Run integration tests
run: ./integration_test.sh
build:
name: Build and Release
needs: test
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
binary_name: git-pair
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
binary_name: git-pair
- os: macos-latest
target: x86_64-apple-darwin
binary_name: git-pair
- os: macos-latest
target: aarch64-apple-darwin
binary_name: git-pair
- os: windows-latest
target: x86_64-pc-windows-msvc
binary_name: git-pair.exe
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install musl-tools (Linux musl only)
if: matrix.target == 'x86_64-unknown-linux-musl'
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Build release binary
run: cargo build --release --target ${{ matrix.target }}
- name: Strip binary (Unix only)
if: matrix.os != 'windows-latest'
run: strip target/${{ matrix.target }}/release/${{ matrix.binary_name }}
- name: Package binary
shell: bash
run: |
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
cp target/${{ matrix.target }}/release/${{ matrix.binary_name }} .
7z a git-pair-${{ matrix.target }}.zip ${{ matrix.binary_name }}
else
cp target/${{ matrix.target }}/release/${{ matrix.binary_name }} .
tar -czf git-pair-${{ matrix.target }}.tar.gz ${{ matrix.binary_name }}
fi
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: git-pair-${{ matrix.target }}
path: |
git-pair-${{ matrix.target }}.tar.gz
git-pair-${{ matrix.target }}.zip
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Get version from tag
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Extract changelog for this version
id: changelog
run: |
if [ -f CHANGELOG.md ]; then
# Extract changelog section for this version
awk '/^## \[${{ steps.version.outputs.VERSION }}\]/{flag=1; next} /^## \[/{flag=0} flag' CHANGELOG.md > release_notes.md
if [ ! -s release_notes.md ]; then
echo "Changes in ${{ steps.version.outputs.VERSION }}" > release_notes.md
fi
else
echo "Release ${{ steps.version.outputs.VERSION }}" > release_notes.md
echo "" >> release_notes.md
echo "## What's Changed" >> release_notes.md
echo "See the full changelog for details." >> release_notes.md
fi
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.version.outputs.VERSION }}
name: Release ${{ steps.version.outputs.VERSION }}
body_path: release_notes.md
draft: false
prerelease: false
files: |
git-pair-x86_64-unknown-linux-gnu/git-pair-x86_64-unknown-linux-gnu.tar.gz
git-pair-x86_64-unknown-linux-musl/git-pair-x86_64-unknown-linux-musl.tar.gz
git-pair-x86_64-apple-darwin/git-pair-x86_64-apple-darwin.tar.gz
git-pair-aarch64-apple-darwin/git-pair-aarch64-apple-darwin.tar.gz
git-pair-x86_64-pc-windows-msvc/git-pair-x86_64-pc-windows-msvc.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-crate:
name: Publish to crates.io
needs: test
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Publish to crates.io
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
continue-on-error: true