diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 99a229b..40ce56e 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -5,26 +5,76 @@ on: env: MACOS_SDK: "14.5" jobs: + # next version = highest vX.Y.Z tag with the patch bumped; push a tag by hand for minor/major + version: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.next.outputs.version }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - id: next + run: | + last=$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | head -n1) + if [ -z "$last" ]; then + next=0.1.0 + else + last=${last#v} + next="${last%.*}.$(( ${last##*.} + 1 ))" + fi + echo "version=$next" >> "$GITHUB_OUTPUT" build: + needs: version runs-on: ubuntu-latest strategy: fail-fast: false matrix: - target: [x86_64-unknown-linux-gnu, aarch64-apple-darwin] + target: [x86_64-unknown-linux-musl, aarch64-apple-darwin] steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: targets: ${{ matrix.target }} - - if: matrix.target == 'x86_64-unknown-linux-gnu' - run: cargo build --release --locked --target ${{ matrix.target }} -p hx-cli - # macOS: zig as cross C compiler/linker, Apple SDK for Security.framework etc. + # zig as cross C compiler/linker for both musl and macOS + - run: pip install ziglang cargo-zigbuild + # macOS: Apple SDK for Security.framework etc. - if: matrix.target == 'aarch64-apple-darwin' run: | - pip install ziglang cargo-zigbuild curl -fsSL "https://github.com/joseluisq/macosx-sdks/releases/download/${MACOS_SDK}/MacOSX${MACOS_SDK}.sdk.tar.xz" | tar -xJ -C "$HOME" - SDKROOT="$HOME/MacOSX${MACOS_SDK}.sdk" cargo zigbuild --release --locked --target ${{ matrix.target }} -p hx-cli + echo "SDKROOT=$HOME/MacOSX${MACOS_SDK}.sdk" >> "$GITHUB_ENV" + - run: cargo zigbuild --release --locked --target ${{ matrix.target }} -p hx-cli + env: + HX_VERSION: ${{ needs.version.outputs.version }} - uses: actions/upload-artifact@v3 with: name: hx-${{ matrix.target }} path: target/${{ matrix.target }}/release/hx + release: + needs: [build, version] + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v3 + with: + path: dist + # artifacts lose the executable bit, restore it before packaging + - working-directory: dist + run: | + for t in hx-*; do + chmod +x "$t/hx" + tar -czf "$t.tar.gz" -C "$t" hx + done + sha256sum *.tar.gz > SHA256SUMS + - env: + TOKEN: ${{ secrets.GITEA_TOKEN }} + API: ${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }} + TAG: v${{ needs.version.outputs.version }} + SHA: ${{ gitea.sha }} + # Gitea creates the tag at target_commitish when it doesn't exist + run: | + id=$(curl -fsS -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \ + -d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"target_commitish\":\"$SHA\"}" "$API/releases" | jq -r .id) + for f in dist/*.tar.gz dist/SHA256SUMS; do + curl -fsS -X POST -H "Authorization: token $TOKEN" \ + -F "attachment=@$f" "$API/releases/$id/assets?name=$(basename "$f")" + done diff --git a/crates/hx-cli/src/main.rs b/crates/hx-cli/src/main.rs index 35a19d2..32d2862 100644 --- a/crates/hx-cli/src/main.rs +++ b/crates/hx-cli/src/main.rs @@ -15,7 +15,12 @@ mod rpc; use std::sync::Arc; #[derive(Parser)] -#[command(name = "hx", version, about = "Minimal coding agent")] +#[command( + name = "hx", + // CI sets HX_VERSION to the release version; local builds use Cargo's + version = option_env!("HX_VERSION").unwrap_or(env!("CARGO_PKG_VERSION")), + about = "Minimal coding agent" +)] struct Cli { #[command(subcommand)] cmd: Option,