name: build on: push: branches: [main] paths-ignore: [bin.json] workflow_dispatch: 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-musl, aarch64-apple-darwin] # rust, zig, cargo-zigbuild, both targets and a macOS SDK (SDKROOT) prebuilt; # the runner keeps the pulled image, so no per-run toolchain/SDK setup container: image: ghcr.io/rust-cross/cargo-zigbuild:0.24.1 steps: # the image has no node, which act_runner needs for the JS actions below - run: | case "$(uname -m)" in x86_64) a=x64 ;; aarch64) a=arm64 ;; esac curl -fsSL "https://nodejs.org/dist/v22.11.0/node-v22.11.0-linux-$a.tar.xz" \ | tar -xJ -C /usr/local --strip-components=1 - uses: actions/checkout@v4 # caches ~/.cargo registry/git and target/, keyed on Cargo.lock + toolchain; # a no-op until the runner's cache server is enabled - uses: Swatinem/rust-cache@v2 with: key: ${{ matrix.target }} - run: cargo zigbuild --release --locked --target ${{ matrix.target }} env: ORCH_VERSION: ${{ needs.version.outputs.version }} - uses: actions/upload-artifact@v3 with: name: orch-${{ matrix.target }} path: target/${{ matrix.target }}/release/orch release: needs: [build, version] runs-on: ubuntu-latest steps: # main, not the build sha: bin.json is committed on top of it - uses: actions/checkout@v4 with: ref: main - uses: actions/download-artifact@v3 with: path: dist # artifacts lose the executable bit, restore it before packaging - working-directory: dist run: | for t in orch-*; do chmod +x "$t/orch" tar -czf "$t.tar.gz" -C "$t" orch 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 # flake.nix reads bin.json to fetch these tarballs instead of building from source - env: VERSION: ${{ needs.version.outputs.version }} run: | jq -Rn --arg v "$VERSION" \ '{version: $v, sha256: ([inputs | split(" ") | {(.[1] | ltrimstr("orch-") | rtrimstr(".tar.gz")): .[0]}] | add)}' \ < dist/SHA256SUMS > bin.json git config user.name gitea-actions git config user.email gitea-actions@git.jokresner.de git add bin.json git commit -m "ci: bin.json v$VERSION" git pull --rebase origin main git push origin HEAD:main