Repository navigation
948 lines (875 loc) · 41.8 KB
/
Copy pathrelease.yml
File metadata and controls
948 lines (875 loc) · 41.8 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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
name: Release
on:
push:
branches:
- main
# A dispatch with no tag runs release-please, like a push. A dispatch
# with a tag rebuilds and publishes that existing release instead: the
# way to recover when a release was tagged but never reached PyPI.
workflow_dispatch:
inputs:
tag:
description: >-
Existing root release tag (vX.Y.Z) to rebuild and publish.
Leave empty to run release-please.
type: string
required: false
default: ""
index:
description: >-
Where a tag dispatch publishes. testpypi is the dry run of the
trusted-publishing setup and advertises nothing.
type: choice
options:
- pypi
- testpypi
default: pypi
permissions:
contents: write
pull-requests: write
# Keep CI from sending telemetry from anything this workflow runs.
env:
DEEPCTL_TELEMETRY_DISABLED: "1"
jobs:
release-please:
name: Release Please
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
prs_created: ${{ steps.release.outputs.prs_created }}
pr: ${{ steps.release.outputs.pr }}
steps:
- uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v4
id: release
with:
token: ${{ github.token }}
config-file: .github/release-please-config.json
manifest-file: .github/.release-please-manifest.json
# Only a push or a plain dispatch cuts a release. A tag dispatch
# republishes an existing tag, and a TestPyPI dry run must not
# create a real release.
if: ${{ github.event_name == 'push' || (inputs.tag == '' && inputs.index != 'testpypi') }}
- name: Refuse a TestPyPI dry run without a tag
if: ${{ github.event_name == 'workflow_dispatch' && inputs.index == 'testpypi' && inputs.tag == '' }}
run: |
echo "::error::a TestPyPI dry run needs a tag to publish"
exit 1
# The release PR's re-pin runs as two jobs so that no third-party code ever
# runs next to a write credential:
# sync-release-pr no token, no secrets. Runs uv and the lockstep check,
# and hands the resulting change over as a patch artifact.
# push-release-pr mints the release App token and runs no Python and no
# uv: it applies the patch, checks which files it touches,
# commits and pushes.
# A release-PR job that must run after the re-pin goes here as
# `needs: [release-please, push-release-pr]`. Benchmark gates report from the
# PR's own workflows, not from this file.
sync-release-pr:
name: Re-pin lockstep versions on the release PR
needs: release-please
if: ${{ needs.release-please.outputs.prs_created == 'true' && needs.release-please.outputs.pr }}
runs-on: ubuntu-latest
permissions:
contents: read
# Two commits landing on main in quick succession would otherwise compute
# two patches against the same branch. Serialize instead of cancelling.
concurrency:
group: sync-release-pr
cancel-in-progress: false
outputs:
changed: ${{ steps.patch.outputs.changed }}
base: ${{ steps.patch.outputs.base }}
env:
BRANCH: ${{ fromJSON(needs.release-please.outputs.pr).headBranchName }}
steps:
- name: Refuse anything but a release-please branch
run: |
case "${BRANCH}" in
release-please--*) ;;
*) echo "::error::refusing to re-pin ${BRANCH}: not a release-please branch"; exit 1 ;;
esac
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ env.BRANCH }}
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
version: "0.13.6"
# No cache: nothing this job writes may be restored by another job.
enable-cache: false
# release-please moves every lockstep version and marked pin. --fix
# catches anything it could not (a package added since, an unmarked
# pin), uv.lock follows the new versions (CI's `uv sync --locked` fails
# every job without it), and the plain check proves the result. The
# check's one dependency is installed hash-pinned.
- name: Re-pin and regenerate uv.lock
run: |
set -euo pipefail
printf '%s\n' 'packaging==26.3 --hash=sha256:d7193f7c8e4e93f444fde0262bf90af30e16fa0ad0ad44cb553c87339b23cd1c' > "${RUNNER_TEMP}/check-requirements.txt"
uv venv -q "${RUNNER_TEMP}/check"
uv pip install -q --python "${RUNNER_TEMP}/check/bin/python" --require-hashes --only-binary :all: -r "${RUNNER_TEMP}/check-requirements.txt"
"${RUNNER_TEMP}/check/bin/python" scripts/check_dependency_floors.py --fix
uv lock
"${RUNNER_TEMP}/check/bin/python" scripts/check_dependency_floors.py
- name: Write the re-pin as a patch
id: patch
run: |
set -euo pipefail
echo "base=$(git rev-parse HEAD)" >> "${GITHUB_OUTPUT}"
git add pyproject.toml packages/*/pyproject.toml uv.lock
# Anything else the re-pin touched means release-please and the
# check disagree about the tree; stop rather than push half of it.
if ! git diff --quiet; then
echo "::error::re-pin changed files outside the pyprojects and uv.lock:"
git diff --name-only
exit 1
fi
if git diff --cached --quiet; then
echo "versions, pins and uv.lock already in sync"
echo "changed=false" >> "${GITHUB_OUTPUT}"
exit 0
fi
git diff --cached --no-renames --binary > repin.patch
git diff --cached --stat
echo "changed=true" >> "${GITHUB_OUTPUT}"
- name: Hand the patch to the push job
if: ${{ steps.patch.outputs.changed == 'true' }}
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: repin-patch
path: repin.patch
retention-days: 1
push-release-pr:
name: Push the re-pin with the release App
needs: [release-please, sync-release-pr]
if: ${{ needs.sync-release-pr.outputs.changed == 'true' }}
runs-on: ubuntu-latest
# The App's private key is a secret of the `release` environment, whose
# deployment branches are limited to main: a workflow on any other branch
# can't read it.
environment: release
permissions:
contents: read
concurrency:
group: push-release-pr
cancel-in-progress: false
env:
BRANCH: ${{ fromJSON(needs.release-please.outputs.pr).headBranchName }}
BASE: ${{ needs.sync-release-pr.outputs.base }}
steps:
- name: Refuse anything but a release-please branch
run: |
case "${BRANCH}" in
release-please--*) ;;
*) echo "::error::refusing to push to ${BRANCH}: not a release-please branch"; exit 1 ;;
esac
# A token for this repository only, with contents: write and nothing
# else. Commits pushed with an App token trigger the PR's workflows, so
# the required checks (Lockstep versions among them) run on the release
# PR's final head. GITHUB_TOKEN pushes trigger nothing.
- name: Mint the release App token
id: app-token
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
client-id: ${{ vars.RELEASE_APP_CLIENT_ID }}
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
permission-contents: write
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ env.BRANCH }}
persist-credentials: false
- name: Fetch the patch
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: repin-patch
path: ${{ runner.temp }}/repin
- name: Apply the patch and check what it touches
run: |
set -euo pipefail
if [ "$(git rev-parse HEAD)" != "${BASE}" ]; then
echo "::error::${BRANCH} moved since the patch was computed; the next release-please run re-pins it"
exit 1
fi
git apply --check "${RUNNER_TEMP}/repin/repin.patch"
git apply --index "${RUNNER_TEMP}/repin/repin.patch"
# Only in-place edits of existing regular files, at exact paths:
# renames are listed as a delete plus an add, so neither a rename,
# a new file, a deletion, a symlink nor a mode change gets through.
git diff --cached --no-renames --raw | while read -r om nm _ _ st path; do
if [ "${om#:} ${nm} ${st}" != "100644 100644 M" ]; then
echo "::error::${path}: only in-place edits of existing files are allowed (${om#:} ${nm} ${st})"; exit 1
fi
if ! [[ "${path}" =~ ^(pyproject\.toml|uv\.lock|packages/[^/]+/pyproject\.toml)$ ]]; then
echo "::error::the patch touches ${path}"; exit 1
fi
done
# The token reaches git only through GIT_CONFIG_* environment entries:
# never in a URL, an argument or .git/config, and hooks are off.
- name: Commit and push with the release App token
env:
APP_TOKEN: ${{ steps.app-token.outputs.token }}
APP_SLUG: ${{ steps.app-token.outputs.app-slug }}
run: |
set -euo pipefail
BOT_ID=$(GH_TOKEN="${APP_TOKEN}" gh api "/users/${APP_SLUG}%5Bbot%5D" --jq .id)
git -c core.hooksPath=/dev/null \
-c user.name="${APP_SLUG}[bot]" \
-c user.email="${BOT_ID}+${APP_SLUG}[bot]@users.noreply.github.com" \
commit -m "chore: re-pin lockstep versions and regenerate uv.lock"
AUTH=$(printf 'x-access-token:%s' "${APP_TOKEN}" | base64 -w0)
echo "::add-mask::${AUTH}"
GIT_CONFIG_COUNT=2 \
GIT_CONFIG_KEY_0="http.https://github.com/.extraheader" \
GIT_CONFIG_VALUE_0="AUTHORIZATION: basic ${AUTH}" \
GIT_CONFIG_KEY_1="core.hooksPath" \
GIT_CONFIG_VALUE_1="/dev/null" \
git push origin "HEAD:refs/heads/${BRANCH}"
build:
name: Build packages
needs: release-please
if: >-
${{ needs.release-please.outputs.release_created == 'true' ||
(github.event_name == 'workflow_dispatch' && inputs.tag != '') }}
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4
with:
persist-credentials: false
# A new release builds the tag release-please just created, not
# whatever the run's branch points at. A recovery checks out its
# tag below, and needs the branch history and its tags for that.
ref: ${{ (github.event_name != 'workflow_dispatch' || inputs.tag == '') && needs.release-please.outputs.tag_name || '' }}
fetch-depth: ${{ (github.event_name == 'workflow_dispatch' && inputs.tag != '') && '0' || '1' }}
# Only a root release tag that is already a published GitHub release
# and is in the history of the branch this run was started on. The
# publish environments accept only main, release/* and next/*.
- name: Check out the recovery tag
if: ${{ github.event_name == 'workflow_dispatch' && inputs.tag != '' }}
env:
TAG: ${{ inputs.tag }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
# Checked before TAG is printed anywhere.
if ! [[ "${TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::the tag input is not a root release tag (vX.Y.Z)"; exit 1
fi
case "${GITHUB_REF}" in
refs/heads/main | refs/heads/release/* | refs/heads/next/*) ;;
*) echo "::error::start a recovery from main, release/* or next/*, not ${GITHUB_REF}"; exit 1 ;;
esac
if ! git rev-parse -q --verify "refs/tags/${TAG}^{commit}" >/dev/null; then
echo "::error::no tag ${TAG}"; exit 1
fi
if ! git merge-base --is-ancestor "refs/tags/${TAG}^{commit}" "${GITHUB_SHA}"; then
echo "::error::${TAG} is not in the history of ${GITHUB_REF_NAME}"; exit 1
fi
if ! DRAFT=$(gh release view "${TAG}" --repo "${GITHUB_REPOSITORY}" --json isDraft --jq .isDraft); then
echo "::error::${TAG} has no GitHub release"; exit 1
fi
if [ "${DRAFT}" != "false" ]; then
echo "::error::${TAG}'s GitHub release is still a draft"; exit 1
fi
git checkout --detach "refs/tags/${TAG}^{commit}"
echo "Rebuilding ${TAG} at $(git rev-parse HEAD)"
- name: Set up Python
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.11"
- name: Install build dependencies
run: pip install build==1.5.0 twine==7.0.0 packaging==26.3
# The release PR passes the Lockstep versions check before it merges;
# check the tree being built once more, so nothing reaches PyPI with a
# package off the root version or a first-party pin that isn't ==.
- name: Check lockstep versions before publishing
run: python scripts/check_dependency_floors.py
- name: Build all packages
run: make build
- name: Verify built packages
run: make verify-packages
# A tag name can move; the version inside the build can't. Publish
# only if the tree that was built carries the tag's version.
- name: Check the build matches the release tag
if: ${{ startsWith(inputs.tag || needs.release-please.outputs.tag_name, 'v') }}
env:
TAG: ${{ inputs.tag || needs.release-please.outputs.tag_name }}
run: |
set -euo pipefail
if ! compgen -G "dist/deepctl-${TAG#v}-*.whl" >/dev/null; then
echo "::error::the build has no deepctl ${TAG#v} wheel; ${TAG} does not point at that release"
ls dist/
exit 1
fi
- name: Upload artifacts
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: dist
path: dist/
test:
name: Test installation
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.11"
- name: Download artifacts
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: dist
path: dist/
- name: Test installation
run: |
DIST_DIR=$(pwd)/dist
pip install --find-links "$DIST_DIR" dist/deepctl-*.whl
deepctl --version
verify-published:
name: Verify release is installable from PyPI
needs: [release-please, publish]
# `pip install deepctl==X` must resolve the full dependency closure from
# PyPI before anything advertises the release. Two real failure modes:
# 0.2.27 published partially (root uninstallable, and pip *silently
# backtracks* to the previous version, exit 0), and the 0.3.0 rollout
# showed a fresh install backtracking to 0.2.26 during the CDN
# propagation window. Poll the actual resolver, not just the JSON
# endpoint, so mark-latest / deploy-web / brew never point at a version
# a user cannot install.
if: |
needs.release-please.outputs.release_created == 'true' &&
startsWith(needs.release-please.outputs.tag_name, 'v')
runs-on: ubuntu-latest
# Reads nothing and writes nothing: it installs from public PyPI. Drop the
# workflow-level contents/pull-requests write it would otherwise inherit.
permissions: {}
# Belt-and-braces ceiling for a hung runner or a wedged pip, so three
# release-advertising jobs can never sit queued behind this one
# indefinitely. It has to clear the poll's own worst case, which is 20
# minutes of sleeps *plus* 60 resolution attempts -- a ceiling that cuts
# the loop short would kill the job before it prints the diagnosis below.
timeout-minutes: 45
steps:
- name: Set up Python
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.12"
# Poll with --dry-run: it stops after resolution, which is cheap and is
# exactly what distinguishes "not propagated yet" from "broken".
- name: Wait until pip can resolve the full release
run: |
set -euo pipefail
VERSION="${TAG_NAME#v}"
python -m venv /tmp/verify
/tmp/verify/bin/pip install --quiet --upgrade pip
# The loop exits the moment resolution succeeds, so the ceiling only
# costs anything when it is actually hit. Propagation is normally
# seconds; 20 minutes is insurance, not an expected wait.
for i in $(seq 1 60); do
if /tmp/verify/bin/pip install --dry-run --no-cache-dir \
"deepctl==${VERSION}" >/dev/null 2>&1; then
echo "deepctl==${VERSION} resolves with its full closure"
exit 0
fi
echo "Waiting for deepctl==${VERSION} to resolve (${i}/60)..."
sleep 20
done
# Every attempt above discarded its output, so the operator would
# otherwise get a bare error line and have to reproduce by hand.
# Run once more with the output visible: pip's resolver says which
# requirement it could not satisfy.
echo "Resolution still failing. Final attempt, with output:"
/tmp/verify/bin/pip install --dry-run --no-cache-dir "deepctl==${VERSION}" || true
echo "::error::deepctl==${VERSION} did not resolve from PyPI after 20 minutes -- a dependency is missing or the index has not propagated. Once PyPI has propagated, use 'Re-run all jobs' on this workflow run -- re-running only this job leaves mark-latest, deploy-web and bump-brew-formula skipped. Re-running all jobs is safe: the PyPI publish step uses skip-existing."
exit 1
env:
TAG_NAME: ${{ needs.release-please.outputs.tag_name }}
# Resolving is not installing. --dry-run is satisfied by PyPI metadata
# (often via PEP 658, without fetching a single wheel), so a corrupt
# artifact or an entry point that cannot import still passes it. The
# build job smoke-tests `deepctl --version`, but against the local
# dist/ artifacts -- this is the only check against what PyPI serves,
# and it is the last gate before three jobs advertise the release.
#
# A fresh venv with nothing but PyPI (no --find-links, no cache), so
# the sub-packages are the ones PyPI serves, not the ones just built.
# A retry covers a wheel the CDN has not finished propagating.
- name: Install for real from PyPI and run the CLI
run: |
set -euo pipefail
VERSION="${TAG_NAME#v}"
for i in $(seq 1 5); do
rm -rf /tmp/real
python -m venv /tmp/real
if /tmp/real/bin/pip install --quiet --no-cache-dir "deepctl==${VERSION}"; then
break
fi
if [ "${i}" = 5 ]; then
echo "::error::pip install deepctl==${VERSION} from PyPI failed 5 times"
exit 1
fi
echo "Install attempt ${i}/5 failed; retrying in 30s..."
sleep 30
done
/tmp/real/bin/deepctl --version
# What the npm launcher and `dg update` rely on: a sibling released
# with stale code fails here with ModuleNotFoundError.
/tmp/real/bin/python -c "import deepctl_core._launcher, deepctl_cmd_update.installation"
env:
TAG_NAME: ${{ needs.release-please.outputs.tag_name }}
mark-latest:
name: Mark root release as latest
needs: [release-please, publish, verify-published]
# Re-assert latest on the root package tag (vX.Y.Z) after PyPI publish so
# users clicking "latest" land on a tag whose artifact is actually
# installable. The plugin example's own release (its only other
# component) is created with make-latest false.
if: |
needs.release-please.outputs.release_created == 'true' &&
startsWith(needs.release-please.outputs.tag_name, 'v')
runs-on: ubuntu-latest
steps:
- name: Mark root release as latest
run: gh release edit "${{ needs.release-please.outputs.tag_name }}" --latest --repo "${{ github.repository }}"
env:
GH_TOKEN: ${{ github.token }}
deploy-web:
name: Deploy web to production
needs: [release-please, publish, verify-published, publish-npm]
# Only fire on root-package releases (v0.2.4, v1.0.0, …) and only after
# PyPI publish and the npm publish + npx smoke test, so cli.deepgram.com
# never advertises a version that isn't installable yet. Sub-package tags look like deepctl-cmd-listen-v0.0.3 —
# skip those.
if: |
needs.release-please.outputs.release_created == 'true' &&
startsWith(needs.release-please.outputs.tag_name, 'v')
uses: ./.github/workflows/web-production.yml
secrets: inherit
# Trusted Publishing: each of the 31 PyPI projects names this file and
# the pypi environment as its publisher, and PyPI swaps the job's OIDC
# token for a short-lived upload token. There is no API token to read.
# The pypi environment deploys only from main, release/* and next/*.
publish:
name: Publish to PyPI
needs: [build, test]
if: ${{ github.event_name == 'push' || inputs.index == 'pypi' }}
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/deepctl/
permissions:
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: dist
path: dist/
# The root package goes last: it pins every sub-package ==, so it must
# never be on the index before them. "deepctl-" sorts before
# "deepctl_", so one upload of dist/ would send it first.
- name: Hold the root package back
run: |
set -euo pipefail
mkdir root-dist
mv dist/deepctl-[0-9]* root-dist/
ls root-dist/
- name: Publish the sub-packages to PyPI
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
packages-dir: dist/
skip-existing: true
- name: Publish the root package to PyPI
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
packages-dir: root-dist/
skip-existing: true
# The same upload against TestPyPI, from its own environment so that its
# OIDC token can never match a production PyPI publisher. Nothing
# downstream needs this job, so a dry run advertises nothing.
publish-testpypi:
name: Publish to TestPyPI
needs: [build, test]
if: ${{ github.event_name == 'workflow_dispatch' && inputs.index == 'testpypi' }}
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/project/deepctl/
permissions:
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: dist
path: dist/
# Root package last, as in publish.
- name: Hold the root package back
run: |
set -euo pipefail
mkdir root-dist
mv dist/deepctl-[0-9]* root-dist/
ls root-dist/
- name: Publish the sub-packages to TestPyPI
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
repository-url: https://test.pypi.org/legacy/
packages-dir: dist/
skip-existing: true
- name: Publish the root package to TestPyPI
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
repository-url: https://test.pypi.org/legacy/
packages-dir: root-dist/
skip-existing: true
bump-brew-formula:
name: Bump Homebrew formula
needs: [release-please, publish, verify-published]
# Only fire on root-package releases (v0.2.4, v1.0.0, …).
# Sub-package tags look like deepctl-cmd-listen-v0.0.3 — skip those.
if: |
needs.release-please.outputs.release_created == 'true' &&
startsWith(needs.release-please.outputs.tag_name, 'v')
runs-on: ubuntu-latest
# Two root releases in quick succession would otherwise race on the tap:
# both read the same "current" formula and the older one could land
# last. Serialize; the version guard below makes the later job a no-op
# if a newer bump already merged.
concurrency:
group: homebrew-tap-bump
cancel-in-progress: false
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4
- name: Set up Python
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.13"
# No PyPI poll here: verify-published is in `needs`, and it does not
# finish until `pip install deepctl==X` resolves its full closure and
# the installed CLI runs. A second, weaker poll behind that gate can
# only cost time.
- name: Checkout homebrew-tap
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4
with:
repository: deepgram/homebrew-tap
token: ${{ secrets.CLI_TAP_SYNC_PAT }}
path: homebrew-tap
- name: Regenerate Formula/deepgram.rb
run: |
set -euo pipefail
VERSION="${TAG_NAME#v}"
python scripts/bump_brew_formula.py \
--version "${VERSION}" \
--formula homebrew-tap/Formula/deepgram.rb \
--python "$(command -v python3.13)"
env:
TAG_NAME: ${{ needs.release-please.outputs.tag_name }}
- name: Open and merge bump PR against homebrew-tap
working-directory: homebrew-tap
env:
GH_TOKEN: ${{ secrets.CLI_TAP_SYNC_PAT }}
TAG_NAME: ${{ needs.release-please.outputs.tag_name }}
run: |
set -euo pipefail
VERSION="${TAG_NAME#v}"
BRANCH="bump-deepctl-${VERSION}"
# sort -V is not PEP 440 aware, so only ever compare plain X.Y.Z,
# which is all release-please cuts for the root package.
is_plain_version() { [[ "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; }
version_gt() { [ "$1" != "$2" ] && [ "$(printf '%s\n' "$1" "$2" | sort -V | tail -n1)" = "$1" ]; }
formula_version() { sed -nE 's|^ url ".*/deepctl-([0-9][^/"]*)\.tar\.gz"$|\1|p'; }
# HEAD is the tap's main as checked out; the regenerate step only
# rewrote the working tree, so HEAD still holds what the tap serves.
CURRENT="$(git show HEAD:Formula/deepgram.rb | formula_version)"
GENERATED="$(formula_version < Formula/deepgram.rb)"
for v in "${VERSION}" "${CURRENT}" "${GENERATED}"; do
if ! is_plain_version "${v}"; then
echo "::error::Expected a plain X.Y.Z deepctl version, got '${v}'; check the tag and the formula template"
exit 1
fi
done
if [ "${GENERATED}" != "${VERSION}" ]; then
echo "::error::Regenerated formula points at deepctl ${GENERATED}, expected ${VERSION}"
exit 1
fi
# Never let a re-run of an older release replace a newer formula.
# Equal skips too: that bump already landed, and re-pinning resources
# under an unchanged version would not reach existing installs.
if ! version_gt "${VERSION}" "${CURRENT}"; then
echo "::warning::Tap already serves deepctl ${CURRENT}; not bumping to ${VERSION}"
exit 0
fi
# Attribute the bump commit to whoever owns CLI_TAP_SYNC_PAT so the
# homebrew-tap PR has a clear, linkable author. Using ${{ github.actor }}
# would misattribute to release-please[bot] (the workflow trigger),
# not the credential owner who actually authorized the push.
PAT_LOGIN=$(gh api /user --jq .login)
PAT_ID=$(gh api /user --jq .id)
git config user.name "${PAT_LOGIN}"
git config user.email "${PAT_ID}+${PAT_LOGIN}@users.noreply.github.com"
git checkout -b "${BRANCH}"
# Syntax check only: catches a broken template or a mangled resource
# block, not a wrong sha256 or a failing `brew install`.
ruby -c Formula/deepgram.rb
git add Formula/deepgram.rb
git commit -m "Bump deepctl to ${VERSION}"
# --force: a re-run must be able to replace the branch an earlier,
# failed attempt pushed, with the formula it just regenerated.
git push --force -u origin "${BRANCH}"
BODY_FILE="$(mktemp)"
cat > "${BODY_FILE}" <<EOF
Automated bump from [deepgram/cli@${TAG_NAME}](https://github.com/deepgram/cli/releases/tag/${TAG_NAME}).
Generated by \`scripts/bump_brew_formula.py\` against PyPI metadata for \`deepctl==${VERSION}\`. Resource blocks regenerated via \`homebrew-pypi-poet\`.
If this PR breaks \`brew test\` or \`brew install\`, do not edit the formula directly — the file is auto-generated. Fix the template in [\`scripts/templates/deepgram.rb.template\`](https://github.com/deepgram/cli/blob/main/scripts/templates/deepgram.rb.template) and let the next release regenerate it. For emergency fixes, run \`scripts/bump_brew_formula.py\` locally and push directly.
EOF
# Reuse the PR an earlier attempt opened, if any. Only trust a
# same-repo PR from the PAT owner: anyone can open a fork PR whose
# head branch has this name. $login is a jq variable, not shell.
# shellcheck disable=SC2016
OURS='[.[] | select((.isCrossRepository | not) and .author.login == $login)]'
PR_URL="$(gh pr list --head "${BRANCH}" --state open --json url,author,isCrossRepository \
| jq -r --arg login "${PAT_LOGIN}" "${OURS}"' | .[0].url // empty')"
if [ -z "${PR_URL}" ]; then
PR_URL="$(gh pr create \
--base main \
--head "${BRANCH}" \
--title "Bump deepctl to ${VERSION}" \
--body-file "${BODY_FILE}")"
fi
if [[ ! "${PR_URL}" =~ ^https://github\.com/deepgram/homebrew-tap/pull/[0-9]+$ ]]; then
echo "::error::Unexpected PR URL '${PR_URL}'"
exit 1
fi
# Merge it immediately. The formula is generated from PyPI metadata,
# and the tap has no checks or reviewers, so an open PR only delays
# Homebrew users: the 0.3.1, 0.3.2 and 0.3.3 bumps all sat unmerged
# while the tap served 0.2.26. The merged PR remains the audit trail.
# GitHub computes mergeability after the PR is created and gh does
# not wait for it, so retry a few times before giving up loudly.
for attempt in 1 2 3 4 5; do
if gh pr merge "${PR_URL}" --merge --delete-branch; then
break
fi
# Someone merged it by hand mid-loop, or gh merged it and then
# failed to delete the branch. Either way the bump landed.
if [ "$(gh pr view "${PR_URL}" --json state --jq .state || true)" = "MERGED" ]; then
break
fi
if [ "${attempt}" -eq 5 ]; then
echo "::error::Could not merge ${PR_URL} after 5 attempts; merge it by hand"
exit 1
fi
sleep $((attempt * 5))
done
# Close older bump PRs this credential opened that never merged:
# they could only downgrade the tap now. Best effort; a cleanup
# failure must not fail a bump that already landed.
STALE="$(mktemp)"
gh pr list --state open --limit 100 --json url,headRefName,author,isCrossRepository \
| jq -r --arg login "${PAT_LOGIN}" "${OURS}"' | .[] | [.url, .headRefName] | @tsv' > "${STALE}" \
|| { echo "::warning::Could not list stale bump PRs"; : > "${STALE}"; }
while IFS=$'\t' read -r url head; do
old="${head#bump-deepctl-}"
if ! { [ "${old}" != "${head}" ] && is_plain_version "${old}" && version_gt "${VERSION}" "${old}"; }; then
continue
fi
gh pr close "${url}" --delete-branch --comment "Superseded by ${PR_URL}." < /dev/null \
|| echo "::warning::Could not close ${url}"
done < "${STALE}"
publish-npm:
name: Publish @deepgram/cli to npm
needs: [release-please, verify-published]
# The npm package is a launcher that runs `deepctl==<its own version>`
# from PyPI, so it must never go out before that exact version installs.
# verify-published is that gate. Root tags only, same as mark-latest.
#
# Recovery: if this job fails (npm outage, trusted publisher not set up
# yet), fix the cause and use "Re-run failed jobs" on this workflow run.
# Job outputs from release-please are preserved across re-runs, and every
# step here is safe to repeat: an already-published version is skipped.
if: |
needs.release-please.outputs.release_created == 'true' &&
startsWith(needs.release-please.outputs.tag_name, 'v')
runs-on: ubuntu-latest
# Trusted publishing: npm exchanges this job's OIDC token for a one-time
# publish credential, so no long-lived npm token exists to leak. The
# trusted publisher on npmjs.com is bound to this workflow file and this
# environment; renaming either breaks publishing until it is updated.
environment: npm-publish
# actions: read only to look up when this run attempt started (below).
permissions:
id-token: write
contents: read
actions: read
timeout-minutes: 30
env:
TAG_NAME: ${{ needs.release-please.outputs.tag_name }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
# No registry-url: it writes an .npmrc expecting NODE_AUTH_TOKEN, and an
# empty token there makes npm skip the OIDC exchange.
- name: Set up Node
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "22"
# Trusted publishing needs npm 11.5.1+; Node 22 bundles npm 10. Pinned
# exactly so a new npm release cannot change how a release publishes.
- name: Install an npm that supports trusted publishing
run: npm install -g npm@11.21.0
# release-please bumps npm/package.json through extra-files. If that
# ever drifts, publishing would ship a launcher pinned to a deepctl
# version that verify-published never checked.
- name: Check the package version matches the tag
id: version
run: |
set -euo pipefail
VERSION="${TAG_NAME#v}"
PKG_VERSION="$(node -p 'require("./npm/package.json").version')"
if [ "${PKG_VERSION}" != "${VERSION}" ]; then
echo "::error::npm/package.json is ${PKG_VERSION} but the tag is ${TAG_NAME}"
exit 1
fi
if ! printf '%s' "${VERSION}" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::error::${VERSION} is not a plain X.Y.Z version"
exit 1
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
# This attempt's build, used only to cross-check what PyPI serves.
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: dist
path: dist/
- name: Install uv
uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
with:
version: "0.13.6"
# The launcher installs only what this file lists, checked against its
# hashes: deepctl's own packages with the hashes of the files PyPI
# serves (its JSON API), everything else from uv.lock. Not hashes of
# dist/: wheels aren't byte-reproducible, and a version PyPI already
# had (skip-existing, or an earlier attempt of this run) keeps its
# first files. Files PyPI received during this attempt must match
# dist/ exactly. Without the file in the tarball, the launcher
# refuses to install anything.
- name: Write the hash-locked requirements file
run: |
set -euo pipefail
STARTED="$(gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/attempts/${GITHUB_RUN_ATTEMPT}" --jq .run_started_at)"
python3 npm/scripts/write_requirements.py --dist dist/ --uploaded-since "${STARTED}"
(cd npm && npm pack --dry-run --json) > pack.json
# shellcheck disable=SC2016 # ${...} below is a JavaScript template
node -e '
const files = JSON.parse(require("fs").readFileSync("pack.json", "utf8"))[0].files.map((f) => f.path);
const want = `requirements-${process.env.VERSION}.txt`;
if (!files.includes(want)) { console.error(`::error::${want} is not in the npm tarball`); process.exit(1); }
'
env:
VERSION: ${{ steps.version.outputs.version }}
GH_TOKEN: ${{ github.token }}
# npm refuses to republish a version, so a re-run after a later step
# failed would otherwise fail here forever.
- name: Check whether this version is already on npm
id: existing
run: |
set -euo pipefail
if [ "$(npm view "@deepgram/cli@${VERSION}" version 2>/dev/null || true)" = "${VERSION}" ]; then
echo "@deepgram/cli@${VERSION} is already published; skipping publish"
echo "published=true" >> "$GITHUB_OUTPUT"
else
echo "published=false" >> "$GITHUB_OUTPUT"
fi
env:
VERSION: ${{ steps.version.outputs.version }}
# `npm publish` moves `latest` by default. A patch for an older line
# (0.4.x after 0.5.0 shipped) must not drag every new install back, so
# it goes out under a maintenance tag instead. Fail closed: only "the
# package has no latest yet" (E404) may fall through to latest.
- name: Choose the dist-tag
id: tag
run: |
set -euo pipefail
ERR="$(mktemp)"
if LATEST="$(npm view @deepgram/cli dist-tags.latest 2>"${ERR}")"; then
:
elif grep -q E404 "${ERR}"; then
LATEST=""
else
cat "${ERR}"
echo "::error::could not read the current latest dist-tag; refusing to guess"
exit 1
fi
TAG=latest
if [ -n "${LATEST}" ]; then
ORDER="$(node -e '
const parse = (v) => {
const [core, pre] = v.split("+")[0].split("-");
return { n: core.split(".").map(Number), pre: pre !== undefined };
};
const a = parse(process.argv[1]);
const b = parse(process.argv[2]);
let c = 0;
for (let i = 0; i < 3 && c === 0; i++) c = Math.sign(a.n[i] - b.n[i]);
if (c === 0 && a.pre !== b.pre) c = a.pre ? -1 : 1;
console.log(c < 0 ? "lower" : "not-lower");
' "${VERSION}" "${LATEST}")"
if [ "${ORDER}" = "lower" ]; then
TAG="v$(printf '%s' "${VERSION}" | cut -d. -f1-2)-maint"
fi
fi
echo "latest is ${LATEST:-unset}; publishing ${VERSION} with dist-tag ${TAG}"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
env:
VERSION: ${{ steps.version.outputs.version }}
- name: Publish
if: steps.existing.outputs.published != 'true'
working-directory: npm
run: npm publish --access public --provenance --tag "${DIST_TAG}"
env:
DIST_TAG: ${{ steps.tag.outputs.tag }}
- name: Wait until the registry serves the version
run: |
set -euo pipefail
for i in $(seq 1 40); do
if [ "$(npm view "@deepgram/cli@${VERSION}" version 2>/dev/null || true)" = "${VERSION}" ]; then
echo "@deepgram/cli@${VERSION} is visible"
exit 0
fi
echo "Waiting for @deepgram/cli@${VERSION} (${i}/40)..."
sleep 15
done
echo "::error::@deepgram/cli@${VERSION} was not visible on the registry after 10 minutes"
exit 1
env:
VERSION: ${{ steps.version.outputs.version }}
# The end-to-end check a user would do: npx resolves the published
# tarball, and the launcher has uv install deepctl from PyPI, checked
# against the tarball's requirements file.
- name: Run the published package
run: |
set -euo pipefail
for i in $(seq 1 10); do
if OUT="$(npx -y "@deepgram/cli@${VERSION}" --version 2>/dev/null)" && printf '%s' "${OUT}" | grep -qF "${VERSION}"; then
echo "${OUT}"
exit 0
fi
echo "npx @deepgram/cli@${VERSION} not runnable yet (${i}/10)..."
sleep 30
done
echo "Final attempt, with output:"
npx -y "@deepgram/cli@${VERSION}" --version || true
echo "::error::npx @deepgram/cli@${VERSION} --version did not report ${VERSION}"
exit 1
env:
VERSION: ${{ steps.version.outputs.version }}