From cf4c678e584c5ee5e75c2abbd75f7fcb03874c4f Mon Sep 17 00:00:00 2001 From: botandbang <337765928+botandbang@users.noreply.github.com> Date: Sat, 31 Oct 2026 10:54:06 -0400 Subject: [PATCH] fix(release): bump the pre-commit hook and the README schema URL on release PRs --- .github/workflows/release.yml | 5 +++-- .pre-commit-hooks.yaml | 3 ++- tools/release-pr-cargo.sh | 31 ++++++++++++++++--------------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7efa1cf..613e880 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,7 +2,7 @@ name: Release # uppt (https://github.com/danielroe/uppt) runs releases. Each push to main opens or updates a draft # release PR from the conventional commits since the last tag, bumping npm/docov/package.json, and -# cargo-pr bumps Cargo.toml on it to match. Merging the PR tags it and dispatches this workflow on +# cargo-pr bumps the rest on it to match. Merging the PR tags it and dispatches this workflow on # the tag, which builds the binaries, then stages the npm packages (tools/npm-approve.sh approves # them) and publishes the crate alongside. Both registries use trusted publishing, so there are no # tokens here. tools/bootstrap-publishing.sh sets that up. @@ -63,7 +63,8 @@ jobs: npm/docov npm/platforms/* - # uppt/pr only bumps package.json, so this brings Cargo.toml along on the release PR + # uppt/pr only bumps package.json, so this brings Cargo.toml, the pre-commit hook and the + # README's $schema URL along on the release PR cargo-pr: needs: pr runs-on: ubuntu-latest diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 28978d1..5d9db59 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -1,6 +1,7 @@ # docov as a pre-commit hook. `language: node` has pre-commit install the npm package, with its # prebuilt binary, in an environment of its own (and Node too when there isn't one), so it works -# without docov installed and on pre-commit.ci. The version moves with Cargo.toml's (a test checks). +# without docov installed and on pre-commit.ci. The version moves with Cargo.toml's: +# tools/release-pr-cargo.sh bumps both, and a test checks. - id: docov name: docov description: JSDoc coverage for JavaScript and TypeScript diff --git a/tools/release-pr-cargo.sh b/tools/release-pr-cargo.sh index 07b411e..d37b0b1 100755 --- a/tools/release-pr-cargo.sh +++ b/tools/release-pr-cargo.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash -# Bumps Cargo.toml and Cargo.lock to npm/docov/package.json's version on each open release PR -# (release/v* in this repository) and pushes the commit. uppt/pr only bumps package.json, so -# release.yml runs this after it. A branch already at that version is left alone, and uppt keeps -# the extra commit when it updates the PR. +# Bumps Cargo.toml, Cargo.lock, .pre-commit-hooks.yaml and the README's $schema URL to +# npm/docov/package.json's version on each open release PR (release/v* in this repository) and +# pushes the commit. uppt/pr only bumps package.json, so release.yml runs this after it. A branch +# already at that version is left alone, and uppt keeps the extra commit when it updates the PR. # # Needs GH_TOKEN, allowed to push and to read pull requests. set -euo pipefail @@ -19,24 +19,25 @@ for branch in $branches; do ( cd "$dir" version=$(jq -r .version npm/docov/package.json) - cargo_version() { - cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version' - } - if [[ $(cargo_version) == "$version" ]]; then - echo "$branch: Cargo.toml is already at $version" - exit - fi # [package]'s version is the first in the file. perl -0777 -pi -e "s/^version = \".*?\"/version = \"$version\"/m" Cargo.toml + # The npm package the pre-commit hook installs (tests/cli.rs checks it matches), and the + # README's $schema URL, pinned to the release's tag. + perl -pi -e "s{\"\@docov/cli\@[^\"]*\"}{\"\@docov/cli\@$version\"}" .pre-commit-hooks.yaml + perl -pi -e "s{cutenode/docov/v[^/]+/docov\.schema\.json}{cutenode/docov/v$version/docov.schema.json}" README.md + if git diff --quiet; then + echo "$branch: already at $version" + exit + fi cargo update --workspace - if [[ $(cargo_version) != "$version" ]]; then + if [[ $(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version') != "$version" ]]; then echo "::error::couldn't set Cargo.toml's version to $version on $branch" exit 1 fi - git -c user.name='github-actions[bot]' -c user.email='41898283+github-actions[bot]@users.noreply.github.com' \ - commit -qam "chore(release): bump Cargo.toml to v$version" + git -c user.name='github-actions[bot]' -c user.email='41898282+github-actions[bot]@users.noreply.github.com' \ + commit -qam "chore(release): bump Cargo.toml, the pre-commit hook and the README to v$version" git push -q origin "HEAD:refs/heads/$branch" - echo "$branch: bumped Cargo.toml to $version" + echo "$branch: bumped Cargo.toml, the pre-commit hook and the README to $version" ) git worktree remove --force "$dir" done