44 push :
55 branches :
66 - main
7- # The version PR is merged via auto-merge, which does not emit a push event;
8- # fire the release from the merge's pull_request closed event instead.
7+ # Fallback only: a GITHUB_TOKEN merge of the version PR does not emit push.
8+ # PAT merges (the usual path) already fire the push event above — do not
9+ # also handle those here or two publishes race.
910 pull_request :
1011 types : [closed]
1112 branches :
1213 - main
1314
14- concurrency : ${{ github.workflow }}-${{ github.ref }}
15+ # One publish at a time. Do not cancel an in-flight npm publish.
16+ concurrency :
17+ group : release-${{ github.repository }}
18+ cancel-in-progress : false
1519
1620jobs :
1721 release :
2226 (github.event_name == 'push' ||
2327 (github.event_name == 'pull_request' &&
2428 github.event.pull_request.merged == true &&
25- github.event.pull_request.head.ref == 'changeset-release/main'))
29+ github.event.pull_request.head.ref == 'changeset-release/main' &&
30+ github.event.pull_request.merged_by.login == 'github-actions[bot]'))
2631 outputs :
2732 packages_published : ${{ steps.changesets.outputs.published }}
2833 kimi_native_release : ${{ steps.kimi-release.outputs.should_publish }}
@@ -39,41 +44,84 @@ jobs:
3944 # On pull_request (closed) events the checkout defaults to the PR
4045 # merge ref; always base the release on main's post-merge state.
4146 ref : main
47+ # checkout's default extraheader uses the job GITHUB_TOKEN and beats
48+ # changesets/action's .netrc PAT, so version-PR updates are pushed
49+ # as github-actions[bot] and CI sits in action_required. Leave
50+ # credentials unset; the action writes .netrc from CHANGESETS_TOKEN.
51+ persist-credentials : false
52+
53+ - name : Detect release mode
54+ id : mode
55+ env :
56+ EVENT_NAME : ${{ github.event_name }}
57+ run : |
58+ set -euo pipefail
59+ has_changesets=false
60+ if find .changeset -maxdepth 1 -name '*.md' ! -name 'README.md' | grep -q .; then
61+ has_changesets=true
62+ fi
63+
64+ is_release_merge=false
65+ subject=$(git log -1 --format=%s)
66+ if [ "$EVENT_NAME" = "pull_request" ]; then
67+ is_release_merge=true
68+ elif [[ "$subject" == *"changeset-release/main"* ]]; then
69+ is_release_merge=true
70+ elif [ "$subject" = "ci: release packages" ]; then
71+ is_release_merge=true
72+ fi
73+
74+ if [ "$has_changesets" = true ]; then
75+ echo "mode=version" >> "$GITHUB_OUTPUT"
76+ elif [ "$is_release_merge" = true ]; then
77+ echo "mode=publish" >> "$GITHUB_OUTPUT"
78+ else
79+ echo "mode=skip" >> "$GITHUB_OUTPUT"
80+ fi
81+ echo "mode has_changesets=$has_changesets is_release_merge=$is_release_merge subject=$subject"
4282
4383 - name : Setup pnpm
84+ if : steps.mode.outputs.mode != 'skip'
4485 uses : pnpm/action-setup@v6
4586
4687 - name : Setup Node.js
88+ if : steps.mode.outputs.mode != 'skip'
4789 uses : actions/setup-node@v6
4890 with :
4991 node-version-file : .nvmrc
5092 cache : " pnpm"
5193 registry-url : " https://registry.npmjs.org"
5294
5395 - name : Upgrade npm for Trusted Publishing
96+ if : steps.mode.outputs.mode == 'publish'
5497 run : npm install -g npm@11
5598
5699 - name : Install dependencies
100+ if : steps.mode.outputs.mode != 'skip'
57101 run : pnpm install --frozen-lockfile
58102
59103 - name : Generate Kimi Code built-in catalog
104+ if : steps.mode.outputs.mode == 'publish'
60105 shell : bash
61106 run : |
62107 CATALOG_FILE="$RUNNER_TEMP/kimi-code-built-in-catalog.json"
63108 node apps/kimi-code/scripts/update-catalog.mjs --out "$CATALOG_FILE"
64109 echo "KIMI_CODE_BUILT_IN_CATALOG_FILE=$CATALOG_FILE" >> "$GITHUB_ENV"
65110
66111 - name : Build packages
112+ if : steps.mode.outputs.mode == 'publish'
67113 run : pnpm build
68114
69115 - name : Create Release Pull Request or Publish to npm
70116 id : changesets
117+ if : steps.mode.outputs.mode != 'skip'
71118 uses : changesets/action@v1
72119 with :
73120 publish : pnpm changeset publish
74121 version : pnpm run version:release
75122 commit : " ci: release packages"
76123 title : " ci: release packages"
124+ commitMode : git-cli
77125 # Use the maintainer's PAT so the version PR is authored by a real
78126 # account: PRs created by github-actions[bot] always require manual
79127 # workflow approval (the bot has no contribution history), which
93141 # branch protection requiring status checks); changesets/action has no
94142 # such input of its own.
95143 - name : Enable auto-merge on the version PR
96- if : steps.changesets.outputs.pullRequestNumber != ''
144+ if : steps.mode.outputs.mode != 'skip' && steps. changesets.outputs.pullRequestNumber != ''
97145 run : gh pr merge --repo "$GITHUB_REPOSITORY" --merge --auto "${{ steps.changesets.outputs.pullRequestNumber }}"
98146 env :
99147 # Auto-merge with the maintainer's PAT: merges performed with the
0 commit comments