-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (138 loc) · 5 KB
/
release.yml
File metadata and controls
164 lines (138 loc) · 5 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
name: Release
on:
pull_request:
push:
branches: [main]
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
id-token: write
jobs:
snapshot:
name: Build & snapshot release
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 10
environment: release
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22.22.1
cache: pnpm
registry-url: https://registry.npmjs.org
- name: Upgrade npm for OIDC trusted publishing
run: npm install -g npm@latest
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
run: pnpm build
- name: Set snapshot version
id: version
run: |
SHORT_SHA=$(git rev-parse --short HEAD)
SNAPSHOT_VERSION="0.0.0-snapshot.${SHORT_SHA}"
pnpm pkg set version="${SNAPSHOT_VERSION}"
echo "version=${SNAPSHOT_VERSION}" >> $GITHUB_OUTPUT
- name: Clear .npmrc auth token (use OIDC instead)
run: npm config delete //registry.npmjs.org/:_authToken || true
- name: Publish snapshot
run: npm publish --tag pr_${{ github.event.number }} --access public --provenance
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const setMessage = (await import('${{ github.workspace }}/scripts/ci/set-message.mjs')).default;
await setMessage({
header: '## 📦 Snapshot release',
body: `Published [\`${{ steps.version.outputs.version }}\`](https://www.npmjs.com/package/@tenphi/glaze/v/${{ steps.version.outputs.version }}).\n\n\`\`\`\npnpm add @tenphi/glaze@${{ steps.version.outputs.version }}\n\`\`\``,
github,
repo: context.repo,
prNumber: ${{ github.event.number }},
});
release:
if: github.event_name == 'push'
runs-on: ubuntu-latest
timeout-minutes: 15
environment: release
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22.22.1
cache: pnpm
registry-url: https://registry.npmjs.org
- name: Upgrade npm for OIDC trusted publishing
run: npm install -g npm@latest
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
run: pnpm build
- name: Clear .npmrc auth token (use OIDC instead)
run: npm config delete //registry.npmjs.org/:_authToken || true
- name: Create Release Pull Request or Publish
id: changesets
uses: changesets/action@v1
with:
publish: pnpm release
title: 'chore: version packages'
commit: 'chore: version packages'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_CONFIG_PROVENANCE: true
- name: Create GitHub Release
if: steps.changesets.outputs.published == 'true'
uses: actions/github-script@v7
with:
script: |
const publishedPackages = JSON.parse('${{ steps.changesets.outputs.publishedPackages }}');
for (const pkg of publishedPackages) {
const tag = `v${pkg.version}`;
try {
const { data: existing } = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag,
});
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: existing.id,
name: tag,
generate_release_notes: true,
});
core.info(`Updated existing release for ${tag}`);
} catch (e) {
if (e.status === 404) {
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tag,
name: tag,
generate_release_notes: true,
});
core.info(`Created release for ${tag}`);
} else {
throw e;
}
}
}
- name: Trigger website redeploy
if: steps.changesets.outputs.published == 'true'
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.DISPATCH_TOKEN }}
repository: tenphi/tasty.style
event-type: glaze-release
client-payload: '{"version": "${{ fromJSON(steps.changesets.outputs.publishedPackages)[0].version }}"}'