-
Notifications
You must be signed in to change notification settings - Fork 1
237 lines (206 loc) · 8.37 KB
/
publish-github-packages.yml
File metadata and controls
237 lines (206 loc) · 8.37 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
# This workflow is the single npm Trusted Publisher entrypoint.
# It handles both stable releases and snapshot releases.
name: Publish npm Package
on:
push:
branches:
- master
- v2
workflow_dispatch:
inputs:
release_mode:
description: Release mode
required: true
default: snapshot
type: choice
options:
- snapshot
- stable
commit_sha:
description: Commit SHA for snapshot publishing (optional)
required: false
type: string
issue_comment:
types: [created]
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
jobs:
handle_snapshot_command:
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'issue_comment' && github.event.issue.pull_request)
runs-on: ubuntu-latest
outputs:
command_found: ${{ steps.check_command.outputs.command_found || 'false' }}
status_comment_id: ${{ steps.comment_deployment.outputs.comment_id || '' }}
pr_sha: ${{ steps.pr_details.outputs.sha || '' }}
steps:
- name: Check for snapshot-release command
if: github.event_name == 'issue_comment'
id: check_command
run: |
comment="${{ github.event.comment.body }}"
comment=$(echo "$comment" | xargs)
if [[ "$comment" =~ ^/snapshot-release ]]; then
echo "command_found=true" >> $GITHUB_OUTPUT
else
echo "command_found=false" >> $GITHUB_OUTPUT
fi
- name: React to comment
if: github.event_name == 'issue_comment' && steps.check_command.outputs.command_found == 'true'
uses: actions/github-script@v7
with:
script: |
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ github.event.comment.id }},
content: 'rocket'
});
- name: Get PR details
if: github.event_name == 'issue_comment' && steps.check_command.outputs.command_found == 'true'
id: pr_details
uses: actions/github-script@v7
with:
script: |
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: ${{ github.event.issue.number }}
});
core.setOutput('sha', pr.head.sha);
- name: Comment deployment started
if: github.event_name == 'issue_comment' && steps.check_command.outputs.command_found == 'true'
id: comment_deployment
uses: actions/github-script@v7
with:
script: |
const { data: comment } = await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.issue.number }},
body: '🚀 Starting snapshot release... This may take a few minutes.'
});
core.setOutput('comment_id', comment.id);
release:
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.release_mode == 'stable')
runs-on: ubuntu-latest
# Must match npm Trusted Publisher environment configuration.
environment: PUBLISH_NPM_REGISTRY_TOKEN
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
# npm Trusted Publishing requires modern Node/npm versions.
node-version: '24'
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: pnpm -r install
- name: Type Check UIKit
run: pnpm --filter @tidbcloud/uikit type-check
- name: Build Package
run: pnpm -r build
- name: Create Release Pull Request or Publish to npm
uses: changesets/action@v1
with:
commit: 'release: bump versions'
title: 'release: bump versions'
publish: pnpm release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_CONFIG_PROVENANCE: true
snapshot_release:
needs: handle_snapshot_command
if: |
(github.event_name == 'issue_comment' && needs.handle_snapshot_command.outputs.command_found == 'true') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.release_mode == 'snapshot')
runs-on: ubuntu-latest
# Must match npm Trusted Publisher environment configuration.
environment: PUBLISH_NPM_REGISTRY_TOKEN
concurrency: ${{ github.workflow }}-${{ github.ref }}-snapshot
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event_name == 'issue_comment' && needs.handle_snapshot_command.outputs.pr_sha || github.event.inputs.commit_sha || github.sha }}
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '24'
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: pnpm install
- name: Type Check UIKit
run: pnpm --filter @tidbcloud/uikit type-check
- name: Build Packages
run: pnpm build
- name: Configure Git User
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create Snapshot Changeset File
run: |
echo "---" > .changeset/snapshot-${{ github.run_id }}.md
echo "'@tidbcloud/uikit': patch" >> .changeset/snapshot-${{ github.run_id }}.md
echo "---" >> .changeset/snapshot-${{ github.run_id }}.md
echo "" >> .changeset/snapshot-${{ github.run_id }}.md
echo "chore: snapshot release" >> .changeset/snapshot-${{ github.run_id }}.md
- name: Bump Version for Snapshot
run: pnpm exec changeset version --snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish Snapshot to npm under experimental tag
run: pnpm exec changeset publish --tag experimental
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_CONFIG_PROVENANCE: true
- name: Get Published Version
id: get_version
run: echo "version=$(node -p "require('./packages/uikit/package.json').version")" >> $GITHUB_OUTPUT
notify_snapshot_result:
needs: [handle_snapshot_command, snapshot_release]
if: github.event_name == 'issue_comment' && always() && needs.handle_snapshot_command.outputs.command_found == 'true'
runs-on: ubuntu-latest
steps:
- name: Update comment with success
if: needs.snapshot_release.result == 'success'
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ needs.handle_snapshot_command.outputs.status_comment_id }},
body: `✅ Snapshot release published successfully!
📦 **Version**: \`${{ needs.snapshot_release.outputs.version }}\`
🏷️ **Tag**: \`experimental\`
🔗 **npm**: https://www.npmjs.com/package/@tidbcloud/uikit/v/${{ needs.snapshot_release.outputs.version }}?activeTab=readme
📥 **Install**:
\`\`\`
pnpm install @tidbcloud/uikit@${{ needs.snapshot_release.outputs.version }}
\`\`\`
You can test this version in your project now.`
});
- name: Update comment with failure
if: needs.snapshot_release.result == 'failure'
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ needs.handle_snapshot_command.outputs.status_comment_id }},
body: '❌ Snapshot release failed. Please check the [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.'
});