-
Notifications
You must be signed in to change notification settings - Fork 4.2k
182 lines (159 loc) · 6.39 KB
/
Copy pathrelease-prepare.yml
File metadata and controls
182 lines (159 loc) · 6.39 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
name: Release
on:
push:
branches: [main]
workflow_dispatch: # manually cut a beta prerelease from main
permissions:
contents: write
pull-requests: write
id-token: write # Required for npm OIDC trusted publishing
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
prepare:
if: github.repository == 'Fission-AI/OpenSpec' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
# Generate GitHub App token first - used for checkout and changesets
# This allows git operations to trigger CI workflows on the version PR
# (GITHUB_TOKEN cannot trigger workflows by design)
- 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 }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: '24' # Node 24 includes npm 11.5.1+ required for OIDC
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'
- run: pnpm install --frozen-lockfile
# Opens/updates the Version Packages PR; publishes when the Version PR merges
- name: Create/Update Version PR
id: changesets
uses: changesets/action@v1
with:
title: 'chore(release): version packages'
createGithubReleases: true
# Use CI-specific release script: relies on version PR having been merged
# so package.json already contains the bumped version.
publish: pnpm run release:ci
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
# npm authentication handled via OIDC trusted publishing (no token needed)
# Manually-dispatched beta prerelease from main: version is the next stable
# release per pending changesets with a -beta.N suffix (e.g. v1.6.0-beta.1),
# published to npm under the `beta` dist-tag and posted as a prerelease-flagged
# GitHub Release. Changesets are left unconsumed, so the stable flow above is
# unaffected. This job lives in this file because npm trusted publishing
# authorizes a single workflow file per package.
#
# Users opt in with: npm install -g @fission-ai/openspec@beta
beta:
if: github.repository == 'Fission-AI/OpenSpec' && github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: '24' # Node 24 includes npm 11.5.1+ required for OIDC
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'
- run: pnpm install --frozen-lockfile
# Beta version = next stable version per pending changesets, plus a
# -beta.N suffix that increments over existing beta tags for that version.
- name: Compute beta version
id: version
env:
GH_TOKEN: ${{ github.token }}
run: |
git fetch --tags --force origin
pnpm exec changeset status --output=changeset-status.json
NEXT=$(node -p "JSON.parse(require('fs').readFileSync('changeset-status.json','utf8')).releases[0]?.newVersion ?? ''")
rm changeset-status.json
if [ -z "$NEXT" ]; then
echo "No pending changesets on main - nothing to cut a beta from."
exit 1
fi
N=1
while true; do
VERSION="${NEXT}-beta.${N}"
TAG="v${VERSION}"
TAG_EXISTS=false
NPM_EXISTS=false
RELEASE_EXISTS=false
if git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null; then
TAG_EXISTS=true
fi
if npm view "@fission-ai/openspec@${VERSION}" version >/dev/null 2>&1; then
NPM_EXISTS=true
fi
if gh release view "${TAG}" >/dev/null 2>&1; then
RELEASE_EXISTS=true
fi
if [ "$TAG_EXISTS" = false ] && [ "$NPM_EXISTS" = false ] && [ "$RELEASE_EXISTS" = false ]; then
break
fi
if [ "$RELEASE_EXISTS" = false ]; then
echo "Resuming incomplete beta ${TAG}"
break
fi
N=$((N + 1))
done
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "Cutting ${TAG}"
- name: Set package version
env:
VERSION: ${{ steps.version.outputs.version }}
run: npm version "$VERSION" --no-git-tag-version
# prepublishOnly runs the build. npm authentication handled via OIDC
# trusted publishing (no token needed).
- name: Publish to npm under the beta dist-tag
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
if npm view "@fission-ai/openspec@${VERSION}" version >/dev/null 2>&1; then
echo "@fission-ai/openspec@${VERSION} is already on npm; skipping publish."
exit 0
fi
npm publish --tag beta
- name: Tag and create GitHub prerelease
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.version }}
run: |
TAG="v${VERSION}"
HEAD_SHA=$(git rev-parse HEAD)
if git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null; then
TAG_SHA=$(git rev-list -n 1 "${TAG}")
if [ "$TAG_SHA" != "$HEAD_SHA" ]; then
echo "${TAG} already exists at ${TAG_SHA}, not current HEAD ${HEAD_SHA}."
exit 1
fi
else
git tag "${TAG}"
fi
if git ls-remote --exit-code --tags origin "refs/tags/${TAG}" >/dev/null 2>&1; then
echo "${TAG} already exists on origin; skipping tag push."
else
git push origin "${TAG}"
fi
if gh release view "${TAG}" >/dev/null 2>&1; then
echo "GitHub Release ${TAG} already exists; skipping release creation."
else
gh release create "${TAG}" \
--prerelease \
--generate-notes \
--title "${TAG}" \
--notes "Beta prerelease. Install with \`npm install -g @fission-ai/openspec@beta\`."
fi