name: Release
on:
push:
branches: [master]
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.version.outputs.changed }}
version: ${{ steps.version.outputs.current }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check if version changed
id: version
run: |
CURRENT_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
git show HEAD~1:Cargo.toml > /tmp/old_cargo.toml 2>/dev/null || echo 'version = "0.0.0"' > /tmp/old_cargo.toml
OLD_VERSION=$(grep '^version' /tmp/old_cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "old=$OLD_VERSION" >> $GITHUB_OUTPUT
if [ "$CURRENT_VERSION" != "$OLD_VERSION" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "Version changed: $OLD_VERSION -> $CURRENT_VERSION"
else
echo "changed=false" >> $GITHUB_OUTPUT
echo "Version unchanged: $CURRENT_VERSION"
fi
build:
needs: check-version
if: needs.check-version.outputs.changed == 'true'
name: Build ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
name: linux-amd64
cross: false
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
name: linux-arm64
cross: true
- target: x86_64-apple-darwin
os: macos-latest
name: darwin-amd64
cross: false
- target: aarch64-apple-darwin
os: macos-latest
name: darwin-arm64
cross: false
- target: x86_64-pc-windows-msvc
os: windows-latest
name: windows-amd64
cross: false
steps:
- uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross
if: matrix.cross
run: cargo install cross
- name: Build
shell: bash
run: |
if [ "${{ matrix.cross }}" = "true" ]; then
cross build --release --target ${{ matrix.target }}
else
cargo build --release --target ${{ matrix.target }}
fi
- name: Package (Unix)
if: runner.os != 'Windows'
run: |
cd target/${{ matrix.target }}/release
tar czf ../../../rsbuild-${{ matrix.name }}.tar.gz rsbuild
- name: Package (Windows)
if: runner.os == 'Windows'
shell: bash
run: |
cd target/${{ matrix.target }}/release
7z a ../../../rsbuild-${{ matrix.name }}.zip rsbuild.exe
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: rsbuild-${{ matrix.name }}
path: rsbuild-${{ matrix.name }}.*
release:
needs: [check-version, build]
if: always() && needs.check-version.outputs.changed == 'true' && !contains(needs.build.result, 'cancelled')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create tag
run: |
git tag "v${{ needs.check-version.outputs.version }}"
git push origin "v${{ needs.check-version.outputs.version }}"
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.check-version.outputs.version }}
name: v${{ needs.check-version.outputs.version }}
generate_release_notes: true
files: artifacts/*
publish:
needs: check-version
if: needs.check-version.outputs.changed == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_TOKEN }}
run: cargo publish --allow-dirty