-
Notifications
You must be signed in to change notification settings - Fork 2
197 lines (164 loc) · 5.41 KB
/
publish.yml
File metadata and controls
197 lines (164 loc) · 5.41 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
name: Publish
on:
workflow_run:
workflows: ["node-es-transformer CI"]
types:
- completed
branches:
- main
release:
types: [published]
workflow_dispatch:
inputs:
target:
description: "Publish target"
required: true
type: choice
default: dry-run
options:
- dry-run
- npm
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
release-pr:
name: Create Release PR
runs-on: ubuntu-latest
if: github.event_name == 'workflow_run'
permissions:
contents: write
pull-requests: write
steps:
- name: Check CI Success
if: ${{ github.event.workflow_run.conclusion != 'success' }}
run: |
echo "CI workflow did not succeed. Skipping release."
exit 1
- name: Generate GitHub App Token
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Checkout
uses: actions/checkout@v6
with:
token: ${{ steps.app-token.outputs.token }}
fetch-depth: 0
- name: Setup Node.js 22.x
uses: actions/setup-node@v6
with:
node-version: 22.x
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Check for Changesets
id: check-changesets
run: |
CHANGESET_COUNT=$(find .changeset -name "*.md" ! -name "README.md" 2>/dev/null | wc -l | tr -d ' ')
if [ "$CHANGESET_COUNT" -gt 0 ]; then
echo "hasChangesets=true" >> $GITHUB_OUTPUT
echo "Found $CHANGESET_COUNT changeset(s)"
else
echo "hasChangesets=false" >> $GITHUB_OUTPUT
echo "No changesets found"
fi
- name: Create Release Pull Request
if: steps.check-changesets.outputs.hasChangesets == 'true'
run: node scripts/create-release-pr.mjs
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
GITHUB_REPOSITORY: ${{ github.repository }}
- name: Check for Published Version
id: check-publish
if: steps.check-changesets.outputs.hasChangesets == 'false'
run: |
VERSION=$(node -p "require('./package.json').version")
if git ls-remote --tags origin "refs/tags/v${VERSION}" | grep -q "v${VERSION}$"; then
echo "shouldPublish=false" >> $GITHUB_OUTPUT
echo "Tag v${VERSION} already exists"
else
echo "shouldPublish=true" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Will create release for v${VERSION}"
fi
- name: Create GitHub Release
if: steps.check-publish.outputs.shouldPublish == 'true'
run: |
VERSION="${{ steps.check-publish.outputs.version }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "v${VERSION}" -m "Release v${VERSION}"
git push origin "v${VERSION}"
RELEASE_NOTES=$(awk '/^## / {if (found) exit; found=1; next} found' CHANGELOG.md)
gh release create "v${VERSION}" \
--title "v${VERSION}" \
--notes "${RELEASE_NOTES}"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
build:
name: Build package
runs-on: ubuntu-latest
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node.js 22.x
uses: actions/setup-node@v6
with:
node-version: 22.x
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Build tarball
run: npm pack --silent
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: package
path: "*.tgz"
publish-dry-run:
name: Publish dry run
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'dry-run'
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: package
path: dist
- name: Setup Node.js 22.x
uses: actions/setup-node@v6
with:
node-version: 22.x
registry-url: https://registry.npmjs.org
- name: Dry-run publish
run: npm publish --dry-run ./dist/*.tgz
publish-npm:
name: Publish to npm
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'npm')
environment: npm
permissions:
contents: read
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: package
path: dist
- name: Setup Node.js 22.x
uses: actions/setup-node@v6
with:
node-version: 22.x
registry-url: https://registry.npmjs.org
- name: Upgrade npm for OIDC support
run: npm install -g npm@latest
- name: Publish to npm
run: npm publish --provenance --access public ./dist/*.tgz