From bf4c151205d0560eefbf7a64cefd2524c57813db Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdx@users.noreply.github.com> Date: Sat, 16 Mar 2024 21:22:02 -0500 Subject: [PATCH] ci: use custom release-plz logic --- .github/workflows/release-plz.yml | 16 +++++++++++-- .github/workflows/test.yml | 1 + .mise.toml | 7 +++--- .mise/tasks/release-plz | 29 +++++++++++++++++++++++ cliff.toml | 39 +++++++++++++++++++++++-------- release-plz.toml | 16 ------------- 6 files changed, 77 insertions(+), 31 deletions(-) create mode 100755 .mise/tasks/release-plz delete mode 100644 release-plz.toml diff --git a/.github/workflows/release-plz.yml b/.github/workflows/release-plz.yml index 8ca9dc7..17a5dc2 100644 --- a/.github/workflows/release-plz.yml +++ b/.github/workflows/release-plz.yml @@ -8,9 +8,10 @@ on: push: branches: - main + - release-plz concurrency: - group: release-plz-${{ github.ref }} + group: release-plz jobs: release-plz: @@ -20,7 +21,18 @@ jobs: with: fetch-depth: 0 token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }} - - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + with: + shared-key: test + save-if: false + - uses: jdx/mise-action@v2 + with: + experimental: true + - run: mise trust --all + - run: mise run release-plz + env: + GITHUB_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }} + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} - uses: MarcoIeni/release-plz-action@v0.5 env: GITHUB_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9a54742..b9371b8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,6 +19,7 @@ jobs: - run: rustup toolchain install stable --profile minimal - uses: Swatinem/rust-cache@v2 with: + shared-key: test save-if: ${{ github.ref_name == 'main' }} - uses: jdx/mise-action@v2 - run: mise r build diff --git a/.mise.toml b/.mise.toml index c18ca65..475f173 100644 --- a/.mise.toml +++ b/.mise.toml @@ -2,6 +2,10 @@ CARGO_TERM_COLOR = 'always' _.path = ["./target/debug"] +[tools] +"npm:prettier" = "latest" +"cargo:cargo-edit" = "latest" + [tasks.build] sources = ['{cli/,}src/**/*.rs', '{cli/,}Cargo.toml'] outputs = ['target/debug/rtx'] @@ -74,6 +78,3 @@ run = [ [tasks.release] run = "cargo release --workspace" - -[tools] -"npm:prettier" = "latest" diff --git a/.mise/tasks/release-plz b/.mise/tasks/release-plz new file mode 100755 index 0000000..a269c38 --- /dev/null +++ b/.mise/tasks/release-plz @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -euxo pipefail + +released_versions="$(git tag --list | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$')" +cur_version="$(cargo pkgid usage-lib | cut -d# -f2)" +if ! echo "$released_versions" | grep -q "^$cur_version$"; then + echo "Releasing $cur_version" + cargo publish -p usage-lib + cargo publish -p usage-cli +fi + +version="$(git cliff --bumped-version)" +changelog="$(git cliff --bump --unreleased --strip all)" + +git cliff --bump -o CHANGELOG.md +cargo set-version "${version#v}" + +git config user.name mise-en-dev +git config user.email 123107610+mise-en-dev@users.noreply.github.com +cargo update +git add \ + Cargo.lock \ + Cargo.toml \ + CHANGELOG.md +git checkout -B release +git commit -m "Release $version" +git push origin release --force +gh pr create --title "Release $version" --body "$changelog" --label "release" || + gh pr edit --title "Release $version" --body "$changelog" diff --git a/cliff.toml b/cliff.toml index 2c1a8a2..cfbfb91 100644 --- a/cliff.toml +++ b/cliff.toml @@ -14,18 +14,32 @@ All notable changes to this project will be documented in this file.\n # template for the changelog body # https://keats.github.io/tera/docs/#introduction body = """ +--- {% if version %}\ - ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} + {% if previous.version %}\ + ## [{{ version | trim_start_matches(pat="v") }}]($REPO/compare/{{ previous.version }}..{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} + {% else %}\ + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} + {% endif %}\ {% else %}\ ## [unreleased] {% endif %}\ {% for group, commits in commits | group_by(attribute="group") %} ### {{ group | striptags | trim | upper_first }} - {% for commit in commits %} - - {% if commit.scope %}*({{ commit.scope }})* {% endif %}\ - {% if commit.breaking %}[**breaking**] {% endif %}\ - {{ commit.message | upper_first }}\ - {% endfor %} + {% for commit in commits + | filter(attribute="scope") + | sort(attribute="scope") %} + - **({{commit.scope}})**{% if commit.breaking %} [**breaking**]{% endif %} \ + {{ commit.message }} - ([{{ commit.id | truncate(length=7, end="") }}]($REPO/commit/{{ commit.id }})) - {{ commit.github.username | default(value=commit.author.name) }} + {%- endfor -%} + {% raw %}\n{% endraw %}\ + {%- for commit in commits %} + {%- if commit.scope -%} + {% else -%} + - {% if commit.breaking %} [**breaking**]{% endif %}\ + {{ commit.message }} - ([{{ commit.id | truncate(length=7, end="") }}]($REPO/commit/{{ commit.id }})) - {{ commit.github.username | default(value=commit.author.name) }} + {% endif -%} + {% endfor -%} {% endfor %}\n """ # template for the changelog footer @@ -34,9 +48,8 @@ footer = """ """ # remove the leading and trailing s trim = true -# postprocessors postprocessors = [ - # { pattern = '', replace = "https://github.com/orhun/git-cliff" }, # replace repository URL + { pattern = '\$REPO', replace = "https://github.com/jdx/mise" }, ] [git] @@ -57,6 +70,7 @@ commit_preprocessors = [ # regex for parsing and grouping commits commit_parsers = [ { message = "^feat", group = "🚀 Features" }, + { message = "^fix\\(deps\\)", skip = true }, { message = "^fix", group = "🐛 Bug Fixes" }, { message = "^doc", group = "📚 Documentation" }, { message = "^perf", group = "⚡ Performance" }, @@ -67,6 +81,7 @@ commit_parsers = [ { message = "^chore\\(deps.*\\)", skip = true }, { message = "^chore\\(pr\\)", skip = true }, { message = "^chore\\(pull\\)", skip = true }, + { message = "^chore: Release", skip = true }, { message = "^chore|^ci", group = "⚙️ Miscellaneous Tasks" }, { body = ".*security", group = "🛡️ Security" }, { message = "^revert", group = "◀️ Revert" }, @@ -76,9 +91,9 @@ protect_breaking_commits = false # filter out the commits that are not matched by commit parsers filter_commits = false # regex for matching git tags -tag_pattern = "^v[0-9].[0-9].[0-9]$" +tag_pattern = 'v\d+\.\d+\.\d+' # regex for skipping tags -skip_tags = "^(v0.1.9|v0.1.8|v0.1.7|v0.1.6|v0.1.5|v0.1.4|v0.1.3|v0.1.2)$" +skip_tags = '^v(1|2023)\.' # regex for ignoring tags # ignore_tags = "" # sort the tags topologically @@ -87,3 +102,7 @@ topo_order = false sort_commits = "oldest" # limit the number of commits included in the changelog. # limit_commits = 42 + +[remote.github] +owner = "jdx" +repo = "usage" diff --git a/release-plz.toml b/release-plz.toml deleted file mode 100644 index 6f3b736..0000000 --- a/release-plz.toml +++ /dev/null @@ -1,16 +0,0 @@ -[workspace] -changelog_update = false -dependencies_update = true -git_release_enable = false -git_tag_enable = false -pr_labels = ["release"] -semver_check = false # TODO: disable after 1.0.0 - -[[package]] -name = "usage-cli" -changelog_include = ["usage-lib"] -changelog_path = "./CHANGELOG.md" -changelog_update = true -git_release_enable = true -git_tag_enable = true -git_tag_name = "v${version}"