forked from NoeFabris/opencode-antigravity-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
209 lines (178 loc) · 6.75 KB
/
Copy pathrepublish-version.yml
File metadata and controls
209 lines (178 loc) · 6.75 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
name: Republish Version
on:
workflow_dispatch:
inputs:
version:
description: 'Version to republish (e.g., 1.2.5)'
required: true
type: string
skip_unpublish:
description: 'Skip unpublish step (if version does not exist on npm)'
required: false
default: false
type: boolean
permissions:
contents: write
id-token: write
jobs:
republish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org
always-auth: true
- name: Verify version matches package.json
run: |
set -euo pipefail
REQUESTED_VERSION="${{ github.event.inputs.version }}"
PACKAGE_VERSION=$(node -p "require('./package.json').version")
if [ "$REQUESTED_VERSION" != "$PACKAGE_VERSION" ]; then
echo "ERROR: Requested version ($REQUESTED_VERSION) does not match package.json ($PACKAGE_VERSION)" >&2
echo "Please update package.json to the version you want to publish" >&2
exit 1
fi
echo "Version verified: $PACKAGE_VERSION"
- name: Unpublish existing version
if: github.event.inputs.skip_unpublish != 'true'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
set -euo pipefail
VERSION="${{ github.event.inputs.version }}"
echo "Checking if version $VERSION exists on npm..."
if npm view opencode-antigravity-auth@$VERSION version >/dev/null 2>&1; then
echo "Version $VERSION exists, unpublishing..."
npm unpublish opencode-antigravity-auth@$VERSION --force
echo "Successfully unpublished version $VERSION"
else
echo "Version $VERSION does not exist on npm, skipping unpublish"
fi
- name: Delete existing git tag
run: |
set -euo pipefail
VERSION="${{ github.event.inputs.version }}"
TAG="v$VERSION"
echo "Checking if tag $TAG exists..."
if git tag -l "$TAG" | grep -q "$TAG"; then
echo "Tag $TAG exists locally, deleting..."
git tag -d "$TAG" || true
fi
if git ls-remote --tags origin | grep -q "refs/tags/$TAG"; then
echo "Tag $TAG exists remotely, deleting..."
git push origin :refs/tags/$TAG || true
fi
echo "Git tag cleanup complete"
- name: Verify NPM token
run: |
if [ -z "${NPM_TOKEN}" ]; then
echo "NPM_TOKEN secret is required" >&2
exit 1
fi
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Install dependencies
run: npm install
- name: Run type check
run: npm run typecheck
- name: Run tests
run: npm test
- name: Build
run: npm run build
- name: Verify build artifacts
run: |
set -euo pipefail
[ -f dist/index.js ] || { echo "dist/index.js missing" >&2; exit 1; }
[ -f dist/index.d.ts ] || { echo "dist/index.d.ts missing" >&2; exit 1; }
[ -d dist/src ] || { echo "dist/src/ missing" >&2; exit 1; }
- name: Publish to npm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
set -euo pipefail
VERSION="${{ github.event.inputs.version }}"
echo "Publishing version $VERSION to npm..."
npm publish --access public --provenance
echo "Successfully published version $VERSION"
echo ""
echo "Updating @latest tag..."
npm dist-tag add opencode-antigravity-auth@$VERSION latest
echo ""
echo "Current dist-tags:"
npm dist-tag ls opencode-antigravity-auth
- name: Create git tag
run: |
VERSION="${{ github.event.inputs.version }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "v$VERSION"
git push origin "v$VERSION"
- name: Generate release notes
id: release_notes
run: |
set -euo pipefail
VERSION="${{ github.event.inputs.version }}"
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$LAST_TAG" ]; then
CHANGELOG=$(git log --no-merges --pretty=format:'- %s (%h)' "${LAST_TAG}..HEAD" | grep -v "\[skip ci\]" || echo "")
COMPARE_URL="https://github.com/${GITHUB_REPOSITORY}/compare/${LAST_TAG}...v${VERSION}"
else
CHANGELOG=$(git log --no-merges --pretty=format:'- %s (%h)' -20 | grep -v "\[skip ci\]" || echo "")
COMPARE_URL=""
fi
if [ -z "$CHANGELOG" ]; then
CHANGELOG="- Release v${VERSION}"
fi
BODY_FILE=$(mktemp)
{
echo "## Release v${VERSION}"
echo ""
if [ -n "$COMPARE_URL" ]; then
echo "Compare changes: $COMPARE_URL"
echo ""
fi
printf "%s\n" "$CHANGELOG"
echo ""
echo "### Install"
echo ""
echo "Update your \`opencode.json\`:"
echo ""
printf '%s\n' '```json'
printf '%s\n' '{'
printf '%s\n' " \"plugins\": [\"opencode-antigravity-auth@${VERSION}\"]"
printf '%s\n' '}'
printf '%s\n' '```'
} >"$BODY_FILE"
{
echo "body<<EOF"
cat "$BODY_FILE"
echo "EOF"
} >>"$GITHUB_OUTPUT"
- name: Create GitHub release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ github.event.inputs.version }}
release_name: v${{ github.event.inputs.version }}
body: ${{ steps.release_notes.outputs.body }}
draft: false
prerelease: false
- name: Summary
run: |
echo "## Version Republished! 🚀" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ github.event.inputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Install:**" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo "npm install opencode-antigravity-auth@${{ github.event.inputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "# or" >> $GITHUB_STEP_SUMMARY
echo "npm install opencode-antigravity-auth@latest" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY