From 0dd9fda69a155e21ec727a33b8e88d579061bc79 Mon Sep 17 00:00:00 2001 From: Xianpeng Shen <3353385+shenxianpeng@users.noreply.github.com> Date: Wed, 25 Nov 2026 18:54:24 +0000 Subject: [PATCH 1/6] build: release with release-plz release-plz keeps a release PR with version bumps and changelogs. Merging it tags each released package and creates its GitHub release; the existing tag-triggered workflows still publish to crates.io, PyPI and npm. - cpp-linter, cpp-linter-py and cpp-linter-js share one version - tags and the release PR use a GitHub App token, so they trigger workflows - the release PR also syncs bindings/node/package.json - binary-builds waits for clang-tools-manager on crates.io before publishing cpp-linter - node-js-packaging checks that package.json matches the tag - a "Set release version" workflow opens a PR for a chosen version --- .github/sync-node-version.sh | 19 ++++ .github/workflows/binary-builds.yml | 18 ++++ .github/workflows/node-js-packaging.yml | 12 +++ .github/workflows/release-plz.yml | 92 +++++++++++++++++ .github/workflows/set-version.yml | 67 ++++++++++++ CONTRIBUTING.md | 21 ++++ release-plz.toml | 130 ++++++++++++++++++++++++ 7 files changed, 359 insertions(+) create mode 100755 .github/sync-node-version.sh create mode 100644 .github/workflows/release-plz.yml create mode 100644 .github/workflows/set-version.yml create mode 100644 release-plz.toml diff --git a/.github/sync-node-version.sh b/.github/sync-node-version.sh new file mode 100755 index 00000000..98aadf45 --- /dev/null +++ b/.github/sync-node-version.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Copy the cpp-linter-js version from bindings/node/Cargo.toml into +# bindings/node/package.json and the version checks in bindings/node/index.js. +# release-plz only updates Cargo manifests, so the release PR needs this step. +set -euo pipefail +cd "$(dirname "$0")/.." + +new=$(cargo metadata --format-version 1 --no-deps \ + | jq -r '.packages[] | select(.name == "cpp-linter-js") | .version') +cd bindings/node +old=$(node -p "require('./package.json').version") +if [[ "$old" == "$new" ]]; then + echo "package.json already has version $new" + exit 0 +fi +npm pkg set version="$new" +# index.js is generated by `napi build`; only its version checks change. +sed -i "s/${old//./\\.}/${new}/g" index.js +echo "Synced bindings/node from $old to $new" diff --git a/.github/workflows/binary-builds.yml b/.github/workflows/binary-builds.yml index d76a832d..936103bd 100644 --- a/.github/workflows/binary-builds.yml +++ b/.github/workflows/binary-builds.yml @@ -216,6 +216,24 @@ jobs: with: name: ${{ needs.seed-build-script.outputs.artifact-name }} path: clang-tools-manager + # release-plz pushes the clang-tools-manager and cpp-linter tags together; + # cpp-linter can only be published once its clang-tools-manager version is on crates.io. + - name: Wait for clang-tools-manager on crates.io + if: startsWith(github.ref_name, 'cpp-linter/v') + run: |- + ver=$(cargo metadata --format-version 1 --no-deps \ + | jq -r '.packages[] | select(.name == "clang-tools-manager") | .version') + for _ in $(seq 1 30); do + if curl -sSf -A "cpp-linter-rs CI (github.com/cpp-linter/cpp-linter-rs)" \ + "https://crates.io/api/v1/crates/clang-tools-manager/${ver}" > /dev/null; then + echo "clang-tools-manager ${ver} is on crates.io" + exit 0 + fi + echo "Waiting for clang-tools-manager ${ver} on crates.io" + sleep 60 + done + echo "::error::clang-tools-manager ${ver} is not on crates.io after 30 minutes" + exit 1 - name: Establish provenance id: auth uses: rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1.0.6 diff --git a/.github/workflows/node-js-packaging.yml b/.github/workflows/node-js-packaging.yml index ec2c46d5..13bf645c 100644 --- a/.github/workflows/node-js-packaging.yml +++ b/.github/workflows/node-js-packaging.yml @@ -358,6 +358,18 @@ jobs: run: ls -R ./npm working-directory: bindings/node shell: bash + - name: Check that package.json matches the tag + if: startsWith(github.ref, 'refs/tags/cpp-linter-js/v') + working-directory: bindings/node + env: + TAG: ${{ github.ref_name }} + run: |- + want="${TAG#cpp-linter-js/v}" + have=$(node -p "require('./package.json').version") + if [[ "${have}" != "${want}" ]]; then + echo "::error::package.json has version ${have}, but the tag is ${TAG}" + exit 1 + fi - name: Publish if: startsWith(github.ref, 'refs/tags/cpp-linter-js/v') working-directory: bindings/node diff --git a/.github/workflows/release-plz.yml b/.github/workflows/release-plz.yml new file mode 100644 index 00000000..ebc33db5 --- /dev/null +++ b/.github/workflows/release-plz.yml @@ -0,0 +1,92 @@ +name: Release-plz + +# Keeps the release PR up to date on every push to main. +# When the release PR is merged, tags each released package and creates +# its GitHub release; the tags trigger the deploy workflows. +# See release-plz.toml for the details. + +on: + push: + branches: [main] + # cpp-linter and clang-tools-manager are compared with crates.io, which is + # updated only after the deploy workflows finish; refresh the PR daily. + schedule: + - cron: "17 3 * * *" + workflow_dispatch: + +permissions: {} + +jobs: + release: + name: Tag and create GitHub releases + if: github.repository_owner == 'cpp-linter' && github.event_name == 'push' + runs-on: ubuntu-latest + steps: + # Tags pushed with the default GITHUB_TOKEN do not trigger other workflows, + # so release-plz uses a token of the release GitHub App. + - name: Generate a GitHub App token + id: app-token + uses: actions/create-github-app-token@v3.4.0 + with: + client-id: ${{ vars.RELEASE_APP_CLIENT_ID }} + private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} + permission-contents: write # push tags, create releases + permission-pull-requests: read # find the merged release PR + - uses: actions/checkout@v7.0.1 + with: + fetch-depth: 0 + token: ${{ steps.app-token.outputs.token }} + persist-credentials: true # needed to push tags + - name: Install Rust + run: rustup update stable --no-self-update + - name: Tag released packages + uses: release-plz/action@66b324fd6c72d05d2a08568492ecdd62bfb8a62b # v0.5.148 + with: + command: release + env: + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} + + release-pr: + name: Update the release PR + if: github.repository_owner == 'cpp-linter' + runs-on: ubuntu-latest + concurrency: + group: release-plz-${{ github.ref }} + cancel-in-progress: false + steps: + # A PR opened with the default GITHUB_TOKEN would not run CI. + - name: Generate a GitHub App token + id: app-token + uses: actions/create-github-app-token@v3.4.0 + with: + client-id: ${{ vars.RELEASE_APP_CLIENT_ID }} + private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} + permission-contents: write # push the release branch + permission-pull-requests: write # open and update the release PR + - uses: actions/checkout@v7.0.1 + with: + fetch-depth: 0 + token: ${{ steps.app-token.outputs.token }} + persist-credentials: true # needed to push the release branch + - name: Install Rust + run: rustup update stable --no-self-update + - name: Update the release PR + id: release-plz + uses: release-plz/action@66b324fd6c72d05d2a08568492ecdd62bfb8a62b # v0.5.148 + with: + command: release-pr + env: + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} + - name: Sync the Node.js package version in the release PR + if: steps.release-plz.outputs.prs_created == 'true' + env: + PR_BRANCH: ${{ fromJSON(steps.release-plz.outputs.pr).head_branch }} + run: |- + git fetch origin "${PR_BRANCH}" + git switch -C "${PR_BRANCH}" FETCH_HEAD + .github/sync-node-version.sh + if git diff --quiet; then + exit 0 + fi + git commit -am "chore: sync cpp-linter-js version in package.json" + git push origin "${PR_BRANCH}" diff --git a/.github/workflows/set-version.yml b/.github/workflows/set-version.yml new file mode 100644 index 00000000..9986934b --- /dev/null +++ b/.github/workflows/set-version.yml @@ -0,0 +1,67 @@ +name: Set release version + +# Opens a PR that sets the version of cpp-linter, cpp-linter-py and +# cpp-linter-js. Use it when the next version is not the one release-plz +# derives from commit messages, e.g. to start release candidates +# (2.1.0-rc.1) or to leave them (2.1.0). +# After that PR is merged, the release PR keeps the version and only +# adds the changelog. + +on: + workflow_dispatch: + inputs: + version: + description: The new version, e.g. 2.1.0 or 2.1.0-rc.1 + type: string + required: true + +permissions: {} + +jobs: + set-version: + runs-on: ubuntu-latest + steps: + - name: Check the version + env: + VERSION: ${{ inputs.version }} + run: |- + if [[ ! "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$ ]]; then + echo "::error::'${VERSION}' is not a version like 2.1.0 or 2.1.0-rc.1" + exit 1 + fi + # A PR opened with the default GITHUB_TOKEN would not run CI. + - name: Generate a GitHub App token + id: app-token + uses: actions/create-github-app-token@v3.4.0 + with: + client-id: ${{ vars.RELEASE_APP_CLIENT_ID }} + private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} + permission-contents: write # push the branch + permission-pull-requests: write # open the PR + - uses: actions/checkout@v7.0.1 + with: + token: ${{ steps.app-token.outputs.token }} + persist-credentials: true # needed to push the branch + - uses: cargo-bins/cargo-binstall@5885714d0a40a14b2535c6ffc051fd8e49aa9665 # v1.27.0 + - name: Install cargo-edit + run: cargo binstall -y cargo-edit + env: + GITHUB_TOKEN: ${{ github.token }} + - name: Open a PR with the new version + env: + VERSION: ${{ inputs.version }} + GH_TOKEN: ${{ steps.app-token.outputs.token }} + APP_SLUG: ${{ steps.app-token.outputs.app-slug }} + run: |- + bot_id=$(gh api "/users/${APP_SLUG}[bot]" --jq .id) + git config user.name "${APP_SLUG}[bot]" + git config user.email "${bot_id}+${APP_SLUG}[bot]@users.noreply.github.com" + branch="set-version-${VERSION}" + git switch -c "${branch}" + cargo set-version -p cpp-linter -p cpp-linter-py -p cpp-linter-js "${VERSION}" + .github/sync-node-version.sh + git commit -am "chore: set version to ${VERSION}" + git push origin "${branch}" + gh pr create --base main --head "${branch}" \ + --title "chore: set version to ${VERSION}" \ + --body "Sets cpp-linter, cpp-linter-py and cpp-linter-js to ${VERSION}. Once merged, the release PR keeps this version and adds the changelog." diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d4a3e7f3..8d9e7175 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -87,4 +87,25 @@ In CI, docs are built using nur docs --build ``` +## Releasing + +Releases are prepared by [release-plz] (see `release-plz.toml`). + +1. On every push to `main`, release-plz opens or updates a release PR titled + "chore: release". It bumps the versions from the conventional commit + messages (`fix` → patch, `feat` → minor, `!` → major) and adds the + changelog entries. +2. cpp-linter, cpp-linter-py and cpp-linter-js always get the same version. + clang-tools-manager has its own version. +3. Review the release PR (the changelog can be edited there) and merge it. +4. release-plz then pushes a `{package}/v{version}` tag for each released + package and creates its GitHub release. The tags trigger the builds that + publish to crates.io, PyPI and npm. Pre-releases (`-rc.N`) go to TestPyPI + and to npm's `next` tag. + +To choose a version yourself (e.g. to start or end release candidates), +run the "Set release version" workflow. It opens a PR with the new version; +after it is merged, the release PR keeps that version. + [nur]: https://nur-taskrunner.github.io/docs/ +[release-plz]: https://release-plz.dev/ diff --git a/release-plz.toml b/release-plz.toml new file mode 100644 index 00000000..47266d49 --- /dev/null +++ b/release-plz.toml @@ -0,0 +1,130 @@ +# Configuration for release-plz (https://release-plz.dev/docs/config). +# +# On every push to main, release-plz keeps one release PR up to date +# (version bumps + changelogs). Merging that PR makes release-plz push one +# `{package}/v{version}` tag per released package and create its GitHub release. +# Those tags trigger the deploy workflows, as before: +# - binary-builds.yml: crates.io + binaries (cpp-linter, clang-tools-manager) +# - python-packaging.yml: PyPI, or TestPyPI for pre-releases (cpp-linter-py) +# - node-js-packaging.yml: npm, `next` dist-tag for pre-releases (cpp-linter-js) + +[workspace] +# Publishing is done by the tag-triggered workflows above. +publish = false +semver_check = false +# Only release when a release PR (branch `release-plz-*`) is merged. +release_always = false +git_tag_name = "{{ package }}/v{{ version }}" +git_release_name = "{{ package }}/v{{ version }}" +# Pre-release versions (e.g. 2.1.0-rc.1) become GitHub pre-releases. +git_release_type = "auto" +git_release_latest = false + +# cpp-linter, cpp-linter-py and cpp-linter-js always share one version, +# so cargo, pip and npm users see the same version number. +[[package]] +name = "cpp-linter" +version_group = "cpp-linter" +git_release_latest = true + +[[package]] +name = "cpp-linter-py" +version_group = "cpp-linter" +# Not on crates.io: the last release is read from git tags. +git_only = true +changelog_include = ["cpp-linter", "clang-tools-manager"] +git_release_body = """ +{%- if changelog -%} +{{ changelog }} +{%- else -%} +Python binding of cpp-linter {{ version }}. \ +See the [cpp-linter {{ version }} release](https://github.com/cpp-linter/cpp-linter-rs/releases/tag/cpp-linter/v{{ version }}) for the changes. +{%- endif -%} +""" + +[[package]] +name = "cpp-linter-js" +version_group = "cpp-linter" +# Not on crates.io: the last release is read from git tags. +git_only = true +changelog_include = ["cpp-linter", "clang-tools-manager"] +git_release_body = """ +{%- if changelog -%} +{{ changelog }} +{%- else -%} +Node.js binding of cpp-linter {{ version }}. \ +See the [cpp-linter {{ version }} release](https://github.com/cpp-linter/cpp-linter-rs/releases/tag/cpp-linter/v{{ version }}) for the changes. +{%- endif -%} +""" + +[[package]] +name = "clang-tools-manager" + +# Only used to generate the docs. +[[package]] +name = "cli-gen" +release = false + +# Same layout as the git-cliff config in .config/cliff.toml, adapted to the +# variables release-plz provides (`package`, `remote.link`, `previous.version`). +[changelog] +header = """ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +""" +body = """ +{%- set this_tag = package ~ "/v" ~ version -%} +## [{{ version }}] - {{ timestamp | date(format="%Y-%m-%d") }} +{% for group, commits in commits | group_by(attribute="group") %} +### {{ group | upper_first }} +{% for commit in commits %} +- {{ commit.message | split(pat="\n") | first | upper_first | trim }}\ + {% if commit.remote.username %} by @{{ commit.remote.username }}{%- endif -%} + {% if commit.remote.pr_number %} in \ + [#{{ commit.remote.pr_number }}]({{ remote.link }}/pull/{{ commit.remote.pr_number }}) + {%- else %} in \ + [`{{ commit.id | truncate(length=7, end="") }}`]({{ remote.link }}/commit/{{ commit.id }}) + {%- endif -%} +{% endfor %} +{% endfor -%} +{%- if previous.version -%} + {%- if previous.version is starting_with(package ~ "/") -%} + {%- set prev_tag = previous.version -%} + {%- else -%} + {%- set prev_tag = package ~ "/v" ~ previous.version -%} + {%- endif %} +[{{ version }}]: {{ remote.link }}/compare/{{ prev_tag }}...{{ this_tag }} + +Full commit diff: [`{{ prev_tag }}...{{ this_tag }}`][{{ version }}] +{% endif %} +""" +trim = true +sort_commits = "oldest" +protect_breaking_commits = true +commit_preprocessors = [ + # remove issue numbers from commits + { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" }, +] +commit_parsers = [ + { message = "^build: bump version to ", skip = true }, + { message = "^chore: release", skip = true }, + { field = "breaking", pattern = "true", group = " 💥 Breaking changes" }, + { field = "group", pattern = "^(add|feat)$", group = " 🚀 Added" }, + { field = "group", pattern = "^deprecate$", group = " 🚫 Deprecated" }, + { field = "group", pattern = "^(remove|delete)$", group = " 🗑️ Removed" }, + { field = "group", pattern = "^(fix|perf)$", group = " 🛠️ Fixed" }, + { field = "group", pattern = "^security$", group = " 🔐 Security" }, + { field = "group", pattern = "^build$", group = " 📦 Dependency updates" }, + { field = "group", pattern = "^test$", group = "🚦 Tests" }, + { field = "group", pattern = "^docs$", group = " 📝 Documentation" }, + { field = "group", pattern = "^(chore|style|refactor)$", group = " 🗨️ Changed" }, + # Unconventional commit messages + { message = "^[aA]dd", group = " 🚀 Added" }, + { message = "^[fF]ix", group = " 🛠️ Fixed" }, + { message = "^.*", group = " 🗨️ Changed" }, +] From 479e483f951a1c74eca2140643e5809f6fc6ef14 Mon Sep 17 00:00:00 2001 From: Xianpeng Shen <3353385+shenxianpeng@users.noreply.github.com> Date: Wed, 25 Nov 2026 19:16:20 +0000 Subject: [PATCH 2/6] build: remove the old release tooling release-plz replaces bump-n-release (and its git-cliff config), so both go. The set-version workflow is replaced by two commands in CONTRIBUTING.md, since a manual version is only needed to start or end release candidates. Also drops a VS Code task that pointed at a script that no longer exists. --- .config/cliff.toml | 165 ---------------- .github/workflows/bump-n-release.nu | 270 --------------------------- .github/workflows/bump-n-release.yml | 139 -------------- .github/workflows/set-version.yml | 67 ------- .gitignore | 1 - .vscode/tasks.json | 23 --- CONTRIBUTING.md | 11 +- release-plz.toml | 4 +- 8 files changed, 11 insertions(+), 669 deletions(-) delete mode 100644 .config/cliff.toml delete mode 100644 .github/workflows/bump-n-release.nu delete mode 100644 .github/workflows/bump-n-release.yml delete mode 100644 .github/workflows/set-version.yml diff --git a/.config/cliff.toml b/.config/cliff.toml deleted file mode 100644 index 07f031af..00000000 --- a/.config/cliff.toml +++ /dev/null @@ -1,165 +0,0 @@ -# git-cliff ~ configuration file -# https://git-cliff.org/docs/configuration - -[changelog] -# template for the changelog header -header = """ -# Changelog\n -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -\n -""" -# template for the changelog body -# https://keats.github.io/tera/docs/#introduction -body = """ -{%- macro remote_url() -%} - https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }} -{%- endmacro -%} -{%- set UNRELEASED = "Unreleased" -%} -{%- set init_commit = "2e25fec0a447df24d0bcc1b80f6624040bab755e" -%} -{%- set this_version = UNRELEASED -%} - -{% if version -%} - {%- set this_version = version | trim_start_matches(pat="v") -%} - ## [{{ this_version }}] - {{ timestamp | date(format="%Y-%m-%d") }} - {%- if message %} - - > {{ message }} - {%- endif %} -{% elif previous.timestamp -%} - ## [{{ UNRELEASED }}] - {{ previous.timestamp | date(format="%Y-%m-%d") }} to present -{% else -%} - ## [{{ UNRELEASED }}] -{% endif -%} - -{% for group, commits in commits | group_by(attribute="group") %} - ### {{ group | upper_first }} - {% for commit in commits %} - - {{ commit.message | split(pat="\n") | first | upper_first | trim }}\ - {% if commit.remote.username %} by @{{ commit.remote.username }}{%- endif -%} - {% if commit.remote.pr_number %} in \ - [#{{ commit.remote.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.remote.pr_number }}) - {%- else %} in \ - [`{{ commit.id | truncate(length=7, end="") }}`]({{ self::remote_url() }}/commit/{{commit.id }}) - {%- endif -%} - {% endfor %} -{% endfor -%} - -{% if version -%} - {#- Use the current version tag as the latest commit -#} - {%- set last_commit = version -%} -{%- else -%} - {#- Otherwise, just call it HEAD -#} - {%- set last_commit = "HEAD" -%} -{%- endif -%} -{%- if not previous.version -%} - {#- If this is the first versioned release, use the initial commit -#} - {%- set first_commit = init_commit -%} -{%- else -%} - {#- Otherwise, use the previous version tag as the starting point -#} - {%- set first_commit = previous.version -%} -{%- endif %} -[{{ this_version }}]: {{ self::remote_url() }}/compare/{{ first_commit }}...{{ last_commit }} - -Full commit diff: [`{% if previous.version -%} - {{ first_commit }} -{%- else -%} - {{ init_commit | truncate(length=7, end="") }} -{%- endif %}...{{ last_commit }}`][{{ this_version }}] -{% if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 %} - ## New Contributors - {% for contributor in github.contributors | filter(attribute="is_first_time", value=true) %} - - @{{ contributor.username }} made their first contribution - {%- if contributor.pr_number %} in \ - [#{{ contributor.pr_number }}]({{ self::remote_url() }}/pull/{{ contributor.pr_number }}) \ - {%- endif %} - {%- endfor %} -{% endif %} - -""" -# template for the changelog footer -footer = """ - -""" -# remove the leading and trailing whitespace from the templates -trim = true -# The file path for output. This can be overridden with `--output` CLI arg -# output = "CHANGELOG.md" - -[git] -# parse the commits based on https://www.conventionalcommits.org -conventional_commits = true -# filter out the commits that are not conventional -filter_unconventional = false -# regex for preprocessing the commit messages -commit_preprocessors = [ - # remove issue numbers from commits - { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" }, -] -# regex for parsing and grouping commits -commit_parsers = [ - { field = "github.pr_labels", pattern = "breaking", group = " 💥 Breaking changes" }, - { field = "github.pr_labels", pattern = "breaking-change", group = " 💥 Breaking changes" }, - { field = "github.pr_labels", pattern = "feature", group = " 🚀 Added" }, - { field = "github.pr_labels", pattern = "enhancement", group = " 🚀 Added" }, - { field = "github.pr_labels", pattern = "deprecated", group = " 🚫 Deprecated" }, - { field = "github.pr_labels", pattern = "removed", group = " 🗑️ Removed" }, - { field = "github.pr_labels", pattern = "bug", group = " 🛠️ Fixed" }, - { field = "github.pr_labels", pattern = "security", group = " 🔐 Security" }, - { field = "github.pr_labels", pattern = "dependencies", group = " 📦 Dependency updates" }, - { field = "github.pr_labels", pattern = "test", group = "🚦 Tests"}, - { field = "github.pr_labels", pattern = "tests", group = "🚦 Tests"}, - { field = "github.pr_labels", pattern = "documentation", group = " 📝 Documentation" }, - { field = "github.pr_labels", pattern = "refactor", group = " 🗨️ Changed" }, - { field = "github.pr_labels", pattern = "skip-changelog", skip = true }, - { field = "github.pr_labels", pattern = "no-changelog", skip = true }, - { field = "github.pr_labels", pattern = "invalid", skip = true }, - # The order of parsers matters. Put rules for PR labels first to prioritize PR labels. - # Next we categorize by conventional commit group (`group: msg`). - { field = "group", pattern = "add", group = " 🚀 Added" }, - { field = "group", pattern = "feat", group = " 🚀 Added" }, - { field = "group", pattern = "fix", group = " 🛠️ Fixed" }, - { field = "group", pattern = "perf", group = " 🛠️ Fixed" }, - { field = "group", pattern = "build", group = " 📦 Dependency updates" }, - { field = "group", pattern = "test", group = "🚦 Tests" }, - { field = "group", pattern = "docs", group = " 📝 Documentation" }, - { field = "group", pattern = "chore", group = " 🗨️ Changed" }, - { field = "group", pattern = "style", group = " 🗨️ Changed" }, - { field = "breaking", pattern = true, group = " 💥 Breaking Changes" }, - { field = "group", pattern = "remove", group = " 🗑️ Removed" }, - { field = "group", pattern = "deprecate", group = " 🚫 Deprecated" }, - { field = "group", pattern = "delete", group = " 🗑️ Removed" }, - { field = "group", pattern = "security", group = " 🔐 Security" }, - { field = "group", pattern = "refactor", group = " 🗨️ Changed" }, - # Next we have filters for unconventional commit messages - { message = "^[a|A]dd", group = " 🚀 Added" }, - { message = "^.*: [s|S]upport", group = " 🚀 Added" }, - { message = "^.*: [a|A]dd", group = " 🚀 Added" }, - { message = "^.*: [d|D]eprecated", group = " 🚫 Deprecated" }, - { message = "^.*: [r|R]emove", group = " 🗑️ Removed" }, - { message = "^.*: [d|D]elete", group = " 🗑️ Removed" }, - { message = "^[f|F]ix", group = " 🛠️ Fixed" }, - { message = "^.*: [f|F]ix", group = " 🛠️ Fixed" }, - { message = "^.*: [s|S]ecure", group = " 🔐 Security" }, - { message = "^.*: [s|S]ecurity", group = " 🔐 Security" }, - { message = "[d|D]oc", group = " 📝 Documentation" }, - { message = "[d|D]ocs", group = " 📝 Documentation" }, - { message = "[d|D]ocumentation", group = " 📝 Documentation" }, - # anything left after not being caught by filters above gets put in the "Changed" section - { message = "[r|R]efactor", group = " 🗨️ Changed" }, - { field = "github.pr_labels", pattern = ".*", group = " 🗨️ Changed" }, - { message = "^.*", group = " 🗨️ Changed" }, -] -# filter out the commits that are not matched by commit parsers -filter_commits = true -# sort the tags topologically -# spell-checker: disable-next-line -topo_order = false -# sort the commits inside sections by oldest/newest order -sort_commits = "oldest" - -[remote.github] -owner = "cpp-linter" -repo = "cpp-linter-rs" diff --git a/.github/workflows/bump-n-release.nu b/.github/workflows/bump-n-release.nu deleted file mode 100644 index 5c04e759..00000000 --- a/.github/workflows/bump-n-release.nu +++ /dev/null @@ -1,270 +0,0 @@ -# This script automates the release process for all of the packages in this repository. -# In order, this script does the following: -# -# 1. Bump version number in appropriate Cargo.toml manifest. -# -# This step requires `cargo-edit` installed. -# -# If bumping the cpp-linter-js package, yarn must be installed to -# update the version in the bindings/node/package.json manifest also. -# -# 2. Updates the appropriate CHANGELOG.md -# -# Requires `git-cliff` (see https://git-cliff.org) to be installed -# to regenerate the change logs from git history. -# -# NOTE: `git cliff` uses GITHUB_TOKEN env var to access GitHub's REST API for -# fetching certain data (like PR labels and commit author's username). -# -# 3. Pushes the changes from (steps 1 and 2) to remote -# -# 4. Creates a GitHub Release and uses the section from the CHANGELOG about the new tag -# as a release description. -# -# Requires `gh-cli` (see https://cli.github.com) to be installed to create the release -# and push the tag. -# -# NOTE: This step also tags the commit from step 3. -# When a tag is pushed to the remote, the CI builds are triggered and -# a package are published to crates.io -# -# NOTE: In a CI run, the GITHUB_TOKEN env var to authenticate access. -# Locally, you can use `gh login` to interactively authenticate the user account. -# -# The GITHUB_TOKEN permissions shall include: -# - read access to Pull Requests (for better CHANGELOG generation). -# - write (and inherently read) access to the repository "Contents" -# for publishing a GitHub release and pushing metadata changes. - -use ../common.nu run-cmd - -const COMMON_EXCLUDES = [ - '.github/**/*' - 'docs/**/*' - '.config/*' - 'README.md' - '.gitattributes' - '.gitignore' - '.pre-commit-config.yaml' - 'crates/README.md' - 'package.json' - 'codecov.yml' - 'Cargo.toml' - 'cspell.config.yml' - '**/CHANGELOG.md' -] - -const PkgPaths = { - 'cpp-linter': { - include: ['cpp-linter/**/*'] - exclude: [ - 'clang-tools-manager/**/*' - 'bindings/**/*' - 'yarn.lock' - '.yarnrc.yml' - ...$COMMON_EXCLUDES - ] - path: 'cpp-linter' - }, - 'clang-tools-manager': { - include: ['clang-tools-manager/**'] - exclude: [ - 'cpp-linter/**/*' - 'bindings/**/*' - 'yarn.lock' - '.yarnrc.yml' - ...$COMMON_EXCLUDES - ] - path: 'clang-tools-manager' - }, - 'cpp-linter-py': { - include: [] - exclude: ['bindings/node/**/*', 'yarn.lock', '.yarnrc.yml', ...$COMMON_EXCLUDES] - path: 'bindings/python' - }, - 'cpp-linter-js': { - include: [] - exclude: ['bindings/python/**', ...$COMMON_EXCLUDES] - path: 'bindings/node' - } -} - -export def get-changed-pkgs [] { - let changed_files = ( - git 'diff' '--name-only' 'HEAD~1' 'HEAD' - | lines - | str trim - | where {not ($in | str starts-with ".")} - ) - print "Changed files:" - print $changed_files - mut pkgs = [] - for row in ($PkgPaths | transpose) { - let pkg = $row.column0 - let paths = $row.column1 - print $"Checking changes for ($pkg)..." - let has_changed = if ($paths.include | is-empty) { true } else { - $changed_files | any {|file| $paths.include | any {|p| ($file | path expand) in (glob $p)}} - } - print $" Has changes: ($has_changed)" - let has_excluded_change = if ($paths.exclude | is-empty) { false } else { - $changed_files | any {|file| $paths.exclude | any {|p| ($file | path expand) in (glob $p)}} - } - print $" Has excluded changes: ($has_excluded_change)" - if $has_changed { - print $" Package ($pkg) has relevant changes" - $pkgs = $pkgs | append $pkg - } - } - if ($pkgs | length) == 0 { - print "No packages changed in the last commit." - } else { - print "Changed packages:" - print $pkgs - } - $pkgs | to json --raw -} - -# Is this executed in a CI run? -# -# Uses env var CI to determine the resulting boolean -export def is-in-ci [] { - $env | get --optional CI | default 'false' | (($in == 'true') or ($in == true)) -} - -# Bump the version per the given component name (major, minor, patch) -# -# This function also updates known occurrences of the old version spec to -# the new version spec in various places (like README.md and action.yml). -export def bump-version [ - pkg: string, # The crate name to bump in respective Cargo.toml manifests - component: string, # The version component to bump -] { - mut args = ['-p', $pkg, '--bump', $component] - if (not (is-in-ci)) { - $args = $args | append '--dry-run' - } - let result = cargo 'set-version' ...$args | complete - if ($result.exit_code != 0) { - error make {msg: $"cargo set-version failed: ($result.stderr)"} - } - let parsed = ( - $result.stderr - | lines - | where {|line| $line | str trim | str starts-with 'Upgrading'} - | first - | str trim - | parse 'Upgrading {pkg} from {old} to {new}' - ) - if ($parsed | is-empty) { - error make {msg: $"Failed to parse version from: ($result.stderr)"} - } - let result = $parsed | first - - print $"bumped ($result | get 'old') to ($result | get 'new')" - # update the version in various places - if (($pkg == 'cpp-linter-js') and (is-in-ci)) { - cd ($PkgPaths | get $pkg | get 'path') - run-cmd 'yarn' 'version' ($result | get 'new') - print 'Updated version in bindings/node/package.json' - cd '../..' - print "Regenerating index.js" - run-cmd yarn build:debug - } - $result | get new -} - -# Use `git-cliff` tp generate changes. -# -# If `--unreleased` is asserted, then the `git-cliff` output will be saved to .config/ReleaseNotes.md. -# Otherwise, the generated changes will span the entire git history and be saved to CHANGELOG.md. -export def gen-changes [ - pkg: string, # The crate name being bumped. - --tag (-t): string = '', # The new version tag to use for unreleased changes. - --unreleased (-u), # only generate changes from unreleased version. -] { - let paths = $PkgPaths | get $pkg - let path = $paths | get path | path expand - let config_path = '.config' | path expand - - mut args = [ - '--config' $"($config_path | path join 'cliff.toml')" - '--tag-pattern' $"($pkg)/*" - ] - if (($tag | str length) > 0) { - $args = $args | append ['--tag', $tag] - } - let prompt = if $unreleased { - let out_path = $config_path | path join 'ReleaseNotes.md' - $args = $args | append [ - '--strip', 'header', '--unreleased', '--output', $out_path - ] - {out_path: ($out_path | path relative-to (pwd)), log_prefix: 'Generated'} - } else { - let out_path = $path | path expand | path join 'CHANGELOG.md' - $args = $args | append [--output $out_path] - {out_path: ($out_path | path relative-to (pwd)), log_prefix: 'Updated'} - } - if (($paths | get 'include' | length) > 0) { - $args = $args | append ['--include-path', ($paths | get 'include' | str join " ")] - } - if (($paths | get 'exclude' | length) > 0) { - $args = $args | append ['--exclude-path', ($paths | get 'exclude' | str join " ")] - } - run-cmd 'git-cliff' ...$args - print ($prompt | format pattern '{log_prefix} {out_path}') -} - -# Is the the default branch currently checked out? -# -# Only accurate if the default branch is named "main". -export def is-on-main [] { - let branch = ( - ^git branch - | lines - | where {$in | str starts-with '*'} - | first - | str trim --left --char '*' - | str trim - ) == 'main' - $branch -} - -# The main function of this script. -# -# The `pkg` and `component` parameters are required CLI options: -# nu .github/workflows/bump-n-release.nu cpp-linter patch -# -# The acceptable `pkg` value are defined in the Cargo.toml manifests' `[package.name]` field. -# -# The acceptable `component` values are what `cargo set-version` accepts: -# -# - major -# - minor -# - patch -# - rc -def main [ - pkg: string, # The crate name to bump in respective Cargo.toml manifests - component: string, # The version component to bump -] { - let ver = bump-version $pkg $component - let tag = $"($pkg)/v($ver)" - gen-changes $pkg --tag $tag - gen-changes $pkg --tag $tag --unreleased - let is_main = is-on-main - if not $is_main { - print $"(ansi yellow)\nNot checked out on default branch!(ansi reset)" - } - if (is-in-ci) and $is_main { - print 'Pushing metadata changes' - run-cmd git config --global user.name $"($env.GITHUB_ACTOR)" - run-cmd git config --global user.email $"($env.GITHUB_ACTOR_ID)+($env.GITHUB_ACTOR)@users.noreply.github.com" - run-cmd git add --all - run-cmd git commit -m $"build: bump version to ($tag)" - run-cmd git push - print $"Deploying ($tag)" - run-cmd gh release create $tag --notes-file .config/ReleaseNotes.md --title $"($pkg) v($ver)" - } else if $is_main { - print $"(ansi yellow)Not deploying from local clone.(ansi reset)" - } -} diff --git a/.github/workflows/bump-n-release.yml b/.github/workflows/bump-n-release.yml deleted file mode 100644 index acc532a8..00000000 --- a/.github/workflows/bump-n-release.yml +++ /dev/null @@ -1,139 +0,0 @@ -name: Bump-n-Release - -# NOTE: The change log is only updated in the remote upon release (in `bump-release` job) - -on: - push: - branches: - - "main" - pull_request: - branches: - - "main" - workflow_dispatch: - inputs: - package: - description: The package to release - type: choice - required: true - default: cpp-linter - options: - - cpp-linter - - cpp-linter-js - - cpp-linter-py - - clang-tools-manager - component: - description: The version component to increase - type: choice - required: true - default: patch - options: - - major - - minor - - patch - - rc - -run-name: >- - ${{ inputs.package && 'Deploy ' || 'Show Unreleased Changes' }} - ${{ inputs.package || '' }} - -permissions: {} - -jobs: - bump-release: - if: github.event_name == 'workflow_dispatch' - name: Bump ${{ inputs.component }} version of ${{ inputs.package }} - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v7.0.1 - with: - token: ${{ secrets.BUMP_N_RELEASE }} - fetch-depth: 0 - fetch-tags: true - persist-credentials: true # needed for `git push` - - name: Set up Python - if: inputs.package == 'cpp-linter-py' - uses: actions/setup-python@v7.1.0 - with: - python-version: 3.x - - name: Install Node.js - if: inputs.package == 'cpp-linter-js' - uses: actions/setup-node@v7 - with: - node-version: 24.x - - run: yarn install - if: inputs.package == 'cpp-linter-js' - - uses: cargo-bins/cargo-binstall@5885714d0a40a14b2535c6ffc051fd8e49aa9665 # v1.27.0 - - run: cargo binstall -y git-cliff - env: - GITHUB_TOKEN: ${{ github.token }} - - name: Install cargo-edit - run: >- - cargo install cargo-edit - --locked - --no-default-features - --features set-version - - name: Install nushell - uses: hustcer/setup-nu@1b8faed9a8ff673c8ce0beae243e0b72d0787241 # v3.30 - - name: Bump ${{ inputs.component }} version - env: - GITHUB_TOKEN: ${{ secrets.BUMP_N_RELEASE }} - GH_TOKEN: ${{ secrets.BUMP_N_RELEASE }} - run: nu .github/workflows/bump-n-release.nu ${{ inputs.package }} ${{ inputs.component }} - id: tagged - - get-changed-pkgs: - if: github.event_name != 'workflow_dispatch' && !startsWith(github.ref, 'refs/tags/') - runs-on: ubuntu-latest - outputs: - pkgs: ${{ steps.get-pkgs.outputs.pkgs }} - steps: - - uses: actions/checkout@v7.0.1 - with: - fetch-depth: 0 - persist-credentials: false - - name: Install nushell - uses: hustcer/setup-nu@1b8faed9a8ff673c8ce0beae243e0b72d0787241 # v3.30 - - name: Get changed packages - id: get-pkgs - shell: nu {0} - run: |- - print (pwd) - use ("./.github/workflows/bump-n-release.nu" | path expand) get-changed-pkgs - let pkgs = (get-changed-pkgs) - $"pkgs=($pkgs)\n" | save --append $env.GITHUB_OUTPUT - - update-changelog: - if: github.event_name != 'workflow_dispatch' - needs: [get-changed-pkgs] - permissions: - contents: read - pull-requests: read - runs-on: ubuntu-latest - strategy: - matrix: - pkg: ${{ fromJSON(needs.get-changed-pkgs.outputs.pkgs) }} - steps: - - uses: actions/checkout@v7.0.1 - with: - fetch-depth: 0 - fetch-tags: true - persist-credentials: false - - uses: cargo-bins/cargo-binstall@5885714d0a40a14b2535c6ffc051fd8e49aa9665 # v1.27.0 - - run: cargo binstall -y git-cliff - env: - GITHUB_TOKEN: ${{ github.token }} - - name: Install nushell - uses: hustcer/setup-nu@1b8faed9a8ff673c8ce0beae243e0b72d0787241 # v3.30 - - name: Generate a release notes - env: - PKG: ${{ matrix.pkg }} - GITHUB_TOKEN: ${{ github.token }} - GITHUB_REPO: ${{ github.repository }} - GIT_CLIFF_CONFIG: .config/cliff.toml - shell: nu {0} - run: |- - use ("./.github/workflows/bump-n-release.nu" | path expand) gen-changes - gen-changes $env.PKG --unreleased - let out = open --raw .config/ReleaseNotes.md - $"## ($env.PKG)\n\n($out)" | save --append $env.GITHUB_STEP_SUMMARY diff --git a/.github/workflows/set-version.yml b/.github/workflows/set-version.yml deleted file mode 100644 index 9986934b..00000000 --- a/.github/workflows/set-version.yml +++ /dev/null @@ -1,67 +0,0 @@ -name: Set release version - -# Opens a PR that sets the version of cpp-linter, cpp-linter-py and -# cpp-linter-js. Use it when the next version is not the one release-plz -# derives from commit messages, e.g. to start release candidates -# (2.1.0-rc.1) or to leave them (2.1.0). -# After that PR is merged, the release PR keeps the version and only -# adds the changelog. - -on: - workflow_dispatch: - inputs: - version: - description: The new version, e.g. 2.1.0 or 2.1.0-rc.1 - type: string - required: true - -permissions: {} - -jobs: - set-version: - runs-on: ubuntu-latest - steps: - - name: Check the version - env: - VERSION: ${{ inputs.version }} - run: |- - if [[ ! "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$ ]]; then - echo "::error::'${VERSION}' is not a version like 2.1.0 or 2.1.0-rc.1" - exit 1 - fi - # A PR opened with the default GITHUB_TOKEN would not run CI. - - name: Generate a GitHub App token - id: app-token - uses: actions/create-github-app-token@v3.4.0 - with: - client-id: ${{ vars.RELEASE_APP_CLIENT_ID }} - private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} - permission-contents: write # push the branch - permission-pull-requests: write # open the PR - - uses: actions/checkout@v7.0.1 - with: - token: ${{ steps.app-token.outputs.token }} - persist-credentials: true # needed to push the branch - - uses: cargo-bins/cargo-binstall@5885714d0a40a14b2535c6ffc051fd8e49aa9665 # v1.27.0 - - name: Install cargo-edit - run: cargo binstall -y cargo-edit - env: - GITHUB_TOKEN: ${{ github.token }} - - name: Open a PR with the new version - env: - VERSION: ${{ inputs.version }} - GH_TOKEN: ${{ steps.app-token.outputs.token }} - APP_SLUG: ${{ steps.app-token.outputs.app-slug }} - run: |- - bot_id=$(gh api "/users/${APP_SLUG}[bot]" --jq .id) - git config user.name "${APP_SLUG}[bot]" - git config user.email "${bot_id}+${APP_SLUG}[bot]@users.noreply.github.com" - branch="set-version-${VERSION}" - git switch -c "${branch}" - cargo set-version -p cpp-linter -p cpp-linter-py -p cpp-linter-js "${VERSION}" - .github/sync-node-version.sh - git commit -am "chore: set version to ${VERSION}" - git push origin "${branch}" - gh pr create --base main --head "${branch}" \ - --title "chore: set version to ${VERSION}" \ - --body "Sets cpp-linter, cpp-linter-py and cpp-linter-js to ${VERSION}. Once merged, the release PR keeps this version and adds the changelog." diff --git a/.gitignore b/.gitignore index b7a4bd29..8b17fa9e 100644 --- a/.gitignore +++ b/.gitignore @@ -346,5 +346,4 @@ docs/site cpp-linter-py/docs/cli_args.rst lcov.info coverage.json -.config/ReleaseNotes.md static-binaries-index.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 1a45b151..86279cc1 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -188,17 +188,6 @@ }, "problemMatcher": [], "group": "build" - }, - { - "type": "shell", - "command": "python", - "label": "workspace: bump version", - "args": [ - ".github/workflows/bump_version.py", - "${input:bumpComponent}" - ], - "problemMatcher": [], - "group": "none" } ], "inputs": [ @@ -207,18 +196,6 @@ "id": "binArgs", "description": "Arguments for the cpp-linter binary executable", "default": "-h" - }, - { - "type": "pickString", - "id": "bumpComponent", - "description": "Which version component to bump?", - "default": "patch", - "options": [ - "major", - "minor", - "patch", - "rc" - ] } ] } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8d9e7175..e812cd68 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -104,8 +104,15 @@ Releases are prepared by [release-plz] (see `release-plz.toml`). and to npm's `next` tag. To choose a version yourself (e.g. to start or end release candidates), -run the "Set release version" workflow. It opens a PR with the new version; -after it is merged, the release PR keeps that version. +open a PR that sets it (needs [cargo-edit]): + +```sh +cargo set-version -p cpp-linter -p cpp-linter-py -p cpp-linter-js 2.0.0 +.github/sync-node-version.sh +``` + +After it is merged, the release PR keeps that version. [nur]: https://nur-taskrunner.github.io/docs/ [release-plz]: https://release-plz.dev/ +[cargo-edit]: https://github.com/killercup/cargo-edit diff --git a/release-plz.toml b/release-plz.toml index 47266d49..664c1396 100644 --- a/release-plz.toml +++ b/release-plz.toml @@ -65,8 +65,8 @@ name = "clang-tools-manager" name = "cli-gen" release = false -# Same layout as the git-cliff config in .config/cliff.toml, adapted to the -# variables release-plz provides (`package`, `remote.link`, `previous.version`). +# Keeps the layout of the existing changelogs, using the variables +# release-plz provides (`package`, `remote.link`, `previous.version`). [changelog] header = """ # Changelog From e66a9bc8ac612842af674d1d210f0eecd076d155 Mon Sep 17 00:00:00 2001 From: Xianpeng Shen <3353385+shenxianpeng@users.noreply.github.com> Date: Wed, 25 Nov 2026 19:18:51 +0000 Subject: [PATCH 3/6] docs: note how to recover a release whose tag exists --- CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e812cd68..d53a9b3a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -103,6 +103,10 @@ Releases are prepared by [release-plz] (see `release-plz.toml`). publish to crates.io, PyPI and npm. Pre-releases (`-rc.N`) go to TestPyPI and to npm's `next` tag. +If release-plz pushes a tag but fails to create its GitHub release, it does +not retry (the tag already exists). Create that release by hand +(`gh release create --verify-tag`) and re-run the failed publish job. + To choose a version yourself (e.g. to start or end release candidates), open a PR that sets it (needs [cargo-edit]): From 48530886b17bd7653efdaaaf2397bb04d2dc5906 Mon Sep 17 00:00:00 2001 From: Xianpeng Shen <3353385+shenxianpeng@users.noreply.github.com> Date: Wed, 25 Nov 2026 19:49:51 +0000 Subject: [PATCH 4/6] build: run release builds only on the ready release PR binary-builds, python-packaging and node-js-packaging no longer run on pushes to main or on regular PRs. release-plz opens the release PR as a draft; marking it ready for review runs these builds on it as a dry run. Tags still publish, and workflow_dispatch can build any branch. --- .github/workflows/binary-builds.yml | 21 ++++++--------------- .github/workflows/node-js-packaging.yml | 25 ++++++------------------- .github/workflows/python-packaging.yml | 23 ++++++----------------- release-plz.toml | 3 +++ 4 files changed, 21 insertions(+), 51 deletions(-) diff --git a/.github/workflows/binary-builds.yml b/.github/workflows/binary-builds.yml index 936103bd..f1fcb01d 100644 --- a/.github/workflows/binary-builds.yml +++ b/.github/workflows/binary-builds.yml @@ -2,26 +2,13 @@ name: Binary builds on: push: - branches: [main] - paths: - - cpp-linter/src/** - - cpp-linter/Cargo.toml - - clang-tools-manager/src/** - - clang-tools-manager/Cargo.toml - - Cargo.toml - - Cargo.lock tags: - cpp-linter/v* - clang-tools-manager/v* pull_request: branches: [main] - paths: - - cpp-linter/src/** - - cpp-linter/Cargo.toml - - clang-tools-manager/src/** - - clang-tools-manager/Cargo.toml - - Cargo.toml - - Cargo.lock + types: [opened, synchronize, reopened, ready_for_review] + workflow_dispatch: env: CARGO_TERM_COLOR: always @@ -36,6 +23,10 @@ concurrency: jobs: seed-build-script: name: Pre-seed static binaries' versions + # On PRs, only the release PR is built, once it is marked ready for review. + if: >- + github.event_name != 'pull_request' + || (startsWith(github.head_ref, 'release-plz-') && !github.event.pull_request.draft) uses: $/.github/workflows/pre-seed-versions.yml create-assets: diff --git a/.github/workflows/node-js-packaging.yml b/.github/workflows/node-js-packaging.yml index 13bf645c..e44c8702 100644 --- a/.github/workflows/node-js-packaging.yml +++ b/.github/workflows/node-js-packaging.yml @@ -2,29 +2,12 @@ name: Node.js builds on: push: - branches: [main] - paths: - - cpp-linter/src/** - - cpp-linter/Cargo.toml - - Cargo.toml - - Cargo.lock - - bindings/node/** - - package.json - - yarn.lock - - .github/workflows/node-js-packaging.yml tags: - 'cpp-linter-js/v*' pull_request: branches: [main] - paths: - - cpp-linter/src/** - - cpp-linter/Cargo.toml - - Cargo.toml - - Cargo.lock - - bindings/node/** - - package.json - - yarn.lock - - .github/workflows/node-js-packaging.yml + types: [opened, synchronize, reopened, ready_for_review] + workflow_dispatch: env: DEBUG: napi:* @@ -40,6 +23,10 @@ concurrency: jobs: seed-build-script: name: Pre-seed static binaries' versions + # On PRs, only the release PR is built, once it is marked ready for review. + if: >- + github.event_name != 'pull_request' + || (startsWith(github.head_ref, 'release-plz-') && !github.event.pull_request.draft) uses: $/.github/workflows/pre-seed-versions.yml build: diff --git a/.github/workflows/python-packaging.yml b/.github/workflows/python-packaging.yml index 68903326..c9cf9f5b 100644 --- a/.github/workflows/python-packaging.yml +++ b/.github/workflows/python-packaging.yml @@ -10,27 +10,12 @@ name: Python builds on: push: - branches: [main] - paths: - - cpp-linter/**.{rs,toml} - - clang-tools-manager/src/** - - clang-tools-manager/Cargo.toml - - bindings/python/** - - Cargo.{toml,lock} - - .github/workflows/python-packaging.yml - - pyproject.toml tags: - 'cpp-linter-py/v*' pull_request: branches: [main] - paths: - - cpp-linter/**.{rs,toml} - - clang-tools-manager/src/** - - clang-tools-manager/Cargo.toml - - bindings/python/** - - Cargo.{toml,lock} - - .github/workflows/python-packaging.yml - - pyproject.toml + types: [opened, synchronize, reopened, ready_for_review] + workflow_dispatch: env: CARGO_TERM_COLOR: always @@ -45,6 +30,10 @@ concurrency: jobs: seed-build-script: name: Pre-seed static binaries' versions + # On PRs, only the release PR is built, once it is marked ready for review. + if: >- + github.event_name != 'pull_request' + || (startsWith(github.head_ref, 'release-plz-') && !github.event.pull_request.draft) uses: $/.github/workflows/pre-seed-versions.yml sdist: diff --git a/release-plz.toml b/release-plz.toml index 664c1396..478bd744 100644 --- a/release-plz.toml +++ b/release-plz.toml @@ -14,6 +14,9 @@ publish = false semver_check = false # Only release when a release PR (branch `release-plz-*`) is merged. release_always = false +# Open the release PR as a draft; marking it ready for review runs the +# release builds (binary-builds, python-packaging, node-js-packaging) on it. +pr_draft = true git_tag_name = "{{ package }}/v{{ version }}" git_release_name = "{{ package }}/v{{ version }}" # Pre-release versions (e.g. 2.1.0-rc.1) become GitHub pre-releases. From c699cb1cb91193eb50e31c7acafe5d29a84b4181 Mon Sep 17 00:00:00 2001 From: Xianpeng Shen <3353385+shenxianpeng@users.noreply.github.com> Date: Wed, 25 Nov 2026 20:19:06 +0000 Subject: [PATCH 5/6] build: publish crates with release-plz release-plz publishes cpp-linter and clang-tools-manager to crates.io in dependency order (trusted publishing), before tagging. binary-builds now only uploads the release assets, so the crates.io wait goes away. The release PR job runs after the release job, so it no longer needs a daily refresh. --- .github/workflows/binary-builds.yml | 50 +++-------------------------- .github/workflows/release-plz.yml | 25 +++++++++------ CONTRIBUTING.md | 14 ++++---- release-plz.toml | 8 ++++- 4 files changed, 35 insertions(+), 62 deletions(-) diff --git a/.github/workflows/binary-builds.yml b/.github/workflows/binary-builds.yml index f1fcb01d..7e186026 100644 --- a/.github/workflows/binary-builds.yml +++ b/.github/workflows/binary-builds.yml @@ -174,67 +174,25 @@ jobs: path: dist/clang-tools-${{ matrix.target }}* if-no-files-found: error - publish: + upload: if: startswith(github.ref, 'refs/tags/cpp-linter/v') || startswith(github.ref, 'refs/tags/clang-tools-manager/v') runs-on: ubuntu-latest - needs: [create-assets, seed-build-script] + needs: [create-assets] permissions: - id-token: write contents: write steps: - - uses: actions/checkout@v7.0.1 - with: - persist-credentials: false - - name: Install Rust - run: rustup update stable --no-self-update - name: Download built assets uses: actions/download-artifact@v8 with: pattern: ${{ startsWith(github.ref_name, 'cpp-linter') && 'cpp-linter' || 'clang-tools' }}-* path: dist merge-multiple: true - - name: Create a Github Release + - name: Upload assets to the GitHub release env: BIN_NAME: ${{ startsWith(github.ref_name, 'cpp-linter') && 'cpp-linter' || 'clang-tools' }} GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} GIT_REF: ${{ github.ref_name }} run: | files=$(ls dist/${BIN_NAME}*) gh release upload "${GIT_REF}" ${files} - - name: Restore build script seed - if: startsWith(github.ref_name, 'clang-tools-manager/v') - uses: actions/download-artifact@v8 - with: - name: ${{ needs.seed-build-script.outputs.artifact-name }} - path: clang-tools-manager - # release-plz pushes the clang-tools-manager and cpp-linter tags together; - # cpp-linter can only be published once its clang-tools-manager version is on crates.io. - - name: Wait for clang-tools-manager on crates.io - if: startsWith(github.ref_name, 'cpp-linter/v') - run: |- - ver=$(cargo metadata --format-version 1 --no-deps \ - | jq -r '.packages[] | select(.name == "clang-tools-manager") | .version') - for _ in $(seq 1 30); do - if curl -sSf -A "cpp-linter-rs CI (github.com/cpp-linter/cpp-linter-rs)" \ - "https://crates.io/api/v1/crates/clang-tools-manager/${ver}" > /dev/null; then - echo "clang-tools-manager ${ver} is on crates.io" - exit 0 - fi - echo "Waiting for clang-tools-manager ${ver} on crates.io" - sleep 60 - done - echo "::error::clang-tools-manager ${ver} is not on crates.io after 30 minutes" - exit 1 - - name: Establish provenance - id: auth - uses: rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1.0.6 - - name: Publish package - env: - PKG_NAME: ${{ startsWith(github.ref_name, 'cpp-linter') && 'cpp-linter' || 'clang-tools-manager' }} - CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} - # `--allow-dirty` is required for clang-tools-manager - # because the static-binaries-index.json file is flagged as "not checked in", - # but docs.rs build requires the static-binaries-index.json file present to - # avoid clang-tools-manager/build.rs using network access. - PUB_ARG: ${{ startsWith(github.ref_name, 'clang-tools-manager/v') && '--allow-dirty' || '' }} - run: cargo publish -p ${PKG_NAME} ${PUB_ARG} diff --git a/.github/workflows/release-plz.yml b/.github/workflows/release-plz.yml index ebc33db5..b6b13f32 100644 --- a/.github/workflows/release-plz.yml +++ b/.github/workflows/release-plz.yml @@ -1,26 +1,25 @@ name: Release-plz # Keeps the release PR up to date on every push to main. -# When the release PR is merged, tags each released package and creates -# its GitHub release; the tags trigger the deploy workflows. +# When the release PR is merged, publishes the crates to crates.io, tags each +# released package and creates its GitHub release; the tags trigger the +# workflows that upload the binaries and publish to PyPI and npm. # See release-plz.toml for the details. on: push: branches: [main] - # cpp-linter and clang-tools-manager are compared with crates.io, which is - # updated only after the deploy workflows finish; refresh the PR daily. - schedule: - - cron: "17 3 * * *" workflow_dispatch: permissions: {} jobs: release: - name: Tag and create GitHub releases + name: Publish, tag and create GitHub releases if: github.repository_owner == 'cpp-linter' && github.event_name == 'push' runs-on: ubuntu-latest + permissions: + id-token: write # trusted publishing to crates.io steps: # Tags pushed with the default GITHUB_TOKEN do not trigger other workflows, # so release-plz uses a token of the release GitHub App. @@ -39,7 +38,13 @@ jobs: persist-credentials: true # needed to push tags - name: Install Rust run: rustup update stable --no-self-update - - name: Tag released packages + # Packaged with clang-tools-manager so that docs.rs builds need no network. + - name: Download static binaries index + run: >- + curl --fail --silent --show-error --location --retry 3 + --output clang-tools-manager/static-binaries-index.json + https://cpp-linter.github.io/clang-tools-static-binaries/index.json + - name: Publish and tag released packages uses: release-plz/action@66b324fd6c72d05d2a08568492ecdd62bfb8a62b # v0.5.148 with: command: release @@ -48,7 +53,9 @@ jobs: release-pr: name: Update the release PR - if: github.repository_owner == 'cpp-linter' + # After `release`, so that versions just published are on crates.io. + needs: [release] + if: ${{ !failure() && !cancelled() && github.repository_owner == 'cpp-linter' }} runs-on: ubuntu-latest concurrency: group: release-plz-${{ github.ref }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d53a9b3a..d7f63ed8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -97,15 +97,17 @@ Releases are prepared by [release-plz] (see `release-plz.toml`). changelog entries. 2. cpp-linter, cpp-linter-py and cpp-linter-js always get the same version. clang-tools-manager has its own version. -3. Review the release PR (the changelog can be edited there) and merge it. -4. release-plz then pushes a `{package}/v{version}` tag for each released - package and creates its GitHub release. The tags trigger the builds that - publish to crates.io, PyPI and npm. Pre-releases (`-rc.N`) go to TestPyPI - and to npm's `next` tag. +3. The release PR is a draft. Mark it ready for review to run the release + builds (binaries, Python wheels, Node.js packages) on it, then merge it. +4. release-plz then publishes cpp-linter and clang-tools-manager to + crates.io, pushes a `{package}/v{version}` tag for each released package + and creates its GitHub release. The tags trigger the builds that upload + the binaries and publish to PyPI and npm. Pre-releases (`-rc.N`) go to + TestPyPI and to npm's `next` tag. If release-plz pushes a tag but fails to create its GitHub release, it does not retry (the tag already exists). Create that release by hand -(`gh release create --verify-tag`) and re-run the failed publish job. +(`gh release create --verify-tag`) and re-run the failed job that was triggered by the tag. To choose a version yourself (e.g. to start or end release candidates), open a PR that sets it (needs [cargo-edit]): diff --git a/release-plz.toml b/release-plz.toml index 478bd744..26104fd8 100644 --- a/release-plz.toml +++ b/release-plz.toml @@ -9,7 +9,8 @@ # - node-js-packaging.yml: npm, `next` dist-tag for pre-releases (cpp-linter-js) [workspace] -# Publishing is done by the tag-triggered workflows above. +# Only cpp-linter and clang-tools-manager are published by release-plz (to +# crates.io, see below); PyPI and npm are published by the tag-triggered workflows. publish = false semver_check = false # Only release when a release PR (branch `release-plz-*`) is merged. @@ -29,6 +30,7 @@ git_release_latest = false name = "cpp-linter" version_group = "cpp-linter" git_release_latest = true +publish = true [[package]] name = "cpp-linter-py" @@ -62,6 +64,10 @@ See the [cpp-linter {{ version }} release](https://github.com/cpp-linter/cpp-lin [[package]] name = "clang-tools-manager" +publish = true +# The packaged static-binaries-index.json (downloaded in release-plz.yml) is +# not checked in, but docs.rs builds need it. +publish_allow_dirty = true # Only used to generate the docs. [[package]] From 0d486c63270bb1dc7e732a017049153b624590b4 Mon Sep 17 00:00:00 2001 From: Xianpeng Shen <3353385+shenxianpeng@users.noreply.github.com> Date: Wed, 25 Nov 2026 20:36:50 +0000 Subject: [PATCH 6/6] docs: cover releases published without a tag --- CONTRIBUTING.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d7f63ed8..07d5ad2f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -105,9 +105,17 @@ Releases are prepared by [release-plz] (see `release-plz.toml`). the binaries and publish to PyPI and npm. Pre-releases (`-rc.N`) go to TestPyPI and to npm's `next` tag. -If release-plz pushes a tag but fails to create its GitHub release, it does -not retry (the tag already exists). Create that release by hand -(`gh release create --verify-tag`) and re-run the failed job that was triggered by the tag. +If a release stops halfway, release-plz does not retry it: it skips a package +whose tag already exists or whose version is already on crates.io. Create the +missing GitHub release by hand, which also creates the tag if it is missing: + +```sh +# add --prerelease for -rc.N versions +gh release create --target +``` + +A new tag starts the tag-triggered builds; if the tag already existed, +re-run its failed jobs instead. To choose a version yourself (e.g. to start or end release candidates), open a PR that sets it (needs [cargo-edit]):