Skip to content

Commit ebf99ee

Browse files
committed
Implement proper two-script release workflow
- Create scripts/update-changelog.js for changelog management - Simplify scripts/release-tag.js to only handle tag creation - Update package.json with separate npm scripts for each step - Fix version script to commit both VERSION and CHANGELOG.md changes - Inspired by Ruby amqp-client release workflow Workflow now: 1. preversion: test:local (skip TLS tests) 2. version: update VERSION + format + update changelog + commit both 3. postversion: create tag + push commits and tags Manual: npm run update-changelog, npm run create-tag
1 parent 6adf219 commit ebf99ee

3 files changed

Lines changed: 55 additions & 44 deletions

File tree

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@
3636
"test": "vitest run --coverage",
3737
"test:local": "vitest run --coverage test/test.ts",
3838
"test-browser": "vitest --config ./vitest.config.browser.ts",
39+
"update-changelog": "node scripts/update-changelog.js",
3940
"create-tag": "node scripts/release-tag.js",
4041
"prebuild": "rm -rf dist lib types",
4142
"build": "tsc && tsc --module commonjs --outDir lib/cjs && tsc --emitDeclarationOnly --removeComments false && rollup -c",
4243
"postbuild": "echo '{\"type\": \"commonjs\"}' > lib/cjs/package.json",
4344
"prepare": "npm run build",
4445
"preversion": "npm run test:local",
45-
"version": "sed -i'' \"s/VERSION = .*/VERSION = \\\"$npm_package_version\\\"/\" src/amqp-base-client.ts && npm run format && node scripts/release-tag.js --update-changelog && git add src/amqp-base-client.ts CHANGELOG.md",
46-
"postversion": "git push && git push --tags",
46+
"version": "sed -i'' \"s/VERSION = .*/VERSION = \\\"$npm_package_version\\\"/\" src/amqp-base-client.ts && npm run format && npm run update-changelog && git add src/amqp-base-client.ts CHANGELOG.md",
47+
"postversion": "npm run create-tag && git push && git push --tags",
4748
"release": "npm version patch",
4849
"release:minor": "npm version minor",
4950
"release:major": "npm version major"

scripts/release-tag.js

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,18 @@ import fs from "fs"
44
import { execSync } from "child_process"
55

66
function main() {
7-
// Check if we should only update changelog (no tag creation)
8-
const updateChangelogOnly = process.argv.includes("--update-changelog")
9-
107
// Read package.json to get current version
118
const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"))
129
const version = pkg.version
1310

14-
if (updateChangelogOnly) {
15-
console.log(`Updating changelog for version ${version}...`)
16-
} else {
17-
console.log(`Creating tag for version ${version}...`)
18-
}
11+
console.log(`Creating tag for version ${version}...`)
1912

2013
// Read changelog
21-
let changelog = fs.readFileSync("CHANGELOG.md", "utf8")
22-
23-
// Update [Unreleased] section to current version if it exists
24-
const unreleasedHeader = "## [Unreleased]"
25-
const versionHeader = `## [${version}]`
26-
const today = new Date().toISOString().split("T")[0] // YYYY-MM-DD format
27-
const newVersionHeader = `## [${version}] - ${today}`
28-
29-
// Check if version already exists in changelog
30-
if (changelog.includes(newVersionHeader) || changelog.includes(versionHeader)) {
31-
console.log(`Version ${version} already exists in changelog. Skipping update.`)
32-
} else if (changelog.includes(unreleasedHeader)) {
33-
console.log("Updating [Unreleased] section to current version...")
34-
changelog = changelog.replace(unreleasedHeader, newVersionHeader)
35-
36-
// Add a new [Unreleased] section at the top for future changes
37-
const changelogLines = changelog.split("\n")
38-
const headerIndex = changelogLines.findIndex((line) => line.startsWith("## ["))
39-
if (headerIndex !== -1) {
40-
changelogLines.splice(headerIndex, 0, "## [Unreleased]", "")
41-
changelog = changelogLines.join("\n")
42-
}
43-
44-
// Write updated changelog back to file
45-
fs.writeFileSync("CHANGELOG.md", changelog, "utf8")
46-
console.log("✅ Updated CHANGELOG.md")
47-
}
48-
49-
// If only updating changelog, exit here (don't create tag)
50-
if (updateChangelogOnly) {
51-
return
52-
}
14+
const changelog = fs.readFileSync("CHANGELOG.md", "utf8")
5315

5416
// Find the section for this version
55-
const startIdx =
56-
changelog.indexOf(newVersionHeader) !== -1 ? changelog.indexOf(newVersionHeader) : changelog.indexOf(versionHeader)
17+
const versionHeader = `## [${version}]`
18+
const startIdx = changelog.indexOf(versionHeader)
5719

5820
if (startIdx === -1) {
5921
console.error(`Error: Version ${version} not found in CHANGELOG.md`)

scripts/update-changelog.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env node
2+
3+
import fs from "fs"
4+
5+
function main() {
6+
// Read package.json to get current version
7+
const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"))
8+
const version = pkg.version
9+
10+
console.log(`Updating changelog for version ${version}...`)
11+
12+
// Read changelog
13+
let changelog = fs.readFileSync("CHANGELOG.md", "utf8")
14+
15+
// Check if version already exists in changelog
16+
const today = new Date().toISOString().split("T")[0] // YYYY-MM-DD format
17+
const versionHeader = `## [${version}]`
18+
const newVersionHeader = `## [${version}] - ${today}`
19+
20+
if (changelog.includes(newVersionHeader) || changelog.includes(versionHeader)) {
21+
console.log(`Version ${version} already exists in changelog. Skipping update.`)
22+
return
23+
}
24+
25+
// Update [Unreleased] section to current version if it exists
26+
const unreleasedHeader = "## [Unreleased]"
27+
28+
if (changelog.includes(unreleasedHeader)) {
29+
console.log("Updating [Unreleased] section to current version...")
30+
changelog = changelog.replace(unreleasedHeader, newVersionHeader)
31+
32+
// Add a new [Unreleased] section at the top for future changes
33+
const changelogLines = changelog.split("\n")
34+
const headerIndex = changelogLines.findIndex((line) => line.startsWith("## ["))
35+
if (headerIndex !== -1) {
36+
changelogLines.splice(headerIndex, 0, "## [Unreleased]", "")
37+
changelog = changelogLines.join("\n")
38+
}
39+
40+
// Write updated changelog back to file
41+
fs.writeFileSync("CHANGELOG.md", changelog, "utf8")
42+
console.log("✅ Updated CHANGELOG.md")
43+
} else {
44+
console.log("No [Unreleased] section found in changelog.")
45+
}
46+
}
47+
48+
main()

0 commit comments

Comments
 (0)