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/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..7e186026 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: @@ -183,49 +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 - - 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/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/node-js-packaging.yml b/.github/workflows/node-js-packaging.yml index ec2c46d5..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: @@ -358,6 +345,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/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/.github/workflows/release-plz.yml b/.github/workflows/release-plz.yml new file mode 100644 index 00000000..b6b13f32 --- /dev/null +++ b/.github/workflows/release-plz.yml @@ -0,0 +1,99 @@ +name: Release-plz + +# Keeps the release PR up to date on every push to main. +# 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] + workflow_dispatch: + +permissions: {} + +jobs: + release: + 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. + - 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 + # 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 + env: + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} + + release-pr: + name: Update the release PR + # 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 }} + 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/.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 d4a3e7f3..07d5ad2f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -87,4 +87,46 @@ 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. 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 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]): + +```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 new file mode 100644 index 00000000..26104fd8 --- /dev/null +++ b/release-plz.toml @@ -0,0 +1,139 @@ +# 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] +# 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. +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. +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 +publish = 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" +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]] +name = "cli-gen" +release = false + +# Keeps the layout of the existing changelogs, using 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" }, +]