Repository navigation
81 lines (79 loc) · 2.95 KB
/
Copy pathrelease.yml
File metadata and controls
81 lines (79 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
name: Release
# Publishes to npm only from a version tag, so work in progress never ships.
# Tag a release with: pnpm version:tag 0.1.0-alpha.1 (see docs/RELEASING.md)
on:
push:
tags: ['v*']
workflow_dispatch: {}
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
registry-url: https://registry.npmjs.org
- run: pnpm install --frozen-lockfile
- run: pnpm build
- run: pnpm typecheck
- run: pnpm test
- name: Check the tag matches the package version
if: github.ref_type == 'tag'
shell: bash
run: |
set -e
TAG="${GITHUB_REF_NAME#v}"
PKG=$(node -p "require('./packages/blockwright/package.json').version")
if [ "$TAG" != "$PKG" ]; then echo "Tag $TAG does not match package version $PKG"; exit 1; fi
- name: Check the npm token works
shell: bash
run: |
set -e
if [ -z "${NODE_AUTH_TOKEN}" ]; then echo "NPM_TOKEN secret is missing"; exit 1; fi
npm whoami --registry=https://registry.npmjs.org/
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish to npm
id: publish
shell: bash
run: |
set -o pipefail
pnpm -r --filter "./packages/*" publish --access public --no-git-checks 2>&1 | tee publish.log
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Save the publish log to the ci-logs branch
if: always()
uses: actions/github-script@v7
with:
script: |
const fs = require('fs')
const log = fs.existsSync('publish.log') ? fs.readFileSync('publish.log', 'utf8') : 'The publish step did not run.'
const content = Buffer.from(`# Release ${context.ref} (${context.runId})\n\n${log.slice(-60000)}`).toString('base64')
const branch = 'ci-logs'
const main = await github.rest.git.getRef({ ...context.repo, ref: 'heads/main' })
try {
await github.rest.git.getRef({ ...context.repo, ref: `heads/${branch}` })
} catch {
await github.rest.git.createRef({ ...context.repo, ref: `refs/heads/${branch}`, sha: main.data.object.sha })
}
let sha
try {
const existing = await github.rest.repos.getContent({ ...context.repo, path: 'publish.log.md', ref: branch })
sha = existing.data.sha
} catch {
sha = undefined
}
await github.rest.repos.createOrUpdateFileContents({
...context.repo,
branch,
path: 'publish.log.md',
message: `ci: publish log for ${context.runId}`,
content,
sha,
})