Skip to content

Commit df2b76b

Browse files
committed
Add basic release automation
This release flow aims for the following features: - npm version && npm publish works locally - Action dispatch runs the same scripts as the local workflow - Automatic build and changelog generation - Github release support
1 parent c354162 commit df2b76b

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

.github/workflows/release.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: npm bump
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
newversion:
7+
description: "npm version {major,minor,patch}"
8+
required: true
9+
10+
env:
11+
node_version: "19"
12+
FORCE_COLOR: 1
13+
14+
concurrency: # prevent concurrent releases
15+
group: npm-bump
16+
cancel-in-progress: true
17+
18+
jobs:
19+
version_and_release:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v2
23+
with:
24+
# fetch full history so things like auto-changelog work properly
25+
fetch-depth: 0
26+
- name: Use Node.js ${{ env.node_version }}
27+
uses: actions/setup-node@v2
28+
with:
29+
node-version: ${{ env.node_version }}
30+
# setting a registry enables the NODE_AUTH_TOKEN env variable where we can set an npm token. REQUIRED
31+
registry-url: "https://registry.npmjs.org"
32+
- run: npm i
33+
- run: npm test
34+
- name: npm version && npm publish
35+
uses: bcomnes/npm-bump@v2
36+
with:
37+
git_email: [email protected]
38+
git_username: ${{ github.actor }}
39+
newversion: ${{ github.event.inputs.newversion }}
40+
github_token: ${{ secrets.GITHUB_TOKEN }} # built in actions token. Passed tp gh-release if in use.
41+
npm_token: ${{ secrets.NPM_ORG_TOKEN }} # user set secret token generated at npm
42+
publish_cmd: npm publish --provenance

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@
3838
"clean:declarations": "rm -rf $(find . -maxdepth 2 -type f -name '*.d.ts*')",
3939
"clean": "run-p clean:*",
4040
"prepare": "husky install",
41-
"prepublishOnly": "run-s build",
41+
"prepublishOnly": "git push --follow-tags && gh-release -y && run-s build",
4242
"test:mocha": "c8 --reporter=lcov --reporter text mocha 'test/**/*.spec.js'",
4343
"test-ci": "run-s test:*",
44-
"test": "run-s check test:*"
44+
"test": "run-s check test:*",
45+
"version": "run-s prepare version:*",
46+
"version:changelog": "auto-changelog -p --template keepachangelog auto-changelog --breaking-pattern 'BREAKING CHANGE:'",
47+
"version:git": "git add CHANGELOG.md"
4548
},
4649
"devDependencies": {
4750
"@socketsecurity/eslint-config": "^2.0.0",
@@ -72,7 +75,9 @@
7275
"mocha": "^10.0.0",
7376
"npm-run-all2": "^6.0.2",
7477
"type-coverage": "^2.24.1",
75-
"typescript": "~4.9.5"
78+
"typescript": "~4.9.5",
79+
"auto-changelog": "^2.4.0",
80+
"gh-release": "^7.0.2"
7681
},
7782
"dependencies": {
7883
"ajv": "^8.12.0",

0 commit comments

Comments
 (0)