-
Notifications
You must be signed in to change notification settings - Fork 0
279 lines (254 loc) · 11.4 KB
/
Copy pathcli-release.yml
File metadata and controls
279 lines (254 loc) · 11.4 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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
name: CLI Release
on:
schedule:
- cron: '5,20,35,50 * * * *'
workflow_dispatch:
inputs:
version:
description: 'Version tag to release, e.g. v1.2.3'
required: false
default: ''
type: string
concurrency:
group: cli-release-${{ inputs.version || github.run_id }}
cancel-in-progress: false
permissions:
contents: write
env:
SOURCE_REPO: ${{ vars.SOURCE_REPO || 'officecli/officecli-internal' }}
SOURCE_DEFAULT_BRANCH: main
jobs:
preflight:
name: Resolve Optional Secret Gates
runs-on: ubuntu-latest
outputs:
ready: ${{ steps.flags.outputs.ready }}
missing: ${{ steps.flags.outputs.missing }}
steps:
- name: Resolve flags
id: flags
env:
PUBLIC_DIST_REPO_TOKEN: ${{ secrets.PUBLIC_DIST_REPO_TOKEN || '' }}
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN || '' }}
PLATFORM_LICENSE_PROOF_SEED: ${{ secrets.PLATFORM_LICENSE_PROOF_SEED || '' }}
CLI_EMBEDDED_PUBLISH_AUTH_KEY: ${{ secrets.CLI_EMBEDDED_PUBLISH_AUTH_KEY || '' }}
run: |
missing=()
if [ -z "${PUBLIC_DIST_REPO_TOKEN}" ]; then
missing+=("PUBLIC_DIST_REPO_TOKEN")
fi
if [ -z "${HOMEBREW_TAP_TOKEN}" ]; then
missing+=("HOMEBREW_TAP_TOKEN")
fi
if [ -z "${PLATFORM_LICENSE_PROOF_SEED}" ]; then
missing+=("PLATFORM_LICENSE_PROOF_SEED")
fi
if [ -z "${CLI_EMBEDDED_PUBLISH_AUTH_KEY}" ]; then
missing+=("CLI_EMBEDDED_PUBLISH_AUTH_KEY")
fi
ready=true
if [ "${#missing[@]}" -gt 0 ]; then
ready=false
fi
echo "ready=${ready}" >> "$GITHUB_OUTPUT"
echo "missing=$(IFS=', '; echo "${missing[*]}")" >> "$GITHUB_OUTPUT"
- name: Append preflight summary
run: |
if [ "${{ steps.flags.outputs.ready }}" = "true" ]; then
echo "CLI Release prerequisites are configured." >> "$GITHUB_STEP_SUMMARY"
else
echo "CLI Release skipped because required configuration is missing: ${{ steps.flags.outputs.missing }}" >> "$GITHUB_STEP_SUMMARY"
fi
release:
name: Build And Publish Public Assets
needs:
- preflight
if: ${{ needs.preflight.outputs.ready == 'true' }}
runs-on: ubuntu-latest
env:
PUBLIC_DIST_REPO_OWNER: ${{ vars.PUBLIC_DIST_REPO_OWNER || 'officecli' }}
PUBLIC_DIST_REPO_NAME: ${{ vars.PUBLIC_DIST_REPO_NAME || 'officecli-dist' }}
PUBLIC_DIST_REPO: ${{ vars.PUBLIC_DIST_REPO || 'officecli/officecli-dist' }}
PUBLIC_DIST_DEFAULT_BRANCH: ${{ vars.PUBLIC_DIST_DEFAULT_BRANCH || 'main' }}
HOMEBREW_TAP_REPO: ${{ vars.HOMEBREW_TAP_REPO || 'officecli/homebrew-officecli' }}
HOMEBREW_TAP_DEFAULT_BRANCH: ${{ vars.HOMEBREW_TAP_DEFAULT_BRANCH || 'main' }}
CLI_EMBEDDED_PUBLISH_BASE_URL: ${{ vars.CLI_EMBEDDED_PUBLISH_BASE_URL || 'https://platform.officecli.io' }}
CLI_EMBEDDED_PUBLISH_AUTH_KEY_ID: ${{ vars.CLI_EMBEDDED_PUBLISH_AUTH_KEY_ID || 'officecli-cli' }}
steps:
- name: Checkout public CI repo
uses: actions/checkout@v6.0.2
- name: Checkout private source repo
uses: actions/checkout@v6.0.2
with:
repository: ${{ env.SOURCE_REPO }}
token: ${{ secrets.SOURCE_REPO_TOKEN }}
ref: ${{ env.SOURCE_DEFAULT_BRANCH }}
path: source
fetch-depth: 0
persist-credentials: false
- name: Resolve target release tag
id: target
shell: bash
env:
SOURCE_REPO_TOKEN: ${{ secrets.SOURCE_REPO_TOKEN }}
run: |
set -euo pipefail
git -C source remote set-url origin "https://x-access-token:${SOURCE_REPO_TOKEN}@github.com/${SOURCE_REPO}.git"
git -C source fetch --tags --force
release_tag=""
if [ -n "${{ inputs.version }}" ]; then
release_tag="${{ inputs.version }}"
if [[ "${release_tag}" != v* ]]; then
release_tag="v${release_tag}"
fi
git -C source rev-parse "${release_tag}^{commit}" >/dev/null 2>&1
else
state_file="${GITHUB_WORKSPACE}/.state/cli-release-tags.txt"
touch "${state_file}"
while IFS= read -r candidate; do
[ -z "${candidate}" ] && continue
if grep -Fxq "${candidate}" "${state_file}"; then
continue
fi
release_tag="${candidate}"
break
done < <(git -C source tag --list 'v*' --sort=-creatordate | rg -v -- '-prod-')
fi
should_run=false
if [ -n "${release_tag}" ]; then
should_run=true
fi
echo "release_tag=${release_tag}" >> "$GITHUB_OUTPUT"
echo "should_run=${should_run}" >> "$GITHUB_OUTPUT"
- name: Stop when no unprocessed release tag exists
if: steps.target.outputs.should_run != 'true'
run: echo "No unprocessed CLI release tag detected."
- name: Prepare release tooling outside source tree
if: steps.target.outputs.should_run == 'true'
shell: bash
run: |
set -euo pipefail
mkdir -p "$RUNNER_TEMP/release-tooling/scripts"
git -C source show "origin/${SOURCE_DEFAULT_BRANCH}:.goreleaser.dist.yml" > "$RUNNER_TEMP/release-tooling/.goreleaser.dist.yml"
git -C source show "origin/${SOURCE_DEFAULT_BRANCH}:scripts/install-officecli.sh" > "$RUNNER_TEMP/release-tooling/scripts/install-officecli.sh"
git -C source show "origin/${SOURCE_DEFAULT_BRANCH}:scripts/sync-public-dist-repo.sh" > "$RUNNER_TEMP/release-tooling/scripts/sync-public-dist-repo.sh"
git -C source show "origin/${SOURCE_DEFAULT_BRANCH}:scripts/sync-homebrew-tap.sh" > "$RUNNER_TEMP/release-tooling/scripts/sync-homebrew-tap.sh"
chmod +x "$RUNNER_TEMP/release-tooling/scripts/install-officecli.sh" \
"$RUNNER_TEMP/release-tooling/scripts/sync-public-dist-repo.sh" \
"$RUNNER_TEMP/release-tooling/scripts/sync-homebrew-tap.sh"
- name: Checkout target release tag
if: steps.target.outputs.should_run == 'true'
shell: bash
run: |
set -euo pipefail
git -C source checkout --detach "${{ steps.target.outputs.release_tag }}"
- name: Setup Go
if: steps.target.outputs.should_run == 'true'
uses: actions/setup-go@v6.4.0
with:
go-version-file: source/go.mod
cache-dependency-path: source/go.mod
- name: Setup Node
if: steps.target.outputs.should_run == 'true'
uses: actions/setup-node@v6.3.0
with:
node-version: '22'
- name: Run tests
if: steps.target.outputs.should_run == 'true'
working-directory: source
run: go test ./...
- name: Setup GoReleaser
if: steps.target.outputs.should_run == 'true'
uses: goreleaser/goreleaser-action@v7.0.0
with:
version: latest
install-only: true
- name: Derive embedded license proof public key
if: steps.target.outputs.should_run == 'true'
working-directory: source
env:
PLATFORM_LICENSE_PROOF_SEED: ${{ secrets.PLATFORM_LICENSE_PROOF_SEED }}
run: |
set -euo pipefail
cat > "$RUNNER_TEMP/derive_license_proof_public_key.go" <<'EOF'
package main
import (
"crypto/ed25519"
"encoding/base64"
"fmt"
"os"
"strings"
)
func main() {
seedValue := strings.TrimSpace(os.Getenv("PLATFORM_LICENSE_PROOF_SEED"))
if seedValue == "" {
panic("missing PLATFORM_LICENSE_PROOF_SEED")
}
seed, err := base64.RawURLEncoding.DecodeString(seedValue)
if err != nil {
panic(err)
}
privateKey := ed25519.NewKeyFromSeed(seed)
fmt.Println(base64.RawURLEncoding.EncodeToString(privateKey.Public().(ed25519.PublicKey)))
}
EOF
cli_license_proof_public_key="$(go run "$RUNNER_TEMP/derive_license_proof_public_key.go")"
echo "CLI_LICENSE_PROOF_PUBLIC_KEY=${cli_license_proof_public_key}" >> "$GITHUB_ENV"
- name: Verify npm wrapper version matches release tag
if: steps.target.outputs.should_run == 'true'
working-directory: source/packages/npm/officecli
env:
RELEASE_TAG: ${{ steps.target.outputs.release_tag }}
run: npm run check:release-version
- name: Delete existing public dist release for reruns
if: steps.target.outputs.should_run == 'true'
env:
GH_TOKEN: ${{ secrets.PUBLIC_DIST_REPO_TOKEN }}
run: |
gh release delete "${{ steps.target.outputs.release_tag }}" -R "${PUBLIC_DIST_REPO}" --yes --cleanup-tag || true
git push "https://x-access-token:${GH_TOKEN}@github.com/${PUBLIC_DIST_REPO}.git" "refs/tags/${{ steps.target.outputs.release_tag }}" || true
- name: Publish binaries to public dist repository
if: steps.target.outputs.should_run == 'true'
working-directory: source
env:
GITHUB_TOKEN: ${{ secrets.PUBLIC_DIST_REPO_TOKEN }}
GORELEASER_CURRENT_TAG: ${{ steps.target.outputs.release_tag }}
CLI_EMBEDDED_PUBLISH_AUTH_KEY: ${{ secrets.CLI_EMBEDDED_PUBLISH_AUTH_KEY }}
CLI_EMBEDDED_PUBLISH_BASE_URL: ${{ env.CLI_EMBEDDED_PUBLISH_BASE_URL }}
CLI_EMBEDDED_PUBLISH_AUTH_KEY_ID: ${{ env.CLI_EMBEDDED_PUBLISH_AUTH_KEY_ID }}
run: goreleaser release --clean --config "$RUNNER_TEMP/release-tooling/.goreleaser.dist.yml"
- name: Sync public dist repository docs and install script
if: steps.target.outputs.should_run == 'true'
working-directory: source
env:
GH_TOKEN: ${{ secrets.PUBLIC_DIST_REPO_TOKEN }}
DIST_REPO: ${{ env.PUBLIC_DIST_REPO }}
DIST_DEFAULT_BRANCH: ${{ env.PUBLIC_DIST_DEFAULT_BRANCH }}
HOMEBREW_TAP_REPO: ${{ env.HOMEBREW_TAP_REPO }}
run: bash "$RUNNER_TEMP/release-tooling/scripts/sync-public-dist-repo.sh"
- name: Sync Homebrew tap formula
if: steps.target.outputs.should_run == 'true'
env:
GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
TAP_REPO: ${{ env.HOMEBREW_TAP_REPO }}
TAP_DEFAULT_BRANCH: ${{ env.HOMEBREW_TAP_DEFAULT_BRANCH }}
DIST_REPO: ${{ env.PUBLIC_DIST_REPO }}
VERSION: ${{ steps.target.outputs.release_tag }}
run: bash "$RUNNER_TEMP/release-tooling/scripts/sync-homebrew-tap.sh"
- name: Persist processed CLI release tag
if: success() && steps.target.outputs.should_run == 'true'
shell: bash
run: |
set -euo pipefail
git fetch origin main
git checkout -B main origin/main
touch .state/cli-release-tags.txt
if ! grep -Fxq "${{ steps.target.outputs.release_tag }}" .state/cli-release-tags.txt; then
printf '%s\n' "${{ steps.target.outputs.release_tag }}" >> .state/cli-release-tags.txt
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .state/cli-release-tags.txt
git diff --cached --quiet && exit 0
git commit -m "ci: track CLI release ${{ steps.target.outputs.release_tag }} [skip ci]"
git push origin HEAD:main