Repository navigation
251 lines (222 loc) · 8.67 KB
/
Copy pathrelease.yml
File metadata and controls
251 lines (222 loc) · 8.67 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
name: Release
on:
release:
# `published` covers new releases and prereleases; `released` also fires
# when an existing prerelease is changed to a full release.
types: [published, released]
workflow_dispatch:
inputs:
version:
type: choice
description: Release Version
required: true
default: next
options:
- latest
- next
branch:
description: Release Branch (confirm release branch)
required: true
default: main
permissions:
contents: read
id-token: write
concurrency:
group: publish-${{ github.workflow }}-${{ github.ref_name || github.run_id }}
cancel-in-progress: false
env:
PACKAGE_NAME: "@module-federation/vinext"
PACKAGE_DIR: packages/vinext
jobs:
publish:
name: Publish to npm
runs-on: ubuntu-latest
environment: Publish
# A new stable release fires both `published` and `released`; publish
# stable releases from `released` only so they run once.
if: github.event_name != 'release' || github.event.action == 'released' || github.event.release.prerelease
steps:
- name: Validate manual publish target
if: github.event_name == 'workflow_dispatch'
env:
RELEASE_BRANCH: ${{ github.event.inputs.branch }}
run: |
if [ "$RELEASE_BRANCH" != "main" ]; then
echo "Releases must publish from main."
echo "Got: $RELEASE_BRANCH"
exit 1
fi
- name: Check out repository
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.event.release.tag_name || github.event.inputs.branch }}
- name: Verify source is on main
run: |
git fetch --no-tags origin main:refs/remotes/origin/main
if ! git merge-base --is-ancestor HEAD origin/main; then
echo "Release source must be reachable from main."
echo "Got: $(git rev-parse HEAD)"
exit 1
fi
- name: Cache tool downloads
uses: actions/cache@v4
with:
path: ~/.cache
key: ${{ runner.os }}-toolcache-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-toolcache-
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: "10.33.2"
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: "24.15.0"
cache: pnpm
registry-url: "https://registry.npmjs.org"
- name: Set up npm
run: npm install --global npm@12.0.2
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Generate preview version
if: github.event_name == 'workflow_dispatch' && github.event.inputs.version == 'next'
run: |
pnpm exec changeset version --snapshot next
cd "$PACKAGE_DIR"
SNAPSHOT_VERSION="$(node -p "require('./package.json').version")"
BASE_VERSION="${SNAPSHOT_VERSION%%-*}"
NEXT_VERSION="${BASE_VERSION}-next.${GITHUB_RUN_ID}"
npm pkg set version="$NEXT_VERSION"
echo "Set preview version: $NEXT_VERSION"
- name: Verify tag matches package version
if: github.event_name == 'release'
working-directory: ${{ env.PACKAGE_DIR }}
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
TAG="$RELEASE_TAG"
if [ "${TAG#v}" != "$TAG" ]; then
echo "Invalid tag format; refusing to publish."
echo "Expected: 1.2.3 (no leading 'v')"
echo "Got: $TAG"
exit 1
fi
PKG_VERSION="$(node -p "require('./package.json').version")"
if [ "$PKG_VERSION" != "$TAG" ]; then
echo "Version mismatch; refusing to publish."
echo "Git tag: $TAG"
echo "package.json version: $PKG_VERSION"
exit 1
fi
- name: Set deterministic prerelease version
if: github.event_name == 'release' && github.event.release.prerelease
working-directory: ${{ env.PACKAGE_DIR }}
run: |
CURRENT_VERSION="$(node -p "require('./package.json').version")"
BASE_VERSION="${CURRENT_VERSION%%-*}"
NEXT_VERSION="${BASE_VERSION}-next.${GITHUB_RUN_ID}"
npm pkg set version="$NEXT_VERSION"
echo "Set prerelease version: $NEXT_VERSION"
- name: Run checks
run: pnpm run check
- name: Check formatting
run: pnpm run fmt.check
- name: Pack package
working-directory: ${{ env.PACKAGE_DIR }}
# pnpm pack resolves catalog: and workspace: specifiers; npm publish does not.
run: pnpm pack --pack-destination "$RUNNER_TEMP/package"
- name: Compute npm dist-tag
id: dist
env:
EVENT_NAME: ${{ github.event_name }}
IS_PRERELEASE: ${{ github.event.release.prerelease || false }}
RELEASE_VERSION: ${{ github.event.inputs.version }}
run: |
DIST_TAG="latest"
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
if [ "$RELEASE_VERSION" = "next" ]; then
DIST_TAG="next"
fi
elif [ "$IS_PRERELEASE" = "true" ]; then
DIST_TAG="next"
fi
echo "dist_tag=$DIST_TAG" >> "$GITHUB_OUTPUT"
- name: Resolve publish action
working-directory: ${{ env.PACKAGE_DIR }}
id: publish_action
env:
DIST_TAG: ${{ steps.dist.outputs.dist_tag }}
run: |
PKG_VERSION="$(node -p "require('./package.json').version")"
ACTION="publish"
REASON="new version not yet on npm"
EXISTING_VERSION="$(npm view "$PACKAGE_NAME@$PKG_VERSION" version --json 2>/dev/null || true)"
EXISTING_VERSION="${EXISTING_VERSION#\"}"
EXISTING_VERSION="${EXISTING_VERSION%\"}"
if [ "$EXISTING_VERSION" = "$PKG_VERSION" ]; then
CURRENT_TAG_VERSION="$(npm view "$PACKAGE_NAME" "dist-tags.$DIST_TAG" --json 2>/dev/null || true)"
CURRENT_TAG_VERSION="${CURRENT_TAG_VERSION#\"}"
CURRENT_TAG_VERSION="${CURRENT_TAG_VERSION%\"}"
if [ "$CURRENT_TAG_VERSION" = "null" ]; then
CURRENT_TAG_VERSION=""
fi
if [ "$CURRENT_TAG_VERSION" = "$PKG_VERSION" ]; then
ACTION="skip"
REASON="version already published and dist-tag already points to it"
else
echo "Refusing to republish existing npm version:"
echo "Package: $PACKAGE_NAME"
echo "Version: $PKG_VERSION"
echo "Target dist-tag: $DIST_TAG"
echo "Current '$DIST_TAG' dist-tag points to: ${CURRENT_TAG_VERSION:-<unset>}"
echo ""
echo "Trusted Publishers do not support dist-tag promotion without publishing."
echo "Use a new semver version for this release flow."
exit 1
fi
fi
echo "action=$ACTION" >> "$GITHUB_OUTPUT"
echo "reason=$REASON" >> "$GITHUB_OUTPUT"
- name: Publish to npm
if: steps.publish_action.outputs.action == 'publish'
env:
DIST_TAG: ${{ steps.dist.outputs.dist_tag }}
run: npm publish "$RUNNER_TEMP"/package/*.tgz --provenance --tag "$DIST_TAG" --access public
- name: Skip npm publish
if: steps.publish_action.outputs.action == 'skip'
env:
REASON: ${{ steps.publish_action.outputs.reason }}
run: |
echo "Skipping npm publish:"
echo "$REASON"
- name: Post summary
if: always()
working-directory: ${{ env.PACKAGE_DIR }}
continue-on-error: true
env:
SOURCE_REF: ${{ github.event.release.tag_name || github.event.inputs.branch }}
DIST_TAG: ${{ steps.dist.outputs.dist_tag }}
ACTION: ${{ steps.publish_action.outputs.action || 'unknown' }}
REASON: ${{ steps.publish_action.outputs.reason || 'n/a' }}
EVENT_NAME: ${{ github.event_name }}
run: |
PKG_VERSION="$(node -p "require('./package.json').version")"
{
echo "## npm publish"
echo ""
echo "Package: \`$PACKAGE_NAME\`"
echo "Version: \`$PKG_VERSION\`"
echo "Dist-tag: \`$DIST_TAG\`"
echo "Action: \`$ACTION\`"
echo "Reason: \`$REASON\`"
echo "Trigger: \`$EVENT_NAME\`"
echo "Source ref: \`$SOURCE_REF\`"
if [ "$ACTION" = "publish" ]; then
echo ""
echo '```sh'
echo "pnpm add $PACKAGE_NAME@$PKG_VERSION"
echo '```'
fi
} >> "$GITHUB_STEP_SUMMARY"