Skip to content

Release ghook

Release ghook #11

Workflow file for this run

name: Release ghook
on:
push:
tags:
- "ghook-v*"
permissions:
contents: write
jobs:
test:
name: Test before release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Verify tag matches Cargo.toml version
# Guards against the tag/crate/release drift that broke installer
# discovery in 0.2.x (see GobbyAI/gobby-cli#4): the public installer
# resolves a version from crates.io and then looks for a matching
# ghook-v{version} GitHub asset, so the tag, the crate version, and
# the release name all have to line up exactly. Fail fast here so a
# mismatched tag never produces a published crate or release.
run: |
set -euo pipefail
tag="${GITHUB_REF#refs/tags/}"
tag_version="${tag#ghook-v}"
if [ "$tag" = "$tag_version" ]; then
echo "::error::Tag '$tag' does not start with 'ghook-v'." >&2
exit 1
fi
cargo_version="$(cargo pkgid -p gobby-hooks | sed 's/.*@//')"
if [ "$tag_version" != "$cargo_version" ]; then
echo "::error::Tag version '$tag_version' does not match crates/ghook/Cargo.toml version '$cargo_version'." >&2
exit 1
fi
echo "Tag '$tag' aligns with crates/ghook/Cargo.toml version '$cargo_version'."
- name: Clippy
run: cargo clippy -p gobby-hooks --all-targets -- -D warnings
- name: Run tests
run: cargo test -p gobby-hooks
build:
needs: test
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-apple-darwin
os: macos-latest
cross: false
- target: x86_64-apple-darwin
os: macos-latest
cross: false
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
cross: false
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
cross: true
- target: x86_64-pc-windows-msvc
os: windows-latest
cross: false
runs-on: ${{ matrix.os }}
name: ${{ matrix.target }}
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross-compilation tools (Linux ARM)
if: matrix.cross && startsWith(matrix.os, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Build ghook
run: cargo build --release --target ${{ matrix.target }} -p gobby-hooks
- name: Package (Unix)
if: "!startsWith(matrix.os, 'windows')"
run: |
cd target/${{ matrix.target }}/release
tar czf ../../../ghook-${{ matrix.target }}.tar.gz ghook
cd ../../..
- name: Package (Windows)
if: startsWith(matrix.os, 'windows')
run: |
cd target/${{ matrix.target }}/release
Compress-Archive -Path ghook.exe -DestinationPath ../../../ghook-${{ matrix.target }}.zip
cd ../../..
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ghook-${{ matrix.target }}
path: |
ghook-${{ matrix.target }}.tar.gz
ghook-${{ matrix.target }}.zip
publish:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Publish gobby-hooks to crates.io
run: cargo publish -p gobby-hooks
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
release:
needs: [build, publish]
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
merge-multiple: true
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: |
ghook-*.tar.gz
ghook-*.zip
generate_release_notes: true