-
Notifications
You must be signed in to change notification settings - Fork 0
215 lines (190 loc) · 7.55 KB
/
Copy pathrelease-switcher.yml
File metadata and controls
215 lines (190 loc) · 7.55 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
name: release-switcher
# Core CLI release only (GoReleaser, R2 CLI, npm) — v* tags or manual dispatch.
# Desktop shell: release-desktop.yml | Landing site: deploy-landing.yml
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
version:
description: "Release version without leading v (for npm only)"
required: false
type: string
permissions:
contents: write
env:
R2_PUBLIC_BASE_URL: https://downloads.clovapi.com
jobs:
goreleaser:
runs-on: ubuntu-latest
defaults:
run:
working-directory: core
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Check existing CLI release
id: existing_cli_release
working-directory: .
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
echo "complete=false" >> "$GITHUB_OUTPUT"
if [[ "${GITHUB_REF_NAME:-}" != v* ]]; then
exit 0
fi
version="${GITHUB_REF_NAME#v}"
required_assets=(
"checksums.txt"
"clovapi_${version}_darwin_amd64.tar.gz"
"clovapi_${version}_darwin_arm64.tar.gz"
"clovapi_${version}_linux_amd64.tar.gz"
"clovapi_${version}_linux_arm64.tar.gz"
"clovapi_${version}_windows_amd64.zip"
"clovapi_${version}_windows_arm64.zip"
)
if ! gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --json assets > /tmp/clovapi-release.json 2>/dev/null; then
exit 0
fi
for asset in "${required_assets[@]}"; do
if ! jq -e --arg name "$asset" '.assets | any(.name == $name)' /tmp/clovapi-release.json >/dev/null; then
exit 0
fi
done
echo "complete=true" >> "$GITHUB_OUTPUT"
echo "Release $GITHUB_REF_NAME already has all CLI assets; skipping GoReleaser publish."
- name: Setup Go
if: steps.existing_cli_release.outputs.complete != 'true'
uses: actions/setup-go@v5
with:
go-version-file: core/go.mod
- name: Run tests
if: steps.existing_cli_release.outputs.complete != 'true'
run: go test ./...
- name: Setup GoReleaser
if: steps.existing_cli_release.outputs.complete != 'true'
uses: goreleaser/goreleaser-action@v6
with:
version: "~> v2"
install-only: true
- name: GoReleaser release
if: steps.existing_cli_release.outputs.complete != 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goreleaser release --clean --config .goreleaser.yaml
- name: Decide R2 publish
id: r2_gate
if: steps.existing_cli_release.outputs.complete != 'true'
working-directory: .
run: |
if [ -n "${{ secrets.R2_ACCOUNT_ID }}" ] && [ -n "${{ secrets.R2_ACCESS_KEY_ID }}" ] && [ -n "${{ secrets.R2_SECRET_ACCESS_KEY }}" ] && [ -n "${{ secrets.R2_BUCKET }}" ]; then
echo "publish=true" >> "$GITHUB_OUTPUT"
else
echo "publish=false" >> "$GITHUB_OUTPUT"
fi
- name: Resolve release tag
id: release_tag
if: ${{ steps.r2_gate.outputs.publish == 'true' }}
working-directory: .
env:
RELEASE_INPUT_VERSION: ${{ github.event.inputs.version }}
run: |
set -euo pipefail
if [[ "${GITHUB_REF_NAME:-}" == v* ]]; then
echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
elif [[ -n "${RELEASE_INPUT_VERSION:-}" ]]; then
echo "tag=v${RELEASE_INPUT_VERSION}" >> "$GITHUB_OUTPUT"
else
echo "tag=" >> "$GITHUB_OUTPUT"
fi
- name: Setup Python
if: ${{ steps.r2_gate.outputs.publish == 'true' && steps.release_tag.outputs.tag != '' }}
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install awscli
if: ${{ steps.r2_gate.outputs.publish == 'true' && steps.release_tag.outputs.tag != '' }}
run: pip install --upgrade awscli
- name: Upload CLI artifacts to Cloudflare R2
if: ${{ steps.r2_gate.outputs.publish == 'true' && steps.release_tag.outputs.tag != '' }}
working-directory: .
env:
R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
R2_SESSION_TOKEN: ${{ secrets.R2_SESSION_TOKEN }}
R2_BUCKET: ${{ secrets.R2_BUCKET }}
R2_ARTIFACT_PREFIX: ${{ secrets.R2_ARTIFACT_PREFIX }}
run: |
set -euo pipefail
chmod +x scripts/r2-publish.sh
./scripts/r2-publish.sh cli --tag "${{ steps.release_tag.outputs.tag }}" --dist core/dist
./scripts/r2-publish.sh install-sh --file landing/public/install.sh
npm:
runs-on: ubuntu-latest
needs: goreleaser
if: ${{ startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch' }}
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Decide npm publish
id: npm_gate
working-directory: .
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
if [ -n "$NPM_TOKEN" ]; then
echo "publish=true" >> "$GITHUB_OUTPUT"
else
echo "publish=false" >> "$GITHUB_OUTPUT"
fi
- name: Setup Node
if: ${{ steps.npm_gate.outputs.publish == 'true' }}
uses: actions/setup-node@v5
with:
node-version: "22"
registry-url: "https://registry.npmjs.org"
- name: Sync package version from tag
if: ${{ steps.npm_gate.outputs.publish == 'true' && startsWith(github.ref, 'refs/tags/v') }}
working-directory: npm
run: |
target_version="${GITHUB_REF_NAME#v}"
current_version="$(node -p "require('./package.json').version")"
if [ "$current_version" != "$target_version" ]; then
npm version "$target_version" --no-git-tag-version
else
echo "package.json version already $target_version, skip npm version"
fi
- name: Sync package version from input
if: ${{ steps.npm_gate.outputs.publish == 'true' && github.event_name == 'workflow_dispatch' && github.event.inputs.version != '' }}
working-directory: npm
run: |
target_version="${{ github.event.inputs.version }}"
current_version="$(node -p "require('./package.json').version")"
if [ "$current_version" != "$target_version" ]; then
npm version "$target_version" --no-git-tag-version
else
echo "package.json version already $target_version, skip npm version"
fi
- name: Check published npm version
id: npm_version
if: ${{ steps.npm_gate.outputs.publish == 'true' }}
working-directory: npm
run: |
version="$(node -p "require('./package.json').version")"
if npm view "@clovapi/cli@${version}" version >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "@clovapi/cli ${version} is already published; skipping npm publish."
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Publish npm package
if: ${{ steps.npm_gate.outputs.publish == 'true' && steps.npm_version.outputs.exists != 'true' }}
working-directory: npm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --access public