mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-07-09 17:29:12 +00:00
chore(flake): simplify nix build and add ci validation (#257)
* chore(flake): simplify nix build and add ci validation - Replace dynamic pnpm-workspace.yaml parsing with hardcoded workspacePaths and workspaceNames to reduce format assumptions - Remove update-pnpm-deps script and kimi-code-pnpm-deps package; use lib.fakeHash for standard hash mismatch workflow - Remove nodejs_latest fallback in nodejsFor, hardcode to nodejs_24 - Add nix-build CI workflow that posts hash-mismatch details to PR comments - Remove unused Nix installation step from release.yml - Add workspace maintenance note to AGENTS.md
This commit is contained in:
parent
ee69d0ac29
commit
817ad1fe9a
9 changed files with 492 additions and 490 deletions
190
.github/workflows/nix-build.yml
vendored
Normal file
190
.github/workflows/nix-build.yml
vendored
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
name: Nix Build
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
check-workspace-sync:
|
||||
name: Check flake.nix workspace sync
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Check workspace sync
|
||||
id: check
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if node scripts/check-nix-workspace.mjs; then
|
||||
echo "SYNC_OK=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "SYNC_OK=false" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Extract missing items
|
||||
if: steps.check.outputs.SYNC_OK == 'false' && github.event_name == 'pull_request'
|
||||
id: missing
|
||||
run: |
|
||||
{
|
||||
echo "body<<EOF"
|
||||
echo "<!-- nix-workspace-sync-bot -->"
|
||||
echo "❌ flake.nix workspace lists out of sync"
|
||||
echo ""
|
||||
echo "The recursive workspace dependencies of \`apps/kimi-code\` do not match \`flake.nix\`. Please run \`node scripts/check-nix-workspace.mjs\` locally for details."
|
||||
echo ""
|
||||
echo "Typical fix: add the missing package name to \`workspaceNames\` and its path to \`workspacePaths\` in \`flake.nix\`."
|
||||
echo "EOF"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Post or update PR comment
|
||||
if: steps.check.outputs.SYNC_OK == 'false' && github.event_name == 'pull_request'
|
||||
uses: actions/github-script@v7
|
||||
env:
|
||||
COMMENT_BODY: ${{ steps.missing.outputs.body }}
|
||||
with:
|
||||
script: |
|
||||
const marker = '<!-- nix-workspace-sync-bot -->';
|
||||
const body = process.env.COMMENT_BODY;
|
||||
|
||||
const { data: comments } = await github.rest.issues.listComments({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.issue.number,
|
||||
});
|
||||
|
||||
const existing = comments.find(c =>
|
||||
c.user.login === 'github-actions[bot]' && c.body.includes(marker)
|
||||
);
|
||||
|
||||
if (existing) {
|
||||
await github.rest.issues.updateComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
comment_id: existing.id,
|
||||
body,
|
||||
});
|
||||
} else {
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.issue.number,
|
||||
body,
|
||||
});
|
||||
}
|
||||
|
||||
- name: Fail if workspace sync failed
|
||||
if: steps.check.outputs.SYNC_OK == 'false'
|
||||
run: exit 1
|
||||
|
||||
nix-build:
|
||||
name: nix build .#kimi-code
|
||||
needs: check-workspace-sync
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Install Nix
|
||||
uses: cachix/install-nix-action@v31
|
||||
with:
|
||||
nix-path: nixpkgs=channel:nixos-unstable
|
||||
|
||||
- name: Build
|
||||
id: build
|
||||
run: |
|
||||
set -euo pipefail
|
||||
LOG_FILE="$(mktemp)"
|
||||
if nix build .#kimi-code --print-build-logs 2>&1 | tee "$LOG_FILE"; then
|
||||
echo "BUILD_FAILED=false" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "BUILD_FAILED=true" >> "$GITHUB_OUTPUT"
|
||||
echo "LOG_FILE=$LOG_FILE" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Extract error log
|
||||
if: steps.build.outputs.BUILD_FAILED == 'true' && github.event_name == 'pull_request'
|
||||
id: error
|
||||
run: |
|
||||
LOG_FILE="${{ steps.build.outputs.LOG_FILE }}"
|
||||
|
||||
# Extract hash mismatch info
|
||||
SPECIFIED=$(grep -oP 'specified:\s+\K\S+' "$LOG_FILE" || true)
|
||||
GOT=$(grep -oP 'got:\s+\K\S+' "$LOG_FILE" || true)
|
||||
|
||||
if [ -n "$SPECIFIED" ] && [ -n "$GOT" ]; then
|
||||
{
|
||||
echo "body<<EOF"
|
||||
echo "❌ Nix build failed"
|
||||
echo ""
|
||||
echo "Hash mismatch in \`pnpmDeps\`:"
|
||||
echo "| | Hash |"
|
||||
echo "|---|---|"
|
||||
echo "| **specified** | \`$SPECIFIED\` |"
|
||||
echo "| **got** | \`$GOT\` |"
|
||||
echo ""
|
||||
echo "Please update \`flake.nix\` with the **got** hash."
|
||||
echo "EOF"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
TAIL=$(tail -n 80 "$LOG_FILE" | sed 's/^/ /')
|
||||
{
|
||||
echo "body<<EOF"
|
||||
echo "❌ Nix build failed"
|
||||
echo ""
|
||||
echo "\`\`\`"
|
||||
echo "$TAIL"
|
||||
echo "\`\`\`"
|
||||
echo "EOF"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Post or update PR comment
|
||||
if: steps.build.outputs.BUILD_FAILED == 'true' && github.event_name == 'pull_request'
|
||||
uses: actions/github-script@v7
|
||||
env:
|
||||
COMMENT_BODY: ${{ steps.error.outputs.body }}
|
||||
with:
|
||||
script: |
|
||||
const marker = '<!-- nix-build-bot -->';
|
||||
const body = marker + '\n' + process.env.COMMENT_BODY;
|
||||
|
||||
const { data: comments } = await github.rest.issues.listComments({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.issue.number,
|
||||
});
|
||||
|
||||
const existing = comments.find(c =>
|
||||
c.user.login === 'github-actions[bot]' && c.body.includes(marker)
|
||||
);
|
||||
|
||||
if (existing) {
|
||||
await github.rest.issues.updateComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
comment_id: existing.id,
|
||||
body,
|
||||
});
|
||||
} else {
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.issue.number,
|
||||
body,
|
||||
});
|
||||
}
|
||||
|
||||
- name: Fail the job if build failed
|
||||
if: steps.build.outputs.BUILD_FAILED == 'true'
|
||||
run: exit 1
|
||||
15
.github/workflows/release.yml
vendored
15
.github/workflows/release.yml
vendored
|
|
@ -18,7 +18,7 @@ jobs:
|
|||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
id-token: write # Required for NPM Trusted Publishing (OIDC)
|
||||
id-token: write # Required for NPM Trusted Publishing (OIDC)
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
|
|
@ -28,17 +28,12 @@ jobs:
|
|||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v6
|
||||
|
||||
# Nix must be installed before setup-node so that setup-node's PATH
|
||||
# entry (Node >= 24) is prepended after Nix's, keeping Node 24 first.
|
||||
- name: Install Nix
|
||||
uses: DeterminateSystems/nix-installer-action@main
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
cache: 'pnpm'
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
cache: "pnpm"
|
||||
registry-url: "https://registry.npmjs.org"
|
||||
|
||||
- name: Upgrade npm for Trusted Publishing
|
||||
run: npm install -g npm@latest
|
||||
|
|
@ -62,8 +57,8 @@ jobs:
|
|||
with:
|
||||
publish: pnpm changeset publish
|
||||
version: pnpm run version:release
|
||||
commit: 'ci: release packages'
|
||||
title: 'ci: release packages'
|
||||
commit: "ci: release packages"
|
||||
title: "ci: release packages"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# NPM_TOKEN is not needed with Trusted Publishing (OIDC)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue