Skip to content

Commit f019d29

Browse files
committed
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
1 parent d082e8c commit f019d29

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
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.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 }}

0 commit comments

Comments
 (0)