forked from MoonshotAI/kimi-code
-
Notifications
You must be signed in to change notification settings - Fork 0
215 lines (193 loc) · 8.02 KB
/
Copy pathrelease.yml
File metadata and controls
215 lines (193 loc) · 8.02 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
on:
push:
branches:
- main
# Fallback only: a GITHUB_TOKEN merge of the version PR does not emit push.
# PAT merges (the usual path) already fire the push event above — do not
# also handle those here or two publishes race.
pull_request:
types: [closed]
branches:
- main
# One publish at a time. Do not cancel an in-flight npm publish.
concurrency:
group: release-${{ github.repository }}
cancel-in-progress: false
jobs:
release:
name: Release
runs-on: ubuntu-latest
if: >
github.repository_owner == 'wangyuling93' &&
(github.event_name == 'push' ||
(github.event_name == 'pull_request' &&
github.event.pull_request.merged == true &&
github.event.pull_request.head.ref == 'changeset-release/main' &&
github.event.pull_request.merged_by.login == 'github-actions[bot]'))
outputs:
packages_published: ${{ steps.changesets.outputs.published }}
kimi_native_release: ${{ steps.kimi-release.outputs.should_publish }}
kimi_release_tag: ${{ steps.kimi-release.outputs.tag }}
permissions:
contents: write
pull-requests: write
id-token: write # Required for NPM Trusted Publishing (OIDC)
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
# On pull_request (closed) events the checkout defaults to the PR
# merge ref; always base the release on main's post-merge state.
ref: main
# checkout's default extraheader uses the job GITHUB_TOKEN and beats
# changesets/action's .netrc PAT, so version-PR updates are pushed
# as github-actions[bot] and CI sits in action_required. Leave
# credentials unset; the action writes .netrc from CHANGESETS_TOKEN.
persist-credentials: false
- name: Detect release mode
id: mode
env:
EVENT_NAME: ${{ github.event_name }}
run: |
set -euo pipefail
has_changesets=false
if find .changeset -maxdepth 1 -name '*.md' ! -name 'README.md' | grep -q .; then
has_changesets=true
fi
is_release_merge=false
subject=$(git log -1 --format=%s)
if [ "$EVENT_NAME" = "pull_request" ]; then
is_release_merge=true
elif [[ "$subject" == *"changeset-release/main"* ]]; then
is_release_merge=true
elif [ "$subject" = "ci: release packages" ]; then
is_release_merge=true
fi
if [ "$has_changesets" = true ]; then
echo "mode=version" >> "$GITHUB_OUTPUT"
elif [ "$is_release_merge" = true ]; then
echo "mode=publish" >> "$GITHUB_OUTPUT"
else
echo "mode=skip" >> "$GITHUB_OUTPUT"
fi
echo "mode has_changesets=$has_changesets is_release_merge=$is_release_merge subject=$subject"
- name: Setup pnpm
if: steps.mode.outputs.mode != 'skip'
uses: pnpm/action-setup@v6
- name: Setup Node.js
if: steps.mode.outputs.mode != 'skip'
uses: actions/setup-node@v6
with:
node-version-file: .nvmrc
cache: "pnpm"
registry-url: "https://registry.npmjs.org"
- name: Upgrade npm for Trusted Publishing
if: steps.mode.outputs.mode == 'publish'
run: npm install -g npm@11
- name: Install dependencies
if: steps.mode.outputs.mode != 'skip'
run: pnpm install --frozen-lockfile
- name: Generate Kimi Code built-in catalog
if: steps.mode.outputs.mode == 'publish'
shell: bash
run: |
CATALOG_FILE="$RUNNER_TEMP/kimi-code-built-in-catalog.json"
node apps/kimi-code/scripts/update-catalog.mjs --out "$CATALOG_FILE"
echo "KIMI_CODE_BUILT_IN_CATALOG_FILE=$CATALOG_FILE" >> "$GITHUB_ENV"
- name: Build packages
if: steps.mode.outputs.mode == 'publish'
run: pnpm build
- name: Create Release Pull Request or Publish to npm
id: changesets
if: steps.mode.outputs.mode != 'skip'
uses: changesets/action@v1
with:
publish: pnpm changeset publish
version: pnpm run version:release
commit: "ci: release packages"
title: "ci: release packages"
commitMode: git-cli
# Use the maintainer's PAT so the version PR is authored by a real
# account: PRs created by github-actions[bot] always require manual
# workflow approval (the bot has no contribution history), which
# stalls the auto-merge loop.
github-token: ${{ secrets.CHANGESETS_TOKEN }}
env:
# Same token as the github-token input: changesets/action refuses a
# mismatch between the two.
GITHUB_TOKEN: ${{ secrets.CHANGESETS_TOKEN }}
# Publishing uses npm OIDC trusted publishing (configured on the
# package page); provenance is generated automatically. No token is
# needed — NPM_TOKEN was only used to bootstrap the first publish.
# id-token: write is granted above.
# Auto-merge the version PR once the required CI checks pass. Uses
# GitHub's native auto-merge (repo setting "Allow auto-merge" +
# branch protection requiring status checks); changesets/action has no
# such input of its own.
- name: Enable auto-merge on the version PR
if: steps.mode.outputs.mode != 'skip' && steps.changesets.outputs.pullRequestNumber != ''
run: gh pr merge --repo "$GITHUB_REPOSITORY" --merge --auto "${{ steps.changesets.outputs.pullRequestNumber }}"
env:
# Auto-merge with the maintainer's PAT: merges performed with the
# GITHUB_TOKEN are attributed to github-actions[bot], whose push /
# closed events do not trigger workflows.
GH_TOKEN: ${{ secrets.CHANGESETS_TOKEN }}
- name: Resolve Kimi Code native release
if: steps.changesets.outputs.published == 'true'
id: kimi-release
run: node apps/kimi-code/scripts/native/resolve-release.mjs
env:
CHANGESETS_PUBLISHED_PACKAGES: ${{ steps.changesets.outputs.publishedPackages }}
deploy-docs:
name: Deploy docs
needs: release
if: needs.release.outputs.packages_published == 'true' && github.repository_owner == 'MoonshotAI'
uses: ./.github/workflows/docs-deploy.yml
permissions:
contents: read
pages: write
id-token: write
native-artifacts:
name: Native release artifact
needs: release
if: needs.release.outputs.kimi_native_release == 'true'
uses: ./.github/workflows/_native-build.yml
with:
upload-artifact-prefix: kimi-code-native
retention-days: 7
sign-macos: true
secrets:
APPLE_CERTIFICATE_P12: ${{ secrets.APPLE_CERTIFICATE_P12 }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
APPLE_NOTARIZATION_KEY_P8: ${{ secrets.APPLE_NOTARIZATION_KEY_P8 }}
APPLE_NOTARIZATION_KEY_ID: ${{ secrets.APPLE_NOTARIZATION_KEY_ID }}
APPLE_NOTARIZATION_ISSUER_ID: ${{ secrets.APPLE_NOTARIZATION_ISSUER_ID }}
publish-native-assets:
name: Publish native release assets
needs:
- release
- native-artifacts
if: needs.release.outputs.kimi_native_release == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Download native artifacts
uses: actions/download-artifact@v8
with:
pattern: kimi-code-native-*
path: dist-native-release
merge-multiple: true
- name: Produce manifest.json
env:
RELEASE_TAG: ${{ needs.release.outputs.kimi_release_tag }}
run: node apps/kimi-code/scripts/native/produce-manifest.mjs dist-native-release "$RELEASE_TAG"
- name: Upload assets to GitHub Release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ needs.release.outputs.kimi_release_tag }}
run: gh release upload "$RELEASE_TAG" dist-native-release/* --clobber