-
Notifications
You must be signed in to change notification settings - Fork 1
179 lines (154 loc) · 6.25 KB
/
release.yml
File metadata and controls
179 lines (154 loc) · 6.25 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
name: Build & Publish Release
on:
release:
types:
- released
- prereleased
concurrency:
group: "release-${{ github.event.release.id }}"
cancel-in-progress: true
permissions:
id-token: write
jobs:
sanity-checks:
name: Sanity Checks
permissions:
id-token: none
uses: ./.github/workflows/sanity-checks.yml
add-publishing-note:
name: Add Publishing Note
if: github.event.release != null
runs-on: ubuntu-latest
permissions:
contents: write
id-token: none
concurrency:
group: "release-editing-${{ github.event.release.id }}"
steps:
#############################
## ##
## Edit Release Body ##
## (build pending) ##
## ##
#############################
- name: "Update Release Title & Description"
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: context.payload.release.id,
name: context.payload.release.name + " (Building)",
body: context.payload.release.body + "\n\n<!-- ACTIONS_REMOVE_AFTER_BUILD -->\n\n---\n\n> [!NOTE]\n> ### This release is currently being built.\n> Build artifacts will be added to this release once the build is complete. For now, you can watch the build progress from [its GitHub Actions page](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).",
})
build-and-publish:
name: Build & Publish
needs: [sanity-checks, add-publishing-note]
runs-on: ubuntu-latest
permissions:
id-token: write
packages: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@v5.0.0
with:
fetch-depth: 0
- name: Setup Tools
uses: tanstack/config/.github/setup@9286c261b7c25a2c0342e2a06510f9cd9e4512f6
- name: Set package.json Version Field to the Release's Tag
if: github.event.release != null
uses: BellCubeDev/update-package-version-by-release-tag@v2
with:
ignore-semver-check: "true"
###########################
## ##
## Build & Package ##
## ##
###########################
- name: Run Build
run: pnpm run build
- name: PNPM Pack
run: |
pnpm pack
#############################
## ##
## Release Artifacts ##
## ##
#############################
- name: "Upload Files to Release"
if: github.event.release != null
uses: AButler/upload-release-assets@v3.0
with:
files: "*.tgz"
repo-token: ${{ secrets.GITHUB_TOKEN }}
release-id: ${{ github.event.release.id }}
########################
## ##
## NPM Registry ##
## ##
########################
- id: publish-npm
name: Publish to NPM Registry
# Uses OIDC token to authenticate, so no need to set up a secret for this
# This does restrict us to only using base `npm`, though 🙁
run: |
pnpm dlx npm publish --access public --registry https://registry.npmjs.org/ --tag ${{ github.event.release.prerelease && 'next' || 'latest' }} --provenance
- name: ON FAILURE - cat NPM debug log for "Publish to NPM Registry"
if: always() && steps.publish-npm.outcome == 'failure'
run: |
echo "ACTIONS_ID_TOKEN_REQUEST_URL: $ACTIONS_ID_TOKEN_REQUEST_URL"
echo "ACTIONS_ID_TOKEN_REQUEST_TOKEN is set: ${{ env.ACTIONS_ID_TOKEN_REQUEST_TOKEN != '' }}"
echo ""
echo ""
cat ~/.npm/_logs/*.log || echo "No NPM log file found"
#############################
## ##
## Edit Release Body ##
## (build success) ##
## ##
#############################
- name: "Update Release Title & Description"
if: github.event.release != null
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: context.payload.release.id,
name: context.payload.release.name.replace(/\s+\(Building\)$/, ''),
body: context.payload.release.body.replace(/<!-- ACTIONS_REMOVE_AFTER_BUILD -->[\s\S]*$/, '') + "\n\n---\n\n##### Built successfully by [GitHub Actions run #${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).",
})
note-release-build-failed:
permissions:
contents: write
id-token: none
name: "Note Release Build Failed"
needs: [build-and-publish]
if: failure() && github.event.release != null
runs-on: ubuntu-latest
concurrency:
group: "release-editing-${{ github.event.release.id }}"
steps:
#############################
## ##
## Edit Release Body ##
## (build failure) ##
## ##
#############################
- name: "Update Release Title & Description"
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: context.payload.release.id,
name: context.payload.release.name.replace(/\s+\(Building\)$/, '') + " (Failed)",
body: "> [!CAUTION]\n> ### This Release's Build Failed\n> The build for this release failed. You can see where and why the build failed in [its GitHub Action page](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).\n\n---\n\n" + context.payload.release.body.replace(/<!-- ACTIONS_REMOVE_AFTER_BUILD -->[\s\S]*$/, ''),
})