-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypescript-service-release.yaml
More file actions
284 lines (269 loc) · 11.6 KB
/
Copy pathtypescript-service-release.yaml
File metadata and controls
284 lines (269 loc) · 11.6 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
name: TypeScript Service Release
on:
workflow_call:
inputs:
service-name:
type: string
required: true
description: "The name of the service to release"
bun-version:
type: string
required: false
default: "latest"
description: "Bun version to use"
npm-tag:
type: string
required: false
default: "latest"
description: "NPM tag to publish with"
no-npm-publish:
type: boolean
required: false
default: false
description: "Do not publish to npm"
working-directory:
type: string
required: false
default: "."
description: "Directory containing package.json"
build-command:
type: string
required: false
default: "bun run build"
description: "Build command"
publish-command:
type: string
required: false
default: "npm publish"
description: "Command used to publish (e.g., 'npm publish', 'bunx clean-publish'). The --tag, --access, and --dry-run flags are appended automatically."
labels-to-check:
type: string
required: false
default: '["release", "prerelease"]'
description: "JSON array of PR labels to check"
prerelease:
type: boolean
required: false
default: false
description: "Force prerelease (overrides label)"
release:
type: boolean
required: false
default: false
description: "Force release - does both GitHub release and npm publish"
dry-run:
type: boolean
required: false
default: false
description: "Run in dry-run mode (no actual publishing)"
use-blacksmith:
type: boolean
required: false
default: false
description: "Opt in to Blacksmith Linux runners (blacksmith-4vcpu-ubuntu-2404). Requires the Blacksmith GitHub App installed on the caller org. Defaults to ubuntu-latest."
use-oidc:
type: boolean
required: false
default: false
description: "Opt in to npm OIDC Trusted Publishing. When true, the publish job inherits the caller's GITHUB_TOKEN so it can use 'id-token: write' (the caller must grant it) and a trusted publisher must be configured on npmjs.com. Falls back to NPM_TOKEN if OIDC is unavailable. When false (default), publishing uses NPM_TOKEN and the job keeps least-privilege 'contents: read'."
notify-on-release:
type: boolean
required: false
default: true
description: "Fire the post-release notify job on real releases (major | minor | patch). Callers not on the in-job allow-list skip cleanly. Set to false to opt a specific release out."
secrets:
OPENAI_API_KEY:
required: true
description: "OpenAI API key for version and notes"
NPM_TOKEN:
required: false
description: "NPM token (required for npm publish)"
APP_ID:
required: false
description: "GitHub App ID for pushing to protected branches and triggering downstream workflows"
APP_PRIVATE_KEY:
required: false
description: "GitHub App private key for pushing to protected branches and triggering downstream workflows"
TS_OAUTH_CLIENT_ID:
required: false
description: "Tailscale OAuth client ID — used by the notify job to join the tailnet ephemerally"
TS_OAUTH_SECRET:
required: false
description: "Tailscale OAuth client secret matching TS_OAUTH_CLIENT_ID"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
check-labels:
runs-on: ${{ inputs.use-blacksmith && 'blacksmith-4vcpu-ubuntu-2404' || 'ubuntu-latest' }}
permissions:
pull-requests: read
contents: read
outputs:
labels: ${{ steps.check.outputs.labels }}
steps:
- name: Check PR Labels
id: check
uses: photon-hq/buildspace/.github/blocks/check-pr-label@main
with:
labels: ${{ inputs.labels-to-check }}
release-info:
needs: check-labels
if: fromJSON(needs.check-labels.outputs.labels).release || inputs.release
runs-on: ${{ inputs.use-blacksmith && 'blacksmith-4vcpu-ubuntu-2404' || 'ubuntu-latest' }}
permissions:
contents: read
outputs:
version: ${{ steps.generate.outputs.version }}
release_notes: ${{ steps.generate.outputs.release_notes }}
release_type: ${{ steps.generate.outputs.release_type }}
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Generate Release Info
id: generate
uses: photon-hq/buildspace/.github/blocks/generate-release-info@main
with:
service-name: ${{ inputs.service-name }}
prerelease: ${{ inputs.prerelease || fromJSON(needs.check-labels.outputs.labels).prerelease }}
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
bump-version:
needs: [check-labels, release-info]
if: fromJSON(needs.check-labels.outputs.labels).release || inputs.release
runs-on: ${{ inputs.use-blacksmith && 'blacksmith-4vcpu-ubuntu-2404' || 'ubuntu-latest' }}
permissions:
contents: write
steps:
- uses: actions/checkout@v5
with:
ref: ${{ github.ref }}
persist-credentials: false
- name: Bump Version
uses: photon-hq/buildspace/.github/blocks/bump-npm-version@main
with:
version: ${{ needs.release-info.outputs.version }}
working-directory: ${{ inputs.working-directory }}
github-token: ${{ github.token }}
app-id: ${{ secrets.APP_ID }}
app-private-key: ${{ secrets.APP_PRIVATE_KEY }}
github-release:
needs: [check-labels, release-info, bump-version]
if: fromJSON(needs.check-labels.outputs.labels).release || inputs.release
runs-on: ${{ inputs.use-blacksmith && 'blacksmith-4vcpu-ubuntu-2404' || 'ubuntu-latest' }}
permissions:
contents: write
steps:
- name: Create GitHub Release
uses: photon-hq/buildspace/.github/blocks/create-github-release@main
with:
version: ${{ needs.release-info.outputs.version }}
title: "${{ inputs.service-name }} v${{ needs.release-info.outputs.version }}"
notes: ${{ needs.release-info.outputs.release_notes }}
prerelease: ${{ inputs.prerelease || fromJSON(needs.check-labels.outputs.labels).prerelease }}
app-id: ${{ secrets.APP_ID }}
app-private-key: ${{ secrets.APP_PRIVATE_KEY }}
# Default publish path (use-oidc: false). Keeps least-privilege
# `contents: read` exactly as before and publishes via NPM_TOKEN. Existing
# callers are unaffected — no permission changes required on their side.
npm-publish:
needs: [check-labels, release-info, bump-version]
if: (fromJSON(needs.check-labels.outputs.labels).release || inputs.release) && inputs.no-npm-publish != true && inputs.use-oidc != true
runs-on: ${{ inputs.use-blacksmith && 'blacksmith-4vcpu-ubuntu-2404' || 'ubuntu-latest' }}
permissions:
contents: read
steps:
- uses: actions/checkout@v5
with:
ref: ${{ github.ref_name }}
fetch-depth: 0
- name: Publish to NPM
uses: photon-hq/buildspace/.github/blocks/publish-npm@main
with:
bun-version: ${{ inputs.bun-version }}
tag: ${{ (inputs.prerelease || fromJSON(needs.check-labels.outputs.labels).prerelease) && 'beta' || inputs.npm-tag }}
working-directory: ${{ inputs.working-directory }}
build-command: ${{ inputs.build-command }}
publish-command: ${{ inputs.publish-command }}
dry-run: ${{ inputs.dry-run }}
npm-token: ${{ secrets.NPM_TOKEN }}
# OIDC publish path (use-oidc: true). Opt-in only. It omits an explicit
# `permissions:` block so it inherits the caller's GITHUB_TOKEN — meaning
# `id-token: write` flows through when the caller grants it. Because it never
# *requests* id-token, callers that haven't granted it can't be hard-failed;
# the publish step just falls back to NPM_TOKEN. Default callers never reach
# this job (the `if` below is false), so their permissions are untouched.
npm-publish-oidc:
needs: [check-labels, release-info, bump-version]
if: (fromJSON(needs.check-labels.outputs.labels).release || inputs.release) && inputs.no-npm-publish != true && inputs.use-oidc == true
runs-on: ${{ inputs.use-blacksmith && 'blacksmith-4vcpu-ubuntu-2404' || 'ubuntu-latest' }}
steps:
- uses: actions/checkout@v5
with:
ref: ${{ github.ref_name }}
fetch-depth: 0
- name: Publish to NPM
uses: photon-hq/buildspace/.github/blocks/publish-npm@main
with:
bun-version: ${{ inputs.bun-version }}
tag: ${{ (inputs.prerelease || fromJSON(needs.check-labels.outputs.labels).prerelease) && 'beta' || inputs.npm-tag }}
working-directory: ${{ inputs.working-directory }}
build-command: ${{ inputs.build-command }}
publish-command: ${{ inputs.publish-command }}
dry-run: ${{ inputs.dry-run }}
npm-token: ${{ secrets.NPM_TOKEN }}
notify:
needs: [check-labels, release-info, github-release, npm-publish, npm-publish-oidc]
if: >-
always() &&
github.repository == 'photon-hq/spectrum-ts' &&
(fromJSON(needs.check-labels.outputs.labels).release || inputs.release) &&
needs.release-info.result == 'success' &&
needs.github-release.result == 'success' &&
(needs.npm-publish.result == 'success' || needs.npm-publish.result == 'skipped') &&
(needs.npm-publish-oidc.result == 'success' || needs.npm-publish-oidc.result == 'skipped') &&
inputs.notify-on-release &&
contains(fromJSON('["major","minor","patch"]'), needs.release-info.outputs.release_type)
runs-on: ${{ inputs.use-blacksmith && 'blacksmith-4vcpu-ubuntu-2404' || 'ubuntu-latest' }}
permissions:
contents: read
steps:
- name: Join Tailnet
uses: tailscale/github-action@v3
with:
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
tags: tag:infra
version: latest
- name: POST to email-monkey
env:
SERVICE_NAME: ${{ inputs.service-name }}
REPO: ${{ github.repository }}
VERSION: ${{ needs.release-info.outputs.version }}
RELEASE_NOTES: ${{ needs.release-info.outputs.release_notes }}
RELEASE_TYPE: ${{ needs.release-info.outputs.release_type }}
shell: bash
run: |
set -euo pipefail
BODY="$(jq -nc \
--arg repo "$REPO" \
--arg version "$VERSION" \
--arg releaseNotes "$RELEASE_NOTES" \
--arg releaseType "$RELEASE_TYPE" \
--arg serviceName "$SERVICE_NAME" \
'{repo:$repo, version:$version, releaseNotes:$releaseNotes, releaseType:$releaseType, serviceName:$serviceName}')"
echo "POSTing to email-monkey for $REPO (release_type=$RELEASE_TYPE, version=$VERSION)"
HTTP_CODE="$(curl --silent --show-error \
--output /tmp/email-monkey.out \
--write-out '%{http_code}' \
--max-time 60 \
--request POST "http://email-monkey/notify-release" \
--header "Content-Type: application/json" \
--data "$BODY")"
echo "email-monkey response ($HTTP_CODE):"
cat /tmp/email-monkey.out || true
echo
if [ "$HTTP_CODE" -ge 400 ]; then
echo "::error::email-monkey returned HTTP $HTTP_CODE"
exit 1
fi