-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (128 loc) · 4.06 KB
/
Copy pathpublish.yml
File metadata and controls
152 lines (128 loc) · 4.06 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Release
on:
push:
branches:
- main
workflow_dispatch:
concurrency:
group: publish
cancel-in-progress: false
jobs:
prepare_release_pr:
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 22.12.0
package-manager-cache: false
- name: Install dependencies
run: npm ci
- name: Run checks
run: npm run check
- name: Create or update release PR
uses: changesets/action@v1
with:
commit: "chore: version packages"
title: "chore: version packages"
version: npm run version-packages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
detect_publish:
runs-on: ubuntu-latest
timeout-minutes: 10
needs: prepare_release_pr
permissions:
contents: read
outputs:
should_publish: ${{ steps.detect.outputs.should_publish }}
local_version: ${{ steps.detect.outputs.local_version }}
registry_version: ${{ steps.detect.outputs.registry_version }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 22.12.0
package-manager-cache: false
- name: Detect pending npm publish
id: detect
shell: bash
run: |
node --input-type=module <<'EOF'
import { readFileSync, appendFileSync } from "node:fs";
const packageJson = JSON.parse(
readFileSync("packages/blr/package.json", "utf8"),
);
const packageName = packageJson.name;
const localVersion = packageJson.version;
let registryVersion = "";
try {
const response = await fetch(
`https://registry.npmjs.org/${encodeURIComponent(packageName)}/latest`,
);
if (response.ok) {
const payload = await response.json();
registryVersion = String(payload.version ?? "");
} else if (response.status !== 404) {
throw new Error(
`npm registry lookup failed with ${response.status} ${response.statusText}`,
);
}
} catch (error) {
console.error(
`[release] Failed to determine npm registry version: ${error instanceof Error ? error.message : String(error)}`,
);
process.exit(1);
}
const shouldPublish = localVersion !== registryVersion;
console.log(
`[release] local=${localVersion} registry=${registryVersion || "<missing>"} should_publish=${shouldPublish}`,
);
const outputPath = process.env.GITHUB_OUTPUT;
if (!outputPath) {
throw new Error("GITHUB_OUTPUT is not set.");
}
appendFileSync(outputPath, `local_version=${localVersion}\n`);
appendFileSync(outputPath, `registry_version=${registryVersion}\n`);
appendFileSync(outputPath, `should_publish=${shouldPublish}\n`);
EOF
publish_package:
runs-on: ubuntu-latest
timeout-minutes: 30
needs: detect_publish
if: needs.detect_publish.outputs.should_publish == 'true'
environment: release
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
package-manager-cache: false
registry-url: https://registry.npmjs.org
- name: Report publish toolchain
run: |
node --version
npm --version
- name: Install dependencies
run: npm ci
- name: Run checks
run: npm run check
- name: Publish package
run: npm run release