Skip to content

Commit 49d4277

Browse files
committed
Update GitHub actions
1 parent 2ae64e1 commit 49d4277

File tree

6 files changed

+168
-6
lines changed

6 files changed

+168
-6
lines changed

Diff for: .github/workflows/prepare-release.yml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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: [18]
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+
35+
- name: Use cached node_modules
36+
id: cache
37+
uses: actions/cache@v3
38+
with:
39+
path: node_modules
40+
key: nodeModules-${{ hashFiles('./package-lock.json') }}-${{ matrix.node-version }}
41+
42+
- name: Install dependencies
43+
if: steps.cache.outputs.cache-hit != 'true'
44+
run: npm install
45+
env:
46+
CI: true
47+
48+
- name: Test
49+
run: npm test
50+
env:
51+
CI: true
52+
53+
- name: Resolve version
54+
id: vars
55+
run: |
56+
echo "TAG_NAME=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
57+
58+
- name: Get release notes
59+
run: |
60+
RELEASE_NOTES=$(npm run release-notes --silent)
61+
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
62+
echo "$RELEASE_NOTES" >> $GITHUB_ENV
63+
echo "EOF" >> $GITHUB_ENV
64+
65+
- name: Release
66+
uses: softprops/action-gh-release@v1
67+
with:
68+
draft: true
69+
tag_name: ${{ env.TAG_NAME }}
70+
body: ${{ env.RELEASE_NOTES }}

Diff for: .github/workflows/release-insiders.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ jobs:
2727

2828
- name: Use cached node_modules
2929
id: cache
30-
uses: actions/cache@v2
30+
uses: actions/cache@v3
3131
with:
3232
path: node_modules
33-
key: nodeModules-${{ hashFiles('**/package-lock.json') }}-${{ matrix.node-version }}
34-
restore-keys: |
35-
nodeModules-
33+
key: nodeModules-${{ hashFiles('./package-lock.json') }}-${{ matrix.node-version }}
3634

3735
- name: Install dependencies
3836
if: steps.cache.outputs.cache-hit != 'true'
@@ -49,7 +47,7 @@ jobs:
4947
id: vars
5048
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
5149

52-
- name: "Version based on commit: 0.0.0-insiders.${{ steps.vars.outputs.sha_short }}"
50+
- name: 'Version based on commit: 0.0.0-insiders.${{ steps.vars.outputs.sha_short }}'
5351
run: npm version 0.0.0-insiders.${{ steps.vars.outputs.sha_short }} --force --no-git-tag-version
5452

5553
- name: Publish

Diff for: .github/workflows/release.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: read
9+
id-token: write
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
node-version: [18]
18+
19+
steps:
20+
- uses: actions/checkout@v3
21+
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v3
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
registry-url: 'https://registry.npmjs.org'
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+
35+
- name: Install dependencies
36+
if: steps.cache.outputs.cache-hit != 'true'
37+
run: npm install
38+
env:
39+
CI: true
40+
41+
- name: Test
42+
run: npm test
43+
env:
44+
CI: true
45+
46+
- name: Calculate environment variables
47+
run: |
48+
echo "RELEASE_CHANNEL=$(npm run release-channel --silent)" >> $GITHUB_ENV
49+
50+
- name: Publish
51+
run: npm publish --provenance --tag ${{ env.RELEASE_CHANNEL }}
52+
env:
53+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

Diff for: package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
"dev": "next dev demo",
2626
"build": "next build demo",
2727
"export": "next export demo",
28-
"start": "next start demo"
28+
"start": "next start demo",
29+
"release-channel": "node ./scripts/release-channel.js",
30+
"release-notes": "node ./scripts/release-notes.js"
2931
},
3032
"peerDependencies": {
3133
"tailwindcss": ">=3.0.0 || insiders"

Diff for: scripts/release-channel.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Given a version, figure out what the release channel is so that we can publish to the correct
2+
// channel on npm.
3+
//
4+
// E.g.:
5+
//
6+
// 1.2.3 -> latest (default)
7+
// 0.0.0-insiders.ffaa88 -> insiders
8+
// 4.1.0-alpha.4 -> alpha
9+
10+
let version =
11+
process.argv[2] || process.env.npm_package_version || require('../package.json').version
12+
13+
let match = /\d+\.\d+\.\d+-(.*)\.\d+/g.exec(version)
14+
if (match) {
15+
console.log(match[1])
16+
} else {
17+
console.log('latest')
18+
}

Diff for: scripts/release-notes.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Given a version, figure out what the release notes are so that we can use this to pre-fill the
2+
// relase notes on a GitHub release for the current version.
3+
4+
let path = require('path')
5+
let fs = require('fs')
6+
7+
let version =
8+
process.argv[2] || process.env.npm_package_version || require('../package.json').version
9+
10+
let changelog = fs.readFileSync(path.resolve(__dirname, '..', 'CHANGELOG.md'), 'utf8')
11+
let match = new RegExp(
12+
`## \\[${version}\\] - (.*)\\n\\n([\\s\\S]*?)\\n(?:(?:##\\s)|(?:\\[))`,
13+
'g'
14+
).exec(changelog)
15+
16+
if (match) {
17+
let [, date, notes] = match
18+
console.log(notes.trim())
19+
} else {
20+
console.log(`Placeholder release notes for version: v${version}`)
21+
}

0 commit comments

Comments
 (0)