Release #6
This file contains 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: | |
permissions: | |
contents: write | |
jobs: | |
verify-branch: | |
name: Verify that runs on the main branch | |
runs-on: ubuntu-latest | |
steps: | |
- name: Fail if branch is not main | |
if: github.ref != 'refs/heads/main' | |
run: | | |
echo "The release workflow should only be triggered on the main branch" | |
exit 1 | |
get-version: | |
name: Get version from Cargo.toml | |
needs: verify-branch | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.version.outputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get version from Cargo.toml | |
id: lookupVersion | |
uses: mikefarah/yq@bc5b54cb1d1f720db16c9f75c5b45384d00e5cbf | |
with: | |
cmd: yq -oy '"v" + .workspace.package.version' 'Cargo.toml' | |
- name: Print version | |
id: version | |
run: | | |
VERSION=${{ steps.lookupVersion.outputs.result }} | |
echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
build-binaries: | |
name: Build ${{ matrix.target }} | |
needs: get-version | |
runs-on: ${{ matrix.os }} | |
env: | |
# Cross-compiled targets will override this to `cross`. | |
CARGO: cargo | |
strategy: | |
matrix: | |
include: | |
- target: x86_64-unknown-linux-gnu | |
os: ubuntu-latest | |
cross: true | |
- target: x86_64-unknown-linux-musl | |
os: ubuntu-latest | |
cross: true | |
- target: aarch64-unknown-linux-gnu | |
os: ubuntu-latest | |
cross: true | |
- target: aarch64-unknown-linux-musl | |
os: ubuntu-latest | |
cross: true | |
- target: x86_64-apple-darwin | |
os: macos-latest | |
- target: aarch64-apple-darwin | |
os: macos-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@315e265cd78dad1e1dcf3a5074f6d6c47029d5aa | |
with: | |
toolchain: stable | |
target: ${{ matrix.target }} | |
- uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab | |
- name: Install cross | |
if: matrix.cross | |
uses: taiki-e/install-action@cross | |
- name: Enable cross-compilation | |
if: matrix.cross | |
shell: bash | |
run: | | |
echo "CARGO=cross" >> $GITHUB_ENV | |
- name: Build | |
run: ${{ env.CARGO }} build --release --locked --target ${{ matrix.target }} | |
- name: Package | |
shell: bash | |
run: | | |
set -euxo pipefail | |
PKG_FULL_NAME="cairo-coverage-${{ needs.get-version.outputs.version }}-${{ matrix.target }}" | |
echo "PKG_FULL_NAME=$PKG_FULL_NAME" >> $GITHUB_ENV | |
bash ./scripts/package.sh "${{ matrix.target }}" "$PKG_FULL_NAME" | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-${{ matrix.target }} | |
path: ${{ env.PKG_FULL_NAME }}.* | |
create-release: | |
name: Create release | |
runs-on: ubuntu-latest | |
needs: [ build-binaries, get-version ] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: artifacts-dl | |
- name: Unpack artifacts to staging directory | |
run: | | |
mkdir -p artifacts | |
mv artifacts-dl/build-*/cairo-coverage-* artifacts/ | |
- name: Create GitHub release | |
id: create-release | |
uses: taiki-e/create-gh-release-action@72d65cee1f8033ef0c8b5d79eaf0c45c7c578ce3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
changelog: CHANGELOG.md | |
allow-missing-changelog: true | |
title: $version | |
ref: refs/tags/${{ needs.get-version.outputs.version }} | |
- name: Upload artifacts to the release | |
working-directory: artifacts | |
run: gh release upload "$TAG" * | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
TAG: ${{ steps.create-release.outputs.computed-prefix }}${{ steps.create-release.outputs.version }} |