Repository navigation
149 lines (144 loc) · 6.3 KB
/
Copy pathrelease.yml
File metadata and controls
149 lines (144 loc) · 6.3 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
name: Release SDK
on:
pull_request:
types: [closed]
branches: [main]
workflow_dispatch:
inputs:
version:
description: 'Recovery only: version to release from main, e.g. 2.0.0'
required: true
type: string
github_packages_only:
description: 'Mirror an existing release to GitHub Packages only; never tag or publish to npm'
type: boolean
default: false
# Avoid concurrent publication attempts.
concurrency:
group: sdk-release
cancel-in-progress: false
permissions:
contents: read
jobs:
release:
name: Tag, publish SDK, and create release
if: >-
(github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' && !inputs.github_packages_only) ||
(github.event.pull_request.merged == true &&
(startsWith(github.event.pull_request.head.ref, 'release/v') ||
startsWith(github.event.pull_request.head.ref, 'dev-v')))
runs-on: ubuntu-latest
timeout-minutes: 25
permissions:
contents: write
id-token: write
outputs:
tag: ${{ steps.metadata.outputs.tag }}
env:
RELEASE_BRANCH: ${{ github.event.pull_request.head.ref || format('release/v{0}', inputs.version) }}
steps:
- name: Check npm publishing credential
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
run: |
if [[ -z "$NODE_AUTH_TOKEN" ]]; then
echo "::error::NPM_AUTH_TOKEN must be available to this repository and authorized to publish @fleetbase/sdk."
exit 1
fi
- uses: actions/checkout@v4
with:
# Never tag whatever main happens to point at when the job starts.
ref: ${{ github.event.pull_request.merge_commit_sha || github.sha }}
fetch-depth: 0
persist-credentials: false
- uses: pnpm/action-setup@v4
with:
run_install: false
- uses: actions/setup-node@v4
with:
node-version: 24.15.0
cache: pnpm
registry-url: https://registry.npmjs.org
- name: Validate reviewed commit and release metadata
id: metadata
run: |
git merge-base --is-ancestor HEAD origin/main
tag=$(node scripts/release-tag.mjs "$RELEASE_BRANCH" --name-only)
node scripts/validate-release.mjs "$tag"
echo "tag=$tag" >> "$GITHUB_OUTPUT"
- run: pnpm install --frozen-lockfile
- run: pnpm run verify
- name: Tag the exact reviewed commit
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh auth setup-git
node scripts/release-tag.mjs "$RELEASE_BRANCH"
# Continue directly: tags pushed by GITHUB_TOKEN do not trigger other workflows.
- name: Publish SDK with provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
run: pnpm run publish:ci
- name: Verify registry checksum and clean consumers
run: node scripts/verify-published.mjs
- name: Preserve release evidence
if: always()
uses: actions/upload-artifact@v4
with:
name: npm-release-${{ github.sha }}
path: artifacts/
if-no-files-found: warn
retention-days: 90
- name: Create GitHub release or attach verified evidence
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TAG: ${{ steps.metadata.outputs.tag }}
run: |
if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
gh release upload "$RELEASE_TAG" artifacts/*.tgz artifacts/SHA256SUMS --clobber
else
extra=()
if [[ "$RELEASE_TAG" == *-* ]]; then extra+=(--prerelease); fi
gh release create "$RELEASE_TAG" artifacts/*.tgz artifacts/SHA256SUMS --verify-tag --notes-file RELEASE.md --title "$RELEASE_TAG" "${extra[@]}"
fi
github_packages:
name: Publish verified release to GitHub Packages
needs: release
if: >-
always() &&
(needs.release.result == 'success' ||
(github.event_name == 'workflow_dispatch' && inputs.github_packages_only))
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
packages: write
env:
RELEASE_TAG: ${{ needs.release.outputs.tag || format('v{0}', inputs.version) }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.merge_commit_sha || github.sha }}
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-node@v4
with:
node-version: 24.15.0
registry-url: https://npm.pkg.github.com
scope: '@fleetbase'
- name: Download the existing release artifact without rebuilding
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
[[ "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]
git merge-base --is-ancestor "$RELEASE_TAG^{commit}" origin/main
gh release download "$RELEASE_TAG" --pattern '*.tgz' --pattern SHA256SUMS --dir artifacts
- name: Publish identical bytes and verify GitHub Packages
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: node scripts/publish-github.mjs "$RELEASE_TAG"
- name: Report GitHub package location and visibility
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api /orgs/fleetbase/packages/npm/sdk --jq '{name, visibility, html_url, repository: .repository.full_name}'