From 05c7a1f019a485508d423d8e9c4c456afeac510d Mon Sep 17 00:00:00 2001 From: Daniel Parks Date: Wed, 22 Oct 2025 13:23:49 -0700 Subject: [PATCH 1/2] =?UTF-8?q?Improvements=20to=20`release.sh`=20and=20?= =?UTF-8?q?=E2=80=9CRelease=E2=80=9D=20GitHub=20workflow.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yaml | 24 ++------ release.sh | 109 +++++++++++++++++++++++++-------- 2 files changed, 89 insertions(+), 44 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index ae86dd56..7375f4ce 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,9 +1,8 @@ -# Mostly copied from https://github.com/taiki-e/cargo-hack/blob/72a9fc95377c453a18026329577c59fa60bfa737/.github/workflows/release.yml +# Mostly copied from https://github.com/taiki-e/cargo-hack/blob/main/.github/workflows/release.yml name: Release permissions: - # TODO: once `releases: write` is supported, use it instead. - contents: write + contents: read on: push: @@ -12,31 +11,20 @@ on: env: CARGO_INCREMENTAL: 0 + CARGO_NET_GIT_FETCH_WITH_CLI: true CARGO_NET_RETRY: 10 CARGO_TERM_COLOR: always RUST_BACKTRACE: 1 RUSTFLAGS: -D warnings RUSTUP_MAX_RETRIES: 10 -defaults: - run: - # Setting shell: bash explicitly activates pipefail - shell: bash - jobs: create-release: if: github.repository_owner == 'danielparks' runs-on: ubuntu-latest + permissions: + contents: write steps: - - uses: actions/checkout@v5 - with: - persist-credentials: false - - name: Install Rust - run: rustup update stable --no-self-update - - run: cargo package - - uses: taiki-e/create-gh-release-action@v1 + - uses: danielparks/github-actions/create-release@main with: - changelog: CHANGELOG.md - title: Release $version - branch: main token: ${{ secrets.GITHUB_TOKEN }} diff --git a/release.sh b/release.sh index 81f10f3b..4d10edda 100755 --- a/release.sh +++ b/release.sh @@ -4,6 +4,7 @@ set -eo pipefail shopt -s extglob version=$1 +branch_name=$(git rev-parse --abbrev-ref HEAD) awk-in-place () { local tmpfile=$(mktemp) @@ -14,6 +15,47 @@ awk-in-place () { rm "$tmpfile" } +check-changes () { + if git ls-files --exclude-standard --other | grep . >/dev/null ; then + echo 'Found untracked files:' >&2 + git ls-files --exclude-standard --other | sed -e 's/^/ /' >&2 + echo >&2 + echo 'Please commit changes before proceeding.' >&2 + return 1 + fi + + git diff --color --exit-code HEAD || { + echo >&2 + echo 'Please commit changes before proceeding.' >&2 + return 1 + } +} + +auto-pr () { + pr_url=$((gh pr view --json url,closed 2>/dev/null || true) \ + | jq -r 'select(.closed | not) | .url') + + if [[ "$pr_url" ]] ; then + echo "Found existing PR: $pr_url" + echo + else + # Create a PR + gh pr create --fill-verbose --title "$1" + fi + + gh pr merge --disable-auto --delete-branch + sleep 3 + gh pr checks --watch --fail-fast + + git checkout main + git pull + git merge --ff-only "$branch_name" + git push origin HEAD + + git branch -d "$branch_name" + git push origin --delete "$branch_name" +} + confirm () { local prompt="$1" local answer @@ -25,10 +67,31 @@ confirm () { } case $version in - +([0-9]).+([0-9]).+([0-9])) ;; # Good + +([0-9]).+([0-9]).+([0-9])*) ;; # Good *) echo "Usage $0 VERSION" >&2 ; exit 1 ;; esac +command -v gh &>/dev/null || { + echo "gh not installed (https://cli.github.com)" >&2 + exit 1 +} + +command -v jq &>/dev/null || { + echo "jq not installed (https://jqlang.org)" >&2 + exit 1 +} + +command -v parse-changelog &>/dev/null || { + echo "parse-changelog not installed (https://github.com/taiki-e/parse-changelog)" >&2 + exit 1 +} + +if [[ "$branch_name" = main ]] ; then + git switch -c "release-$version" +fi + +check-changes + echo 'Making sure version is correct.' awk-in-place Cargo.toml ' @@ -38,15 +101,8 @@ awk-in-place Cargo.toml ' } { print }' -awk-in-place README.md '{ - sub(/https:\/\/docs\.rs\/htmlize\/[0-9]+.[0-9]+.[0-9]+\//, "https://docs.rs/htmlize/'$version'/") - print - }' - cargo check --quiet -cargo semver-checks check-release - awk-in-place CHANGELOG.md ' /^## / && !done { $0 = "## Release '$version' ('$(date +%Y-%m-%d)')" @@ -54,21 +110,6 @@ awk-in-place CHANGELOG.md ' } { print }' -# Check for changes -if git ls-files --exclude-standard --other | grep . >/dev/null ; then - echo 'Found untracked files:' >&2 - git ls-files --exclude-standard --other | sed -e 's/^/ /' >&2 - echo >&2 - echo 'Please commit changes before proceeding.' >&2 - exit 1 -fi - -git diff --color --exit-code HEAD || { - echo >&2 - echo 'Please commit changes before proceeding.' >&2 - exit 1 -} - # Confirm changelog changelog=$(mktemp) { @@ -81,10 +122,23 @@ cat "$changelog" echo confirm 'Release notes displayed above. Continue?' -cargo publish +# Commit version bump if necessary. +check-changes &>/dev/null || { + git add -u + git commit --cleanup=verbatim --file - < Date: Thu, 23 Oct 2025 00:54:21 -0700 Subject: [PATCH 2/2] `release.sh`: Fix docs.rs links in README.md and run semver-checks. --- release.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/release.sh b/release.sh index 4d10edda..a46faaca 100755 --- a/release.sh +++ b/release.sh @@ -31,6 +31,10 @@ check-changes () { } } +crate-names () { + cargo metadata --format-version 1 --no-deps | jq -r '.packages[].name' +} + auto-pr () { pr_url=$((gh pr view --json url,closed 2>/dev/null || true) \ | jq -r 'select(.closed | not) | .url') @@ -101,8 +105,23 @@ awk-in-place Cargo.toml ' } { print }' +# Fix docs.rs links in README, if present +for name in $(crate-names) ; do + awk-in-place README.md '{ + sub(/https:\/\/docs\.rs\/'"$name"'\/[0-9]+.[0-9]+.[0-9]+\//, \ + "https://docs.rs/'"$name"'/'$version'/") + print + }' +done + cargo check --quiet +# Do semver checks only if there is a version on crates.io to compare to. +# FIXME: can’t tell if crates.io search failed for another reason. +if (cd / && cargo info "$(crate-names | head -1)" &>/dev/null) ; then + cargo semver-checks || { echo ; confirm 'Release anyway?' ; } +fi + awk-in-place CHANGELOG.md ' /^## / && !done { $0 = "## Release '$version' ('$(date +%Y-%m-%d)')"