Repository navigation
440 lines (397 loc) · 18.1 KB
/
Copy pathrelease.yml
File metadata and controls
440 lines (397 loc) · 18.1 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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
name: "Release"
on:
push:
branches: [main]
paths:
- '.changeset/*.md'
workflow_dispatch:
permissions:
contents: read
# Concurrency control: only one release process can run at a time
# This prevents race conditions if multiple releasable changesets merge simultaneously
concurrency:
group: release
cancel-in-progress: false
jobs:
check-changesets:
name: Check for changesets
runs-on: ubuntu-latest
outputs:
has-changesets: ${{ steps.check.outputs.has-changesets }}
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
fetch-depth: 0
- name: Check for changesets
id: check
run: |
if [ ! -d ".changeset" ] || [ -z "$(ls -A .changeset/*.md 2>/dev/null | grep -v README.md)" ]; then
echo "❌ No changesets found. Cannot proceed with release."
echo "Please ensure your PR includes a changeset file."
echo "has-changesets=false" >> "$GITHUB_OUTPUT"
else
echo "✓ Found changesets to process"
echo "has-changesets=true" >> "$GITHUB_OUTPUT"
fi
notify-approval-needed:
name: Notify Slack - Approval Needed
needs: check-changesets
if: needs.check-changesets.outputs.has-changesets == 'true'
uses: posthog/.github/.github/workflows/notify-approval-needed.yml@5ba5d24966f2c416ca792654638e4ce6f19f545b
with:
slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }}
slack_user_group_id: ${{ vars.GROUP_CLIENT_LIBRARIES_SLACK_GROUP_ID }}
secrets:
slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }}
posthog_project_api_key: ${{ secrets.POSTHOG_PROJECT_API_KEY }}
preserve-slack-thread:
name: Preserve Slack thread
needs: notify-approval-needed
if: needs.notify-approval-needed.outputs.slack_ts != ''
runs-on: ubuntu-latest
timeout-minutes: 5
continue-on-error: true
steps:
- name: Save approval thread timestamp
env:
THREAD_TS: ${{ needs.notify-approval-needed.outputs.slack_ts }}
run: printf '%s' "$THREAD_TS" > thread-ts.txt
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: release-slack-thread-${{ github.run_attempt }}
path: thread-ts.txt
retention-days: 30
if-no-files-found: error
version-bump:
name: Bump versions and commit to main
needs: [check-changesets, notify-approval-needed]
runs-on: ubuntu-latest
if: always() && needs.check-changesets.outputs.has-changesets == 'true'
environment: "Release"
permissions:
contents: read
outputs:
committed: ${{ steps.version-bump-outputs.outputs.committed }}
commit-hash: ${{ steps.version-bump-outputs.outputs.commit-hash }}
steps:
- name: Notify Slack - Approved
if: needs.notify-approval-needed.outputs.slack_ts != ''
uses: posthog/.github/.github/actions/slack-thread-reply@cb0979b67dcd585828b61ac45927eef4da8f6287 # main
with:
slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }}
slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }}
thread_ts: ${{ needs.notify-approval-needed.outputs.slack_ts }}
message: "✅ Release approved! Version bump in progress..."
emoji_reaction: "white_check_mark"
- name: Get GitHub App token
id: releaser
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
client-id: ${{ secrets.GH_APP_POSTHOG_RUBY_RELEASER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_RUBY_RELEASER_PRIVATE_KEY }}
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
fetch-depth: 0
token: ${{ steps.releaser.outputs.token }}
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Set up pnpm and Node.js
uses: pnpm/setup@fa36a5ef7dcdefc3a7cb25655c122e00cf6e636e # v3.1.2
with:
# TODO: pnpm/setup does not read .nvmrc yet. Keep this in sync with .nvmrc
# until https://github.com/jasongin/nvs/pull/315 lands.
# pnpm/setup installs runtimes via pnpm runtime, which requires pnpm >=11.1.0.
version: 11.7.0
runtime: node@24
cache: true
install: false
- name: Install changesets dependencies
run: pnpm install --frozen-lockfile
- name: Apply changesets
run: pnpm changeset version
- name: Sync versions to Ruby files
run: ./scripts/bump-version.sh
- name: Set up Ruby
uses: ruby/setup-ruby@de492cf36cbab201753d720ce4f4e336cd688c94 # v1.336.0
with:
ruby-version: ruby
bundler: 4.0.13
- name: Update lockfiles
run: |
bundle lock
BUNDLE_GEMFILE=gemfiles/otel.gemfile bundle lock
- name: Check for version bump changes
id: check-changes
run: |
if [ -z "$(git status --porcelain)" ]; then
echo "No changes to commit"
echo "has-changes=false" >> "$GITHUB_OUTPUT"
else
echo "has-changes=true" >> "$GITHUB_OUTPUT"
fi
- name: Commit version bump
id: commit-version-bump
if: steps.check-changes.outputs.has-changes == 'true'
uses: planetscale/ghcommit-action@a6b150b81dca5dd027baa898604418eec9e11465 # v0.2.22
with:
commit_message: "chore: update package versions [version bump] [skip ci]"
repo: ${{ github.repository }}
branch: main
env:
GITHUB_TOKEN: ${{ steps.releaser.outputs.token }}
- name: Set version bump outputs
id: version-bump-outputs
env:
HAS_CHANGES: ${{ steps.check-changes.outputs.has-changes }}
COMMIT_HASH: ${{ steps.commit-version-bump.outputs.commit-hash }}
run: |
if [ "$HAS_CHANGES" = "true" ]; then
echo "committed=true" >> "$GITHUB_OUTPUT"
echo "commit-hash=$COMMIT_HASH" >> "$GITHUB_OUTPUT"
else
echo "committed=false" >> "$GITHUB_OUTPUT"
echo "commit-hash=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
fi
- name: Resolve release failure metadata
id: release-failure-metadata
if: ${{ failure() }}
run: |
set -euo pipefail
package_name=""
package_version=""
separator=""
for package_json in posthog-ruby/package.json posthog-rails/package.json; do
if [ -f "$package_json" ]; then
package_name_part=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1])).get("name", ""))' "$package_json")
version=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1])).get("version", ""))' "$package_json")
if [ -n "$package_name_part" ] && [ -n "$version" ]; then
package_name="${package_name}${separator}${package_name_part}"
package_version="${package_version}${separator}${package_name_part}@v${version}"
separator=", "
fi
fi
done
echo "package_name=$package_name" >> "$GITHUB_OUTPUT"
echo "package_version=$package_version" >> "$GITHUB_OUTPUT"
- name: Send failure event to PostHog
if: ${{ failure() }}
continue-on-error: true
uses: PostHog/posthog-github-action@9a6a19d360820ab4d95ecc4a5a7564062c895f84 # v1.3.0
with:
posthog-token: "${{ secrets.POSTHOG_PROJECT_API_KEY }}"
event: "posthog-sdk-github-release-workflow-failure"
properties: >-
{
"commitSha": "${{ github.sha }}",
"jobStatus": "${{ job.status }}",
"ref": "${{ github.ref }}",
"repository": "${{ github.repository }}",
"sdk": "posthog-ruby",
"jobName": "version-bump",
"packageName": "${{ steps.release-failure-metadata.outputs.package_name || 'unknown' }}",
"packageVersion": "${{ steps.release-failure-metadata.outputs.package_version || 'unknown' }}",
"actionUrl": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"alertText": ":rotating_light: Failed to prepare release for posthog-ruby :rotating_light:",
"alertContext": "The version bump/changelog step failed before packages were published."
}
notify-rejected:
name: Notify Slack - Rejected
needs: [version-bump, notify-approval-needed]
runs-on: ubuntu-latest
if: always() && needs.version-bump.result == 'failure' && needs.notify-approval-needed.outputs.slack_ts != ''
steps:
- name: Check for rejection
id: check-rejection
env:
GH_TOKEN: ${{ github.token }}
run: |
RESPONSE=$(gh api /repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/approvals)
REJECTED=$(echo "$RESPONSE" | jq '[.[] | select(.state == "rejected")] | length')
if [ "$REJECTED" -gt 0 ]; then
echo "was_rejected=true" >> "$GITHUB_OUTPUT"
COMMENT=$(echo "$RESPONSE" | jq -r '.[] | select(.state == "rejected") | .comment // empty' | head -1)
if [ -n "$COMMENT" ]; then
{
echo 'message<<EOF'
echo "🚫 Release was rejected: $COMMENT"
echo 'EOF'
} >> "$GITHUB_OUTPUT"
else
echo "message=🚫 Release was rejected." >> "$GITHUB_OUTPUT"
fi
else
echo "was_rejected=false" >> "$GITHUB_OUTPUT"
fi
- name: Notify Slack - Rejected
if: steps.check-rejection.outputs.was_rejected == 'true'
uses: posthog/.github/.github/actions/slack-thread-reply@cb0979b67dcd585828b61ac45927eef4da8f6287 # main
with:
slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }}
slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }}
thread_ts: ${{ needs.notify-approval-needed.outputs.slack_ts }}
message: '${{ steps.check-rejection.outputs.message }}'
emoji_reaction: "no_entry_sign"
publish:
name: Release and publish (${{ matrix.package.name }})
needs: [version-bump, notify-approval-needed]
runs-on: ubuntu-latest
if: always() && needs.version-bump.outputs.committed == 'true'
permissions:
contents: write
id-token: write
strategy:
# Publish posthog-ruby before posthog-rails because the Rails gem depends on the core gem.
fail-fast: true
max-parallel: 1
matrix:
package:
- name: posthog-ruby
path: .
package_json: posthog-ruby/package.json
gemspec: posthog-ruby.gemspec
changelog: posthog-ruby/CHANGELOG.md
- name: posthog-rails
path: posthog-rails
package_json: posthog-rails/package.json
gemspec: posthog-rails.gemspec
changelog: posthog-rails/CHANGELOG.md
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.version-bump.outputs.commit-hash }}
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Fetch tags
run: git fetch --tags --force
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
- name: Set up Ruby
uses: ruby/setup-ruby@de492cf36cbab201753d720ce4f4e336cd688c94 # v1.336.0
with:
ruby-version: ruby
bundler: 4.0.13
bundler-cache: true
- name: Configure trusted publishing credentials
uses: rubygems/configure-rubygems-credentials@dc5a8d8553e6ee01fc26761a49e99e733d17954a # v2.1.0
- name: Detect version change for ${{ matrix.package.name }}
id: detect-version
run: |
set -euo pipefail
PACKAGE_JSON="${{ matrix.package.package_json }}"
CURRENT_VERSION=$(node -p "require('./${PACKAGE_JSON}').version")
RELEASE_TAG="${{ matrix.package.name }}-v${CURRENT_VERSION}"
if git diff --quiet HEAD^ HEAD -- "$PACKAGE_JSON"; then
echo "${{ matrix.package.name }} version did not change in the version-bump commit"
echo "has-new-version=false" >> "$GITHUB_OUTPUT"
elif git rev-parse "$RELEASE_TAG" >/dev/null 2>&1; then
echo "Tag $RELEASE_TAG already exists - no new version to release"
echo "has-new-version=false" >> "$GITHUB_OUTPUT"
else
echo "New ${{ matrix.package.name }} version detected: $CURRENT_VERSION"
echo "has-new-version=true" >> "$GITHUB_OUTPUT"
echo "version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
echo "tag=$RELEASE_TAG" >> "$GITHUB_OUTPUT"
fi
- name: Build ${{ matrix.package.name }}
if: steps.detect-version.outputs.has-new-version == 'true'
working-directory: ${{ matrix.package.path }}
run: gem build ${{ matrix.package.gemspec }}
- name: Publish ${{ matrix.package.name }}
if: steps.detect-version.outputs.has-new-version == 'true'
working-directory: ${{ matrix.package.path }}
env:
GEM_NAME: ${{ matrix.package.name }}
GEM_VERSION: ${{ steps.detect-version.outputs.version }}
run: |
set -euo pipefail
# A re-run after a later step failed must not try to push the same version again
if curl -fs --connect-timeout 10 --max-time 30 -o /dev/null "https://rubygems.org/api/v2/rubygems/${GEM_NAME}/versions/${GEM_VERSION}.json"; then
echo "${GEM_NAME} ${GEM_VERSION} is already on RubyGems - skipping push"
else
gem push "${GEM_NAME}"-*.gem
fi
- name: Wait for ${{ matrix.package.name }} to be available
if: steps.detect-version.outputs.has-new-version == 'true'
working-directory: ${{ matrix.package.path }}
# RubyGems' full index can take longer than the 5-minute default to update.
# rubygems-await 0.5.4 crashes on its compact index check with Bundler 4.1+,
# so activate an older Bundler before loading it.
run: |
gem install --no-document rubygems-await -v 0.5.4
ruby -e 'gem "bundler", "< 4.1"; load Gem.bin_path("rubygems-await", "rubygems-await")' -- --timeout 900 ${{ matrix.package.name }}-*.gem
- name: Tag ${{ matrix.package.name }}
if: steps.detect-version.outputs.has-new-version == 'true'
env:
RELEASE_TAG: ${{ steps.detect-version.outputs.tag }}
RELEASE_VERSION: ${{ steps.detect-version.outputs.version }}
PACKAGE_NAME: ${{ matrix.package.name }}
run: |
git tag -a "$RELEASE_TAG" -m "$PACKAGE_NAME $RELEASE_VERSION"
git push origin "$RELEASE_TAG"
- name: Create GitHub Release for ${{ matrix.package.name }}
if: steps.detect-version.outputs.has-new-version == 'true'
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ steps.detect-version.outputs.tag }}
CHANGELOG_FILE: ${{ matrix.package.changelog }}
run: |
if [ -f "$CHANGELOG_FILE" ]; then
awk -v defText="See $CHANGELOG_FILE" '
/^## / { if (found_version) exit; found_version=1; next }
found_version { print }
END { if (!found_version) print defText }
' "$CHANGELOG_FILE" | sed '/[^[:space:]]/,$!d' | tac | sed '/[^[:space:]]/,$!d' | tac > release-notes.md
else
echo "See $CHANGELOG_FILE" > release-notes.md
fi
gh release create "$RELEASE_TAG" \
--target "${{ needs.version-bump.outputs.commit-hash }}" \
--title "$RELEASE_TAG" \
--notes-file release-notes.md
- name: Send failure event to PostHog
if: ${{ failure() }}
continue-on-error: true
uses: PostHog/posthog-github-action@9a6a19d360820ab4d95ecc4a5a7564062c895f84 # v1.3.0
with:
posthog-token: "${{ secrets.POSTHOG_PROJECT_API_KEY }}"
event: "posthog-sdk-github-release-workflow-failure"
properties: >-
{
"commitSha": "${{ github.sha }}",
"jobStatus": "${{ job.status }}",
"ref": "${{ github.ref }}",
"repository": "${{ github.repository }}",
"sdk": "posthog-ruby",
"jobName": "publish",
"packageName": "${{ matrix.package.name }}",
"packageVersion": "${{ steps.detect-version.outputs.version || 'unknown' }}",
"actionUrl": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"alertText": ":rotating_light: Failed to release ${{ matrix.package.name }}@${{ steps.detect-version.outputs.version }} :rotating_light:",
"alertContext": "The package publish step failed."
}
notify-released:
name: Notify Slack - Released
needs: [version-bump, publish, notify-approval-needed]
runs-on: ubuntu-latest
if: always() && needs.publish.result == 'success' && needs.notify-approval-needed.outputs.slack_ts != ''
steps:
- name: Notify Slack - Released
uses: posthog/.github/.github/actions/slack-thread-reply@cb0979b67dcd585828b61ac45927eef4da8f6287 # main
with:
slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }}
slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }}
thread_ts: ${{ needs.notify-approval-needed.outputs.slack_ts }}
message: "🚀 Released updated package(s) successfully!"
emoji_reaction: "rocket"