Skip to content

Commit ef78680

Browse files
authored
fix: add pre version support to release generation (#26)
1 parent f15a5ea commit ef78680

File tree

5 files changed

+159
-24
lines changed

5 files changed

+159
-24
lines changed

.github/workflows/github-release-and-npm-package-publish.yml

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ jobs:
1313
permissions:
1414
contents: read
1515
outputs:
16-
run_suffix_present: ${{ steps.check_run_suffix_present.outputs.run_suffix_present }}
17-
run_suffix_force_version: ${{ steps.check_run_suffix_present.outputs.run_suffix_force_version }}
16+
is_suffix_present: ${{ steps.check_create_release_suffix.outputs.is_suffix_present }}
17+
is_version_bump: ${{ steps.check_create_release_suffix.outputs.is_version_bump }}
18+
force_version: ${{ steps.check_create_release_suffix.outputs.force_version }}
1819
steps:
1920
- name: Checkout the Codebase
2021
uses: actions/checkout@v4
2122
with:
2223
ref: main # branch to checkout
2324
fetch-depth: 0
2425

25-
- name: Check commit message suffix for `[create-release]`
26-
id: check_run_suffix_present
26+
- name: Check commit message suffix for `[create-release-TYPE]`
27+
id: check_create_release_suffix
2728
uses: actions/github-script@v7
2829
with:
2930
script: |
@@ -32,24 +33,45 @@ jobs:
3233
const lastCommitMessage = context.payload.head_commit.message;
3334
const lastCommitMessageFirstLine = lastCommitMessage.split('\n')[0];
3435
35-
let run_suffix_present = "false";
36-
let run_suffix_force_version = "";
36+
let is_suffix_present = "false";
37+
let is_version_bump = "false";
38+
let force_version = "";
39+
40+
const allowedTypes = [
41+
"auto",
42+
"major",
43+
"minor",
44+
"patch",
45+
"premajor",
46+
"preminor",
47+
"prepatch",
48+
"prerelease",
49+
];
3750
3851
const regex = /\[create-release(?:-([a-z]+))?\]/;
3952
const match = lastCommitMessageFirstLine.match(regex);
4053
4154
if (match) {
42-
run_suffix_present = "true";
55+
is_suffix_present = "true";
4356
if(match[1]){
44-
run_suffix_force_version = `--${match[1]}`
57+
if(!allowedTypes.includes(match[1])){
58+
throw new Error(`Invalid release TYPE: ${match[1]}`);
59+
}
60+
is_version_bump = "true";
61+
if(match[1] !== "auto"){
62+
force_version = `--${match[1]}`
63+
}
4564
}
4665
}
4766
48-
console.dir(`Set output: run_suffix_present=${run_suffix_present}`);
49-
core.setOutput("run_suffix_present", run_suffix_present);
67+
console.dir(`Set output: is_suffix_present=${is_suffix_present}`);
68+
core.setOutput("is_suffix_present", is_suffix_present);
5069
51-
console.dir(`Set output: run_suffix_force_version=${run_suffix_force_version}`);
52-
core.setOutput("run_suffix_force_version", run_suffix_force_version);
70+
console.dir(`Set output: is_version_bump=${is_version_bump}`);
71+
core.setOutput("is_version_bump", is_version_bump);
72+
73+
console.dir(`Set output: force_version=${force_version}`);
74+
core.setOutput("force_version", force_version);
5375
5476
dependence-lint:
5577
name: Depend on Lint
@@ -59,7 +81,7 @@ jobs:
5981
needs:
6082
- check_conditions
6183
- dependence-lint
62-
if: needs.check_conditions.outputs.run_suffix_present == 'true'
84+
if: needs.check_conditions.outputs.is_suffix_present == 'true'
6385
name: Create GitHub Release & NPM Publish
6486
runs-on: ubuntu-latest
6587
permissions:
@@ -86,20 +108,30 @@ jobs:
86108
git config --global user.name "github-actions[bot]"
87109
git config --global user.email "no-reply@todde.tv"
88110
111+
- name: Install dependencies
112+
run: pnpm install --frozen-lockfile
113+
89114
# - name: Get old `package.json` version
90115
# id: get_package_version_old
91116
# run: echo version=$(node -p "require('./package.json').version") >> $GITHUB_OUTPUT
92117

93-
- name: Bump `package.json` version & generate changelog both from conventional commits
118+
- name: Bump `package.json` version depending on given TYPE from commit message
119+
if: needs.check_conditions.outputs.is_version_bump == 'true'
94120
# -from "v${{ steps.get_package_version_old.outputs.version }}"
95-
run: pnpx changelogen@0.5.7 --output CHANGELOG.md --bump --no-commit --no-tag ${{ needs.check_conditions.outputs.run_suffix_force_version }}
121+
run: pnpm changelogen --bump ${{ needs.check_conditions.outputs.force_version }} --no-commit --no-tag
96122
env:
97123
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
98124

99125
- name: Get new `package.json` version
100126
id: get_package_version_new
101127
run: echo version=$(node -p "require('./package.json').version") >> $GITHUB_OUTPUT
102128

129+
- name: Generate changelog from conventional commits
130+
# -from "v${{ steps.get_package_version_old.outputs.version }}"
131+
run: pnpm changelogen --output CHANGELOG.md -r "${{ steps.get_package_version_new.outputs.version }}" --no-commit --no-tag
132+
env:
133+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
134+
103135
- name: Git add, commit & push changes made to `package.json` & `CHANGELOG.md` to `main`
104136
run: |
105137
git add .
@@ -112,14 +144,13 @@ jobs:
112144
git push origin --tags
113145
114146
- name: Sync tags with GitHub releases & create the new release
115-
# run: pnpx changelogen@0.5.7 gh release "v${{ steps.get_package_version_new.outputs.version }}"
116-
# run: pnpx changelogen@0.5.7 gh release
117-
run: pnpx changelogen@0.5.7 gh release all
147+
# run: pnpm changelogen gh release all
148+
run: pnpm changelogen gh release "v${{ steps.get_package_version_new.outputs.version }}"
118149
env:
119150
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
120151

121-
- name: Install dependencies
122-
run: pnpm install --frozen-lockfile
152+
# - name: Install dependencies
153+
# run: pnpm install --frozen-lockfile
123154

124155
- name: Build the project
125156
run: pnpm run build

README.dev.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ the GitHub workflow (CI action) that:
5858

5959
- uses `pnpx changelogen` to analyze the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) from
6060
the last version to the current commit for:
61-
- bumping the version in `package.json` via:
62-
- automatically when no `TYPE` is given
63-
- manually with a given `TYPE` where the following is possible:
61+
- If no `TYPE` is present: Use the version from the `package.json` as target new version.<br>
62+
So if the version already was changed via development this can be used to not bump another version on top.
63+
- If no `TYPE` present: Bumping the version in `package.json` via:
64+
- automatically when `TYPE` is `auto` depending on the detected semver changes.
65+
- manually with the following `TYPE`:
6466
- `major`: Bump as a semver-major version
6567
- `minor`: Bump as a semver-minor version
6668
- `patch`: Bump as a semver-patch version

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
"@antfu/eslint-config": "~3.16.0",
167167
"@types/node": "~22.10.7",
168168
"@types/three": "~0.172.0",
169+
"changelogen": "0.5.7",
169170
"eslint": "~9.18.0",
170171
"eslint-plugin-format": "~1.0.1",
171172
"eslint-plugin-perfectionist": "~4.7.0",
@@ -180,7 +181,8 @@
180181
},
181182
"pnpm": {
182183
"patchedDependencies": {
183-
"three-stdlib": "patches/three-stdlib.patch"
184+
"three-stdlib": "patches/three-stdlib.patch",
185+
"changelogen": "patches/changelogen.patch"
184186
}
185187
}
186188
}

patches/changelogen.patch

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
diff --git a/dist/shared/changelogen.a79f5d5c.mjs b/dist/shared/changelogen.a79f5d5c.mjs
2+
index 901f6e360af4b6ea62758ebe28f0758d306a41f0..e8b5f4c3f9a94c7cd80344097950daea6fa499f8 100644
3+
--- a/dist/shared/changelogen.a79f5d5c.mjs
4+
+++ b/dist/shared/changelogen.a79f5d5c.mjs
5+
@@ -395,8 +395,8 @@ function groupBy(items, key) {
6+
}
7+
return groups;
8+
}
9+
-const CHANGELOG_RELEASE_HEAD_RE = /^#{2,}\s+.*(v?(\d+\.\d+\.\d+)).*$/gm;
10+
-const VERSION_RE = /^v?(\d+\.\d+\.\d+)$/;
11+
+const CHANGELOG_RELEASE_HEAD_RE = /^#{2,}\s+.*(v?(\d+\.\d+\.\d+(-(rc\.)?\d+)?)).*$/gm;
12+
+const VERSION_RE = /^v?(\d+\.\d+\.\d+(-(rc\.)?\d+)?)$/;
13+
14+
const defaultOutput = "CHANGELOG.md";
15+
const getDefaultConfig = () => ({
16+
diff --git a/dist/shared/changelogen.c9085e7f.cjs b/dist/shared/changelogen.c9085e7f.cjs
17+
index 41e5865eb367763db7bc45aa1003bc0e7af4035b..e6dd6b133c4320c535541333d49540787db64c6c 100644
18+
--- a/dist/shared/changelogen.c9085e7f.cjs
19+
+++ b/dist/shared/changelogen.c9085e7f.cjs
20+
@@ -397,8 +397,8 @@ function groupBy(items, key) {
21+
}
22+
return groups;
23+
}
24+
-const CHANGELOG_RELEASE_HEAD_RE = /^#{2,}\s+.*(v?(\d+\.\d+\.\d+)).*$/gm;
25+
-const VERSION_RE = /^v?(\d+\.\d+\.\d+)$/;
26+
+const CHANGELOG_RELEASE_HEAD_RE = /^#{2,}\s+.*(v?(\d+\.\d+\.\d+(-(rc\.)?\d+)?)).*$/gm;
27+
+const VERSION_RE = /^v?(\d+\.\d+\.\d+(-(rc\.)?\d+)?)$/;
28+
29+
const defaultOutput = "CHANGELOG.md";
30+
const getDefaultConfig = () => ({

pnpm-lock.yaml

Lines changed: 70 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)