Repository navigation
293 lines (261 loc) · 9.9 KB
/
Copy pathpublish.yml
File metadata and controls
293 lines (261 loc) · 9.9 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
name: publish
on:
workflow_dispatch:
inputs:
tag:
description: Git tag to release, e.g. v0.5.0-rc.0
required: true
type: string
push:
tags:
- 'v*'
workflow_run:
workflows: ['ci']
types: [completed]
branches: [main]
permissions:
contents: read
id-token: write
jobs:
publish-stable:
name: publish stable packages
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
steps:
- name: Resolve tag
id: tag
env:
INPUT_TAG: ${{ inputs.tag }}
REF_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
TAG="${INPUT_TAG:-$REF_NAME}"
if [[ -z "$TAG" || ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
echo "Expected a vX.Y.Z or vX.Y.Z-prerelease tag, got '$TAG'" >&2
exit 1
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
VERSION="${TAG#v}"
if [[ "$VERSION" == *-* ]]; then
NPM_TAG="${VERSION#*-}"
NPM_TAG="${NPM_TAG%%.*}"
else
NPM_TAG="latest"
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "npm_tag=$NPM_TAG" >> "$GITHUB_OUTPUT"
- name: Checkout tag
uses: actions/checkout@v4
with:
ref: ${{ steps.tag.outputs.tag }}
fetch-depth: 0
submodules: recursive
- name: Validate tag and source versions
env:
TAG: ${{ steps.tag.outputs.tag }}
VERSION: ${{ steps.tag.outputs.version }}
run: |
set -euo pipefail
git fetch origin main --tags
if ! git merge-base --is-ancestor "$TAG" origin/main; then
echo "Tag $TAG is not an ancestor of origin/main" >&2
exit 1
fi
node <<'NODE'
const fs = require('fs');
const version = process.env.VERSION;
const root = JSON.parse(fs.readFileSync('package.json', 'utf8')).version;
const demo = JSON.parse(fs.readFileSync('demo/package.json', 'utf8')).version;
const flake = fs.readFileSync('flake.nix', 'utf8').match(/version = "([^"]+)";/)?.[1];
for (const [name, value] of Object.entries({ root, demo, flake })) {
if (value !== version) throw new Error(`${name} version ${value} does not match tag version ${version}`);
}
console.log(`Validated source versions for ${version}`);
NODE
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Setup Zig
uses: ./.github/actions/setup-zig
with:
version: 0.15.2
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Check formatting
run: bun run fmt
- name: Run linter
run: bun run lint
- name: Check types
run: bun run typecheck
- name: Run tests
run: bun test
- name: Build library
run: bun run build
- name: Check WASM size
run: |
SIZE=$(stat -c%s ghostty-vt.wasm)
echo "WASM size: $SIZE bytes"
if [ "$SIZE" -gt 524288 ]; then
echo "❌ Error: WASM exceeds 512 KiB limit"
exit 1
fi
- name: Setup Node.js for npm
uses: actions/setup-node@v4
with:
node-version: '24.22.1'
registry-url: 'https://registry.npmjs.org'
- name: Ensure current npm for trusted publishing
run: npm install -g npm@latest
- name: Publish ghostty-web
env:
VERSION: ${{ steps.tag.outputs.version }}
NPM_TAG: ${{ steps.tag.outputs.npm_tag }}
run: |
set -euo pipefail
PACKAGE_NAME=$(node -p "require('./package.json').name")
if npm view "${PACKAGE_NAME}@${VERSION}" version >/dev/null 2>&1; then
echo "${PACKAGE_NAME}@${VERSION} already exists; skipping publish"
npm dist-tag add "${PACKAGE_NAME}@${VERSION}" "${NPM_TAG}" || echo "Unable to repair ${NPM_TAG} dist-tag with current npm credentials; package already exists."
else
npm publish --tag "${NPM_TAG}" --provenance --access public
fi
- name: Pin and validate demo package
env:
VERSION: ${{ steps.tag.outputs.version }}
run: |
set -euo pipefail
node <<'NODE'
const fs = require('fs');
const version = process.env.VERSION;
const path = 'demo/package.json';
const pkg = JSON.parse(fs.readFileSync(path, 'utf8'));
pkg.version = version;
pkg.dependencies['ghostty-web'] = version;
fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + '\n');
console.log(`Pinned @ghostty-web/demo to ghostty-web ${version}`);
NODE
- name: Publish @ghostty-web/demo
working-directory: demo
env:
VERSION: ${{ steps.tag.outputs.version }}
NPM_TAG: ${{ steps.tag.outputs.npm_tag }}
run: |
set -euo pipefail
PACKAGE_NAME=$(node -p "require('./package.json').name")
if npm view "${PACKAGE_NAME}@${VERSION}" version >/dev/null 2>&1; then
echo "${PACKAGE_NAME}@${VERSION} already exists; skipping publish"
npm dist-tag add "${PACKAGE_NAME}@${VERSION}" "${NPM_TAG}" || echo "Unable to repair ${NPM_TAG} dist-tag with current npm credentials; package already exists."
else
npm publish --tag "${NPM_TAG}" --provenance --access public
fi
publish-next:
name: publish next packages
runs-on: ubuntu-latest
if: github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success'
steps:
- name: Checkout CI head
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}
fetch-depth: 0
submodules: recursive
- name: Skip release commits
id: release-commit
env:
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
set -euo pipefail
SUBJECT=$(git log -1 --format=%s "$HEAD_SHA")
echo "subject=$SUBJECT"
if [[ "$SUBJECT" =~ ^chore\(release\):\ ]]; then
echo "skip=true" >> "$GITHUB_OUTPUT"
echo "Skipping next publish for release commit"
else
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
- name: Setup Bun
if: steps.release-commit.outputs.skip != 'true'
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Setup Zig
if: steps.release-commit.outputs.skip != 'true'
uses: ./.github/actions/setup-zig
with:
version: 0.15.2
- name: Install dependencies
if: steps.release-commit.outputs.skip != 'true'
run: bun install --frozen-lockfile
- name: Build library
if: steps.release-commit.outputs.skip != 'true'
run: bun run build
- name: Setup Node.js for npm
if: steps.release-commit.outputs.skip != 'true'
uses: actions/setup-node@v4
with:
node-version: '24.22.1'
registry-url: 'https://registry.npmjs.org'
- name: Ensure current npm for trusted publishing
if: steps.release-commit.outputs.skip != 'true'
run: npm install -g npm@latest
- name: Compute next version
if: steps.release-commit.outputs.skip != 'true'
id: version
run: |
set -euo pipefail
LATEST_TAG=$(git describe --tags --abbrev=0)
BASE_VERSION="${LATEST_TAG#v}"
SHORT_SHA=$(git rev-parse --short HEAD)
COMMITS_SINCE_TAG=$(git rev-list --count HEAD ^"$LATEST_TAG")
NEXT_VERSION="${BASE_VERSION}-next.${COMMITS_SINCE_TAG}.g${SHORT_SHA}"
echo "version=$NEXT_VERSION" >> "$GITHUB_OUTPUT"
echo "Publishing next version $NEXT_VERSION"
- name: Prepare root package
if: steps.release-commit.outputs.skip != 'true'
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
node <<'NODE'
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
pkg.version = process.env.VERSION;
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
NODE
- name: Publish ghostty-web next
if: steps.release-commit.outputs.skip != 'true'
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
set -euo pipefail
PACKAGE_NAME=$(node -p "require('./package.json').name")
if npm view "${PACKAGE_NAME}@${VERSION}" version >/dev/null 2>&1; then
echo "${PACKAGE_NAME}@${VERSION} already exists; skipping"
else
npm publish --tag next --provenance --access public
fi
- name: Prepare demo package
if: steps.release-commit.outputs.skip != 'true'
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
node <<'NODE'
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('demo/package.json', 'utf8'));
pkg.version = process.env.VERSION;
pkg.dependencies['ghostty-web'] = process.env.VERSION;
fs.writeFileSync('demo/package.json', JSON.stringify(pkg, null, 2) + '\n');
NODE
- name: Publish @ghostty-web/demo next
if: steps.release-commit.outputs.skip != 'true'
working-directory: demo
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
set -euo pipefail
PACKAGE_NAME=$(node -p "require('./package.json').name")
if npm view "${PACKAGE_NAME}@${VERSION}" version >/dev/null 2>&1; then
echo "${PACKAGE_NAME}@${VERSION} already exists; skipping"
else
npm publish --tag next --provenance --access public
fi