Skip to content

Commit addaf45

Browse files
authored
Prepare for release (#1)
* add script to get the release notes Usage: ```sh npm run release-notes # Gets notes for current version npm run release-notes 1.2.3 # Gets notes for explicit version ``` * add actions for preparing a release, and releasing a release The `prepare release` will be executed when a tag is pushed. It does the following things: 1. Checks out the repo 2. Installs the dependencies 3. Runs the tests 4. Creates a draft release on GitHub with the release notes pre-filled based on the `CHANGELOG.md` file of the current version. Once you publish the actual release on GitHub, the `release` action will run. This will execute the following steps: 1. Checks out the repo 2. Installs the dependencies 3. Runs the tests as a sanity check 4. Published the current version to npm * use `SHA_SHORT` for env variables
1 parent 96fefc6 commit addaf45

File tree

5 files changed

+150
-4
lines changed

5 files changed

+150
-4
lines changed

.github/workflows/prepare-release.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Prepare Release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- 'v*'
8+
9+
env:
10+
CI: true
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
prepare:
17+
permissions:
18+
contents: write # for softprops/action-gh-release to create GitHub release
19+
20+
runs-on: ubuntu-latest
21+
22+
strategy:
23+
matrix:
24+
node-version: [14]
25+
26+
steps:
27+
- uses: actions/checkout@v3
28+
29+
- name: Use Node.js ${{ matrix.node-version }}
30+
uses: actions/setup-node@v3
31+
with:
32+
node-version: ${{ matrix.node-version }}
33+
registry-url: 'https://registry.npmjs.org'
34+
# cache: 'npm'
35+
#
36+
# - name: Use cached node_modules
37+
# id: cache
38+
# uses: actions/cache@v3
39+
# with:
40+
# path: node_modules
41+
# key: nodeModules-${{ hashFiles('**/package-lock.json') }}-${{ matrix.node-version }}
42+
# restore-keys: |
43+
# nodeModules-
44+
45+
- name: Resolve version
46+
id: vars
47+
run: |
48+
echo "TAG_NAME=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
49+
50+
- name: Get release notes
51+
run: |
52+
RELEASE_NOTES=$(npm run release-notes --silent)
53+
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
54+
echo "$RELEASE_NOTES" >> $GITHUB_ENV
55+
echo "EOF" >> $GITHUB_ENV
56+
57+
- name: Install dependencies
58+
# if: steps.cache.outputs.cache-hit != 'true'
59+
run: npm install
60+
env:
61+
CI: true
62+
63+
- name: Test
64+
run: npm test
65+
env:
66+
CI: true
67+
68+
- name: Release
69+
uses: softprops/action-gh-release@v1
70+
with:
71+
draft: true
72+
tag_name: ${{ env.TAG_NAME }}
73+
body: ${{ env.RELEASE_NOTES }}

.github/workflows/release-insiders.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ jobs:
3939
- name: Resolve version
4040
id: vars
4141
run: |
42-
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
42+
echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
4343
44-
- name: "Version based on commit: 0.0.0-insiders.${{ env.sha_short }}"
45-
run: npm version 0.0.0-insiders.${{ env.sha_short }} --force --no-git-tag-version
44+
- name: "Version based on commit: 0.0.0-insiders.${{ env.SHA_SHORT }}"
45+
run: npm version 0.0.0-insiders.${{ env.SHA_SHORT }} --force --no-git-tag-version
4646

4747
- name: Publish
4848
run: npm publish --tag insiders

.github/workflows/release.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
node-version: [14]
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
21+
- name: Use Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
registry-url: 'https://registry.npmjs.org'
26+
# cache: 'npm'
27+
#
28+
# - name: Use cached node_modules
29+
# id: cache
30+
# uses: actions/cache@v3
31+
# with:
32+
# path: node_modules
33+
# key: nodeModules-${{ hashFiles('**/package-lock.json') }}-${{ matrix.node-version }}
34+
# restore-keys: |
35+
# nodeModules-
36+
37+
- name: Install dependencies
38+
# if: steps.cache.outputs.cache-hit != 'true'
39+
run: npm install
40+
env:
41+
CI: true
42+
43+
- name: Test
44+
run: npm test
45+
env:
46+
CI: true
47+
48+
- name: Calculate environment variables
49+
run: |
50+
echo "TAG_NAME=$(npm run calculate-tag-name --silent)" >> $GITHUB_ENV
51+
52+
- name: Publish
53+
run: npm publish --tag ${{ env.TAG_NAME }}
54+
env:
55+
CI: true
56+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"build": "npm run swcify",
1515
"dev": "npm run swcify -- --watch",
1616
"postbuild": "tsc --emitDeclarationOnly",
17-
"prepublishOnly": "npm run build"
17+
"prepublishOnly": "npm run build",
18+
"release-notes": "node ./scripts/release-notes.js"
1819
},
1920
"prettier": {
2021
"printWidth": 100,

scripts/release-notes.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
let path = require('path')
2+
let fs = require('fs')
3+
4+
let version = process.argv[2] || require('../package.json').version
5+
let changelog = fs.readFileSync(path.resolve(__dirname, '..', 'CHANGELOG.md'), 'utf8')
6+
let match = new RegExp(
7+
`## \\[${version}\\] - (.*)\\n\\n([\\s\\S]*?)\\n(?:(?:##\\s)|(?:\\[))`,
8+
'g'
9+
).exec(changelog)
10+
11+
if (match) {
12+
let [, date, notes] = match
13+
console.log(notes.trim())
14+
} else {
15+
console.log(`Placeholder release notes for version: v${version}`)
16+
}

0 commit comments

Comments
 (0)