From ae713ea3df4e3b3ebc287bd7f99064d02acf01c1 Mon Sep 17 00:00:00 2001 From: joaolfp Date: Sun, 15 Nov 2026 00:11:27 -0300 Subject: [PATCH] ci: release with release-plz, releasor and Homebrew tap; audit workflows with zizmor Co-Authored-By: Claude Opus 5.5 --- .github/workflows/CI.yml | 38 +++++++++- .github/workflows/release-plz.yml | 121 ++++++++++++++++++++++++++++++ CLAUDE.md | 11 ++- mise.lock | 57 ++++++++++++++ mise.toml | 12 +++ release-plz.toml | 11 +++ 6 files changed, 245 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/release-plz.yml create mode 100644 mise.lock create mode 100644 release-plz.toml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 6b5381c..3280fe6 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -1,24 +1,34 @@ name: CI on: [pull_request] +permissions: {} + +concurrency: + group: ci-${{ github.event.pull_request.number }} + cancel-in-progress: true + jobs: build: + name: Build (${{ matrix.os }}) strategy: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} + permissions: + contents: read steps: - - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Mise install - uses: jdx/mise-action@641a2bcbed5ce4f7aa8ffed0a3af42b65cdf1094 + uses: jdx/mise-action@d5574b52816a478f9d4e6529a3f6ff17a8a36785 # v5.2.8 with: cache: true - experimental: true - - uses: Swatinem/rust-cache@f51f967e158417aafa338a1e46ab22095f07aa01 + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 - name: Run build run: mise build @@ -29,3 +39,23 @@ jobs: - name: Run tests run: mise test + zizmor: + name: Audit workflows (zizmor) + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Mise install + uses: jdx/mise-action@d5574b52816a478f9d4e6529a3f6ff17a8a36785 # v5.2.8 + with: + install_args: zizmor + + - name: Audit workflows + run: mise run zizmor + env: + GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/release-plz.yml b/.github/workflows/release-plz.yml new file mode 100644 index 0000000..e5dc41e --- /dev/null +++ b/.github/workflows/release-plz.yml @@ -0,0 +1,121 @@ +name: Release + +on: + push: + branches: + - main + +permissions: {} + +concurrency: + group: release-${{ github.ref }} + cancel-in-progress: false + +jobs: + release-plz-release: + name: Release + environment: release + if: github.repository_owner == 'heroesofcode' + runs-on: ubuntu-latest + permissions: + contents: write + id-token: write + outputs: + releases_created: ${{ steps.release-plz.outputs.releases_created }} + releases: ${{ steps.release-plz.outputs.releases }} + + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Mise install + uses: jdx/mise-action@d5574b52816a478f9d4e6529a3f6ff17a8a36785 # v5.2.8 + with: + install_args: rust + + - name: Run release-plz + id: release-plz + uses: release-plz/action@66b324fd6c72d05d2a08568492ecdd62bfb8a62b # v0.5.148 + with: + command: release + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} + + release-plz-pr: + name: Release PR + environment: release + if: github.repository_owner == 'heroesofcode' + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Mise install + uses: jdx/mise-action@d5574b52816a478f9d4e6529a3f6ff17a8a36785 # v5.2.8 + with: + install_args: rust + + - name: Run release-plz + uses: release-plz/action@66b324fd6c72d05d2a08568492ecdd62bfb8a62b # v0.5.148 + with: + command: release-pr + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} + + homebrew: + name: Homebrew + environment: release + needs: release-plz-release + if: needs.release-plz-release.outputs.releases_created == 'true' + runs-on: macos-latest + permissions: + contents: write + env: + TAG: ${{ fromJSON(needs.release-plz-release.outputs.releases)[0].tag }} + + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ env.TAG }} + persist-credentials: false + + - name: Mise install + uses: jdx/mise-action@d5574b52816a478f9d4e6529a3f6ff17a8a36785 # v5.2.8 + with: + install_args: rust cargo:releasor + + - name: Package with releasor + run: mise run package + + - name: Upload to the GitHub release + run: gh release upload "$TAG" gitrat.tar.gz --clobber + env: + GH_TOKEN: ${{ github.token }} + + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: heroesofcode/homebrew-taps + path: homebrew-taps + persist-credentials: false + + - name: Update formula + working-directory: homebrew-taps + env: + RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }} + run: | + sha=$(shasum -a 256 ../gitrat.tar.gz | cut -d ' ' -f 1) + url="https://github.com/heroesofcode/gitrat/releases/download/$TAG/gitrat.tar.gz" + sed -i '' -E "s|^( *url ).*|\1\"$url\"|; s|^( *sha256 ).*|\1\"$sha\"|" gitrat.rb + git diff + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git commit -am "gitrat ${TAG#v}" + git push "https://x-access-token:${RELEASE_TOKEN}@github.com/heroesofcode/homebrew-taps.git" HEAD:main diff --git a/CLAUDE.md b/CLAUDE.md index 66089e1..ecae39c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -12,6 +12,9 @@ cargo clippy --all-targets --all-features # or: mise lint cargo fmt --all -- --check # or: mise fmt cargo fmt --all # apply formatting cargo build --release # or: mise release +mise run zizmor # audit .github/workflows (must report no findings) +mise run package # releasor -f gitrat → gitrat.tar.gz (macOS) +mise lock --platform linux-x64,linux-arm64,macos-x64,macos-arm64,windows-x64 # after changing [tools] ``` ## Code Style @@ -24,7 +27,13 @@ Formatting is enforced via `.rustfmt.toml`: ## Toolchain -Rust 1.100 (edition 2024), pinned in `mise.toml` and `rust-version` in `Cargo.toml`. CI installs it via `mise`. +Rust 1.100 (edition 2024), pinned in `mise.toml` and `rust-version` in `Cargo.toml`. CI installs it via `mise`; tool versions are locked in `mise.lock`. + +## CI and releases + +- `CI.yml` (PRs): build/lint/test on Ubuntu, macOS and Windows, plus a `zizmor` job. Actions are pinned by commit SHA with a `# vX.Y.Z` comment, `persist-credentials: false`, `permissions: {}` at the top and commented per-job permissions. +- `release-plz.yml` (push to `main`): release-plz (`release-plz.toml`, changelog via `cliff.toml`) opens the release PR; merging it publishes to crates.io, tags `vX.Y.Z` and creates the GitHub release. The `homebrew` job then builds `gitrat.tar.gz` with releasor on macOS, uploads it to the release and updates `gitrat.rb` in `heroesofcode/homebrew-taps`. +- Never bump the version in `Cargo.toml` by hand; release-plz does it. ## Architecture diff --git a/mise.lock b/mise.lock new file mode 100644 index 0000000..0bd4c4d --- /dev/null +++ b/mise.lock @@ -0,0 +1,57 @@ +# @generated - this file is auto-generated by `mise lock` https://mise.jdx.dev/dev-tools/mise-lock.html + +lockfile_version = 1 + +[[tools."cargo:releasor"]] +version = "2.0.1" +backend = "cargo:releasor" +specifiers = ["2.0.1"] + +[[tools.rust]] +version = "1.100.0" +backend = "core:rust" +specifiers = ["1.100.0"] + +[tools.rust.options] +components = "clippy,rustfmt" + +[[tools.zizmor]] +version = "1.32.0" +backend = "aqua:zizmorcore/zizmor" +specifiers = ["1.32.0"] + +[tools.zizmor."platforms.linux-arm64"] +checksum = "sha256:cb152b207f815116d7fa1c1ee4614f61578803351395052908095e79adfd9fd0" +url = "https://github.com/zizmorcore/zizmor/releases/download/v1.32.0/zizmor-aarch64-unknown-linux-gnu.tar.gz" +url_api = "https://api.github.com/repos/zizmorcore/zizmor/releases/assets/703541931" +provenance = "github-attestations" + +[tools.zizmor."platforms.linux-arm64-musl"] +provenance = "github-attestations" + +[tools.zizmor."platforms.linux-x64"] +checksum = "sha256:bb110cc765eca9cd7efb2e284a956be5974c60027b0970f16397d86208a9957b" +url = "https://github.com/zizmorcore/zizmor/releases/download/v1.32.0/zizmor-x86_64-unknown-linux-gnu.tar.gz" +url_api = "https://api.github.com/repos/zizmorcore/zizmor/releases/assets/703541932" +provenance = "github-attestations" + +[tools.zizmor."platforms.linux-x64-musl"] +provenance = "github-attestations" + +[tools.zizmor."platforms.macos-arm64"] +checksum = "sha256:6efed18c4539a663fd3c851a2be9533fd8456c4e646d9416206da059154a0d3c" +url = "https://github.com/zizmorcore/zizmor/releases/download/v1.32.0/zizmor-aarch64-apple-darwin.tar.gz" +url_api = "https://api.github.com/repos/zizmorcore/zizmor/releases/assets/703541933" +provenance = "github-attestations" + +[tools.zizmor."platforms.macos-x64"] +checksum = "sha256:6983143c719ada6845a69cc4dd2bacc215f971662fecd8bbd2678388e5ce5969" +url = "https://github.com/zizmorcore/zizmor/releases/download/v1.32.0/zizmor-x86_64-apple-darwin.tar.gz" +url_api = "https://api.github.com/repos/zizmorcore/zizmor/releases/assets/703541930" +provenance = "github-attestations" + +[tools.zizmor."platforms.windows-x64"] +checksum = "sha256:d284a16e09d9df4ce2c000357e7b59bd531be093bea5718a1ce225b449b59d49" +url = "https://github.com/zizmorcore/zizmor/releases/download/v1.32.0/zizmor-x86_64-pc-windows-msvc.zip" +url_api = "https://api.github.com/repos/zizmorcore/zizmor/releases/assets/703541929" +provenance = "github-attestations" diff --git a/mise.toml b/mise.toml index 9522e60..436b4ba 100644 --- a/mise.toml +++ b/mise.toml @@ -1,5 +1,11 @@ +[settings] +lockfile = true + [tools] rust = { version = "1.100.0", components = "clippy,rustfmt" } +zizmor = "1.32.0" +# Packages the release binary (`mise run package`); only needed on macOS. +"cargo:releasor" = { version = "2.0.1", os = ["macos"] } [tasks.lint] run = "cargo clippy --all-targets --all-features" @@ -28,3 +34,9 @@ run = "cargo fmt --all -- --check" [tasks.changelog] run = "git cliff -o CHANGELOG.md" + +[tasks.zizmor] +run = "zizmor .github/workflows" + +[tasks.package] +run = "releasor -f gitrat" diff --git a/release-plz.toml b/release-plz.toml new file mode 100644 index 0000000..5afb7c2 --- /dev/null +++ b/release-plz.toml @@ -0,0 +1,11 @@ +[workspace] +# Changelog generated with git-cliff using the project's cliff.toml. +changelog_config = "cliff.toml" +changelog_update = true +# Tag `vX.Y.Z` and create the GitHub release; the release workflow then +# attaches the macOS binary built by releasor and updates the Homebrew tap. +git_tag_enable = true +git_tag_name = "v{{ version }}" +git_release_enable = true +git_release_name = "v{{ version }}" +publish = true