Skip to content

Commit cb0c45f

Browse files
authored
feat: publish releases after updating notes (#35)
- Add `--then-undraft` to publish releases after notes update succeeds - Document the option and cover success, failure, and skip cases
1 parent c9728be commit cb0c45f

3 files changed

Lines changed: 106 additions & 4 deletions

File tree

‎README.md‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The lookup uses `cargo metadata --no-deps`, ignores non-workspace packages, and
1818
Contains release-plz post-processing commands:
1919

2020
- `x52-bump-changelogs` checks out a release-plz pull request, adds the released versions to crate changelogs, updates README version links, and pushes a commit when anything changed.
21-
- `x52-update-release-notes` copies the matching changelog sections into GitHub releases.
21+
- `x52-update-release-notes` copies the matching changelog sections into GitHub releases. Use `--then-undraft` to publish each release after its notes update succeeds.
2222
- `x52-comment-release-pr` adds or updates a draft-release link comment on the merged release pull request.
2323
- `x52-comment-release-assets-uploaded` adds or updates a comment after the release assets are uploaded.
2424
- `x52-update-homebrew-tap` updates macOS checksums in `x52dev/homebrew-tap` and opens a formula pull request.
@@ -115,6 +115,17 @@ For GitHub Actions, enter the development shell before invoking the release comm
115115
116116
Pass release-plz output through `RELEASE_PLZ_PR_JSON` or `RELEASE_PLZ_RELEASES_JSON`, and provide `GH_TOKEN` for GitHub mutations.
117117

118+
`x52-update-release-notes` leaves the release's draft status unchanged by default.
119+
To publish each release after its changelog notes are set, run:
120+
121+
```sh
122+
x52-update-release-notes --then-undraft
123+
```
124+
125+
The command skips releases whose package has no `CHANGELOG.md`. A failed notes
126+
update stops the command before it publishes that release. An empty changelog
127+
section uses the existing fallback note and can still be published.
128+
118129
The commands use fixed `x52-` HTML markers. They make retries update the existing comment instead of creating another one:
119130

120131
```sh

‎release-tools/test.bash‎

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ printf ' <%s>' "$@" >>"$COMMAND_LOG"
9494
printf '\n' >>"$COMMAND_LOG"
9595
9696
case "$*" in
97+
'release edit demo-v1.1.0 --notes='*)
98+
if [[ "${RELEASE_NOTES_EDIT_FAIL:-false}" == "true" ]]; then
99+
exit 17
100+
fi
101+
;;
97102
*'/commits/'*'/pulls'*)
98103
printf '42\n'
99104
;;
@@ -202,10 +207,69 @@ grep -Fq 'gh <pr> <checkout> <42>' "$command_log"
202207
grep -Fq 'git <push>' "$command_log"
203208

204209
export RELEASE_PLZ_RELEASES_JSON='[{"package_name":"demo","version":"1.1.0","tag":"demo-v1.1.0"}]'
205-
x52-update-release-notes
210+
COMMAND_LOG="$test_root/release-notes-default.log" x52-update-release-notes
211+
212+
cat >"$test_root/expected-release-notes-default.log" <<'EOF'
213+
gh <release> <edit> <demo-v1.1.0> <--notes=- Added feature.>
214+
EOF
215+
216+
diff -u "$test_root/expected-release-notes-default.log" "$test_root/release-notes-default.log"
217+
218+
COMMAND_LOG="$test_root/release-notes-undraft.log" x52-update-release-notes --then-undraft
219+
220+
cat >"$test_root/expected-release-notes-undraft.log" <<'EOF'
221+
gh <release> <edit> <demo-v1.1.0> <--notes=- Added feature.>
222+
gh <release> <edit> <demo-v1.1.0> <--draft=false>
223+
EOF
224+
225+
diff -u "$test_root/expected-release-notes-undraft.log" "$test_root/release-notes-undraft.log"
226+
227+
if COMMAND_LOG="$test_root/release-notes-failed.log" RELEASE_NOTES_EDIT_FAIL=true \
228+
x52-update-release-notes --then-undraft; then
229+
echo "Expected a failed release notes update to fail" >&2
230+
exit 1
231+
else
232+
[[ "$?" == 17 ]]
233+
fi
234+
235+
diff -u "$test_root/expected-release-notes-default.log" "$test_root/release-notes-failed.log"
236+
237+
mv "$fixture_root/CHANGELOG.md" "$fixture_root/CHANGELOG.md.saved"
238+
touch "$test_root/release-notes-missing.log"
239+
COMMAND_LOG="$test_root/release-notes-missing.log" x52-update-release-notes --then-undraft
240+
[[ ! -s "$test_root/release-notes-missing.log" ]]
241+
242+
cat >"$fixture_root/CHANGELOG.md" <<'EOF'
243+
# Changelog
244+
245+
## 1.1.0
246+
EOF
247+
248+
COMMAND_LOG="$test_root/release-notes-empty.log" x52-update-release-notes --then-undraft
249+
250+
cat >"$test_root/expected-release-notes-empty.log" <<'EOF'
251+
gh <release> <edit> <demo-v1.1.0> <--notes=- No significant changes since the previous release.>
252+
gh <release> <edit> <demo-v1.1.0> <--draft=false>
253+
EOF
254+
255+
diff -u "$test_root/expected-release-notes-empty.log" "$test_root/release-notes-empty.log"
256+
mv "$fixture_root/CHANGELOG.md.saved" "$fixture_root/CHANGELOG.md"
257+
258+
touch "$test_root/release-notes-invalid-option.log"
259+
if COMMAND_LOG="$test_root/release-notes-invalid-option.log" \
260+
x52-update-release-notes --unknown >"$test_root/release-notes-invalid-option-output.log" 2>&1; then
261+
echo "Expected an unknown release notes option to fail" >&2
262+
exit 1
263+
else
264+
[[ "$?" == 2 ]]
265+
fi
266+
267+
[[ ! -s "$test_root/release-notes-invalid-option.log" ]]
268+
[[ "$(<"$test_root/release-notes-invalid-option-output.log")" == 'Unknown argument: --unknown' ]]
206269

207-
grep -Fq 'gh <release> <edit> <demo-v1.1.0>' "$command_log"
208-
grep -Fq '<--notes=- Added feature.>' "$command_log"
270+
env -u RELEASE_PLZ_RELEASES_JSON X52_CARGO=/nonexistent \
271+
x52-update-release-notes --help >"$test_root/release-notes-help.log"
272+
[[ "$(<"$test_root/release-notes-help.log")" == *'Usage: x52-update-release-notes [--then-undraft]'* ]]
209273

210274
export GITHUB_REPOSITORY='example/demo'
211275
x52-comment-release-pr "$RELEASE_PLZ_RELEASES_JSON" deadbeef >"$comment_log"

‎release-tools/update-release-notes.bash‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
set -eEuo pipefail
22
shopt -s inherit_errexit
33

4+
undraft=false
5+
6+
while (( $# > 0 )); do
7+
case "$1" in
8+
--then-undraft)
9+
undraft=true
10+
;;
11+
-h | --help)
12+
echo "Usage: x52-update-release-notes [--then-undraft]"
13+
echo "Copy changelog notes to GitHub releases."
14+
echo "Use --then-undraft to publish each release after its notes update succeeds."
15+
exit 0
16+
;;
17+
*)
18+
echo "Unknown argument: $1" >&2
19+
exit 2
20+
;;
21+
esac
22+
23+
shift
24+
done
25+
426
release_plz_releases_json="${RELEASE_PLZ_RELEASES_JSON:?RELEASE_PLZ_RELEASES_JSON is required}"
527
cargo_bin="${X52_CARGO:-cargo}"
628
gh_bin="${X52_GH:-gh}"
@@ -76,6 +98,11 @@ update_release_notes() {
7698
fi
7799

78100
"$gh_bin" release edit "$tag" --notes="$notes"
101+
102+
if [[ "$undraft" == "true" ]]; then
103+
echo "Publishing ${tag}"
104+
"$gh_bin" release edit "$tag" --draft=false
105+
fi
79106
}
80107

81108
while IFS=$'\t' read -r name version tag; do

0 commit comments

Comments
 (0)