Skip to content

Commit 379b8b7

Browse files
authored
fix(changelog): use effect, because hidden does nothing (#35)
1 parent cdb93d9 commit 379b8b7

8 files changed

Lines changed: 462 additions & 27 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ jobs:
2525
build-command: pnpm run build
2626
test-command: pnpm run test
2727
# `build/` is generated, so the only way to know the published tarball
28-
# isn't empty is to pack one.
29-
extra-command: npm pack --dry-run
28+
# isn't empty is to pack one. changelog:check renders a synthetic history
29+
# of every commit type through the real changelog preset and fails if a
30+
# type renders against policy or a breaking change goes missing.
31+
#
32+
# One `extra-command`, so they're chained. `&&` short-circuits, which is
33+
# what we want: either failing fails the job.
34+
extra-command: npm pack --dry-run && pnpm run changelog:check
3035
# Nothing here uses turbo.
3136
turbo-cache: false
3237

‎.github/workflows/release.yml‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
- run: pnpm run build
5959

6060
# Publishes to npm, pushes the annotated tag and creates the GitHub
61-
# release. The version bump commit stays local, see .release-it.cjs.
61+
# release. The version bump commit stays local, see .release-it.mjs.
6262
- name: Release
6363
id: release
6464
env:
@@ -79,9 +79,25 @@ jobs:
7979
args="$args --dry-run"
8080
fi
8181
82+
before=$(node -p "require('./package.json').version")
8283
pnpm run release $args
83-
84-
echo "version=$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT"
84+
after=$(node -p "require('./package.json').version")
85+
86+
echo "version=$after" >> "$GITHUB_OUTPUT"
87+
88+
# Now that the changelog types carry `effect`, only the `bump` ones
89+
# can raise a version, so a cycle of nothing but docs/chore/build/
90+
# refactor commits recommends nothing. release-it prints "No new
91+
# version to release", exits 0 and leaves the tree alone. Without
92+
# this flag the next step would push an empty branch, fail to open a
93+
# PR against it and report that npm and the tag are out when neither
94+
# is. Re-run with the `increment` input if a release was the point.
95+
if [ "$before" = "$after" ]; then
96+
echo "released=false" >> "$GITHUB_OUTPUT"
97+
echo "::notice::No new version to release. Nothing was published or tagged. Dispatch again with an explicit \`increment\` to force one."
98+
else
99+
echo "released=true" >> "$GITHUB_OUTPUT"
100+
fi
85101
86102
# master requires status checks and a fresh commit has none, so the bump
87103
# has to arrive as a PR. Merge commit, not squash: the tag points at the
@@ -99,7 +115,7 @@ jobs:
99115
# npm, the tag and the GitHub release are already out at that point, so
100116
# only the bump on master is waiting.
101117
- name: Land the version bump on master
102-
if: ${{ !inputs.dry-run }}
118+
if: ${{ !inputs.dry-run && steps.release.outputs.released == 'true' }}
103119
env:
104120
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105121
VERSION: ${{ steps.release.outputs.version }}
@@ -130,7 +146,10 @@ jobs:
130146
echo "opened $url"
131147
132148
# The merge commit lands on master too, so it needs a conventional
133-
# subject. `.release-it.cjs` filters `chore(release)` out of the
134-
# changelog, so neither this nor the bump commit shows up next time.
149+
# subject. `--merge` rather than `--squash` is what keeps both this
150+
# and the bump commit out of the next changelog: conventional-changelog
151+
# skips merge commits, and a merge is what this produces. There used
152+
# to be a `commitFilter` in the release-it config claiming that job,
153+
# but the plugin never read the key.
135154
gh pr merge "$number" --auto --merge --delete-branch \
136155
--subject "chore(release): v$VERSION (#$number)" --body ""

.release-it.cjs renamed to .release-it.mjs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@
33
* release workflow can't push the version bump straight to it. release-it
44
* commits and tags locally, pushes only the tag (tags aren't covered by a
55
* branch ruleset), and the workflow lands the bump commit through a PR.
6+
*
7+
* ESM rather than `.release-it.cjs` so the type list can live in
8+
* tools/changelog-preset.mjs and be shared with tools/changelog-check.mjs.
9+
* conventional-changelog-conventionalcommits is ESM-only, so a CJS config
10+
* could only reach it through a dynamic import.
611
*/
7-
module.exports = {
12+
import { TYPES } from "./tools/changelog-preset.mjs";
13+
14+
const config = {
815
git: {
916
requireBranch: "master",
1017
commitMessage: "chore(release): v${version}",
@@ -39,26 +46,21 @@ module.exports = {
3946
"@release-it/conventional-changelog": {
4047
infile: "CHANGELOG.md",
4148
header: "# Changelog",
42-
// Each release leaves a `chore(release)` bump commit and the merge commit
43-
// that lands it. Neither is worth a changelog line.
44-
commitFilter: (commit) =>
45-
!(commit.header ?? "").startsWith("chore(release)"),
49+
// There used to be a `commitFilter` here, meant to keep the
50+
// `chore(release)` bump commits out of the notes. The plugin never read
51+
// it: it destructures `preset`, `context`, `gitRawCommitsOpts`,
52+
// `parserOpts`, `writerOpts` and `whatBump`, and `commitFilter` appears
53+
// nowhere in its source. Nothing was lost by it doing nothing, because
54+
// the bump commits reach master as merge commits (both v1.0.12's and
55+
// v1.0.13's have two parents) and conventional-changelog skips those
56+
// anyway. Removing the key so the config stops claiming a behaviour it
57+
// never had.
4658
preset: {
4759
name: "conventionalcommits",
48-
types: [
49-
{ type: "feat", section: "Features" },
50-
{ type: "fix", section: "Bug Fixes" },
51-
{ type: "perf", section: "Performance" },
52-
{ type: "refactor", section: "Code Refactoring" },
53-
{ type: "docs", section: "Documentation" },
54-
{ type: "build", section: "Build System" },
55-
{ type: "ci", section: "Continuous Integration" },
56-
{ type: "chore", section: "Chores" },
57-
{ type: "revert", section: "Reverts" },
58-
{ type: "test", hidden: true },
59-
{ type: "style", hidden: true },
60-
],
60+
types: TYPES,
6161
},
6262
},
6363
},
6464
};
65+
66+
export default config;

‎oxlint.config.mts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ import base from "magic-oxlint-config/base";
99
// with nothing local to drift from the preset.
1010
export default extendConfig(base, {
1111
overrides: [
12+
{
13+
// tools/ holds the changelog preset and its control script. Printing to
14+
// the terminal is what the control is for, the CI job reads its output.
15+
files: ["tools/**"],
16+
rules: { "no-console": "off" },
17+
},
1218
{
1319
// `${version}` and friends in this file are release-it's own template
1420
// syntax, interpolated by release-it at release time. They are supposed
1521
// to reach it uninterpolated, so a real template literal would be the bug.
16-
files: [".release-it.cjs"],
22+
files: [".release-it.mjs"],
1723
rules: { "no-template-curly-in-string": "off" },
1824
},
1925
],

‎package.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
},
2525
"scripts": {
2626
"build": "tsc --project tsconfig.build.json",
27+
"changelog:check": "node tools/changelog-check.mjs",
2728
"clean": "expo-module clean",
2829
"lint": "oxlint --report-unused-disable-directives --deny-warnings",
2930
"lint:fix": "oxlint --report-unused-disable-directives --deny-warnings --fix",
@@ -40,6 +41,9 @@
4041
"@release-it/conventional-changelog": "^12.0.0",
4142
"@types/jest": "^29.5.14",
4243
"@types/node": "^24.13.3",
44+
"conventional-changelog": "^8.1.0",
45+
"conventional-changelog-conventionalcommits": "^10.2.1",
46+
"conventional-recommended-bump": "^12.1.0",
4347
"expo": ">=49.0.0",
4448
"expo-module-scripts": "^3.0.3",
4549
"jest": "^29",

‎pnpm-lock.yaml‎

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)