-
Notifications
You must be signed in to change notification settings - Fork 0
202 lines (183 loc) · 7.5 KB
/
release.yml
File metadata and controls
202 lines (183 loc) · 7.5 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
name: release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "Tag name to release (e.g. v1.2.3). If empty, skip release/publish steps."
required: false
type: string
npm_only:
description: "Only publish to npm (skip GitHub Packages)"
required: false
type: boolean
default: false
skip_github_release:
description: "Skip GitHub Release creation (useful for npm retry)"
required: false
type: boolean
default: false
permissions:
contents: write
packages: write
id-token: write
jobs:
build-and-publish:
runs-on: ubuntu-latest
env:
RELEASE_TAG: ${{ github.ref_type == 'tag' && github.ref_name || inputs.tag }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout input tag
if: ${{ inputs.tag != '' && github.ref_type != 'tag' }}
run: git checkout "${{ inputs.tag }}"
- name: Setup Node (build/test)
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "npm"
cache-dependency-path: package-lock.json
- name: Install
run: npm ci
- name: Build
run: npm run build
- name: Test
run: npm test
- name: Sync version from Tag
if: ${{ env.RELEASE_TAG != '' }}
run: |
VERSION=${RELEASE_TAG#v}
echo "Syncing version to $VERSION"
npm version $VERSION --no-git-tag-version --allow-same-version
- name: Pack
id: pack
run: |
TARBALL="$(npm pack --silent)"
echo "tarball=$TARBALL" >> "$GITHUB_OUTPUT"
# Check if GitHub Release already exists
- name: Check existing GitHub Release
if: ${{ env.RELEASE_TAG != '' }}
id: check_release
run: |
if gh release view "${{ env.RELEASE_TAG }}" &>/dev/null; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "::notice::GitHub Release ${{ env.RELEASE_TAG }} already exists, skipping creation"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Tarball Artifact
uses: actions/upload-artifact@v4
with:
name: npm-tarball
path: ${{ steps.pack.outputs.tarball }}
overwrite: true
- name: Create GitHub Release (attach tarball)
if: ${{ env.RELEASE_TAG != '' && steps.check_release.outputs.exists != 'true' && inputs.skip_github_release != true }}
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.RELEASE_TAG }}
files: ${{ steps.pack.outputs.tarball }}
generate_release_notes: true
- name: Setup Node (GitHub Packages)
if: ${{ env.RELEASE_TAG != '' && inputs.npm_only != true }}
uses: actions/setup-node@v4
with:
node-version: "22"
registry-url: "https://npm.pkg.github.com"
scope: "@${{ github.repository_owner }}"
- name: Publish to GitHub Packages
if: ${{ env.RELEASE_TAG != '' && inputs.npm_only != true }}
continue-on-error: true
id: publish_github
run: |
npm pkg set name="@${{ github.repository_owner }}/git-ai"
npm publish --access public 2>&1 | tee publish_output.txt || true
if grep -q "You cannot publish over the previously published versions" publish_output.txt; then
echo "::notice::Version already exists on GitHub Packages, skipping"
echo "skipped=true" >> "$GITHUB_OUTPUT"
elif grep -q "Cannot publish over existing version" publish_output.txt; then
echo "::notice::Version already exists on GitHub Packages (E409), skipping"
echo "skipped=true" >> "$GITHUB_OUTPUT"
elif grep -q "^\+ @${{ github.repository_owner }}/git-ai@" publish_output.txt; then
echo "::notice::Successfully published to GitHub Packages"
echo "skipped=false" >> "$GITHUB_OUTPUT"
elif grep -q "npm error 40[13]" publish_output.txt; then
echo "::warning::GitHub Packages publish failed with auth error, continuing to npmjs.org"
echo "skipped=true" >> "$GITHUB_OUTPUT"
else
echo "::error::Failed to publish to GitHub Packages"
cat publish_output.txt
exit 1
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Restore package name for npmjs
if: ${{ env.RELEASE_TAG != '' }}
run: |
npm pkg set name="@mars167/git-ai"
- name: Setup Node (npmjs.org)
if: ${{ env.RELEASE_TAG != '' }}
uses: actions/setup-node@v4
with:
node-version: "22"
registry-url: "https://registry.npmjs.org"
scope: "@mars167"
- name: Publish to npmjs.org
if: ${{ env.RELEASE_TAG != '' }}
id: publish_npm
run: |
npm publish --access public --provenance 2>&1 | tee publish_output.txt || true
if grep -q "You cannot publish over the previously published versions" publish_output.txt; then
echo "::notice::Version already exists on npmjs.org, skipping"
echo "skipped=true" >> "$GITHUB_OUTPUT"
elif grep -q "^\+ @mars167/git-ai@" publish_output.txt; then
echo "::notice::Successfully published to npmjs.org"
echo "skipped=false" >> "$GITHUB_OUTPUT"
elif grep -q "npm error" publish_output.txt; then
echo "::error::Failed to publish to npmjs.org"
cat publish_output.txt
exit 1
else
echo "::warning::Unexpected npm publish output, check logs"
cat publish_output.txt
echo "skipped=false" >> "$GITHUB_OUTPUT"
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish Summary
if: ${{ env.RELEASE_TAG != '' }}
run: |
echo "## Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ env.RELEASE_TAG }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### GitHub Release:" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.check_release.outputs.exists }}" == "true" ] || [ "${{ inputs.skip_github_release }}" == "true" ]; then
echo "- [x] Already exists (skipped)" >> $GITHUB_STEP_SUMMARY
else
echo "- [x] Created" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Published to:" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.publish_github.outputs.skipped }}" == "true" ]; then
echo "- [x] GitHub Packages: \`@${{ github.repository_owner }}/git-ai\` (already exists)" >> $GITHUB_STEP_SUMMARY
else
echo "- [x] GitHub Packages: \`@${{ github.repository_owner }}/git-ai\`" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ steps.publish_npm.outputs.skipped }}" == "true" ]; then
echo "- [x] npmjs.org: \`@mars167/git-ai\` (already exists)" >> $GITHUB_STEP_SUMMARY
else
echo "- [x] npmjs.org: \`@mars167/git-ai\`" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Install:" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "npm install -g @mars167/git-ai" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY