Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion .github/workflows/update-claude-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
# Run daily at 6 AM UTC
- cron: '0 6 * * *'
workflow_dispatch: # Allow manual trigger
pull_request:
paths:
- 'nix/claude-code/**'
- '.github/workflows/update-claude-code.yml'

jobs:
update:
Expand All @@ -24,7 +28,21 @@ jobs:
extra_nix_config: |
experimental-features = nix-command flakes

- name: Update claude-code package
- name: Update claude-code package (test)
if: github.event_name == 'pull_request'
run: |
# On PRs, run the update script to test it works
# but don't commit or create PRs with the changes
set +e
./nix/claude-code/update.sh
status=$?
if [ "$status" -ne 0 ]; then
echo "::warning::Update script execution test failed (exit code: $status)"
exit "$status"
fi

- name: Update claude-code package (production)
if: github.event_name != 'pull_request'
id: update
run: |
# Script exits 0 if already at latest (no changes to commit)
Expand All @@ -35,12 +53,14 @@ jobs:
echo "version=$VERSION" >> $GITHUB_OUTPUT

- name: Update flake.lock
if: github.event_name != 'pull_request'
run: nix flake update

- name: Verify build
run: nix develop --command claude --version

- name: Create Pull Request
if: github.event_name != 'pull_request'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
26 changes: 23 additions & 3 deletions nix/claude-code/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,32 @@ mkdir -p "$TMPDIR/src"
tar -xzf "$TMPDIR/claude-code.tgz" -C "$TMPDIR/src" --strip-components=1
SRC_HASH=$(nix hash path "$TMPDIR/src")

# Get package-lock.json from tarball
# Get package-lock.json from tarball, or generate it if not present
if [[ -f "$TMPDIR/src/package-lock.json" ]]; then
cp "$TMPDIR/src/package-lock.json" package-lock.json
else
echo "Error: No package-lock.json in tarball"
exit 1
echo "No package-lock.json in tarball, generating from package.json"
# Verify package.json exists
if [[ ! -f "$TMPDIR/src/package.json" ]]; then
echo "Error: No package.json in tarball"
exit 1
fi
# Generate package-lock.json from package.json
cp "$TMPDIR/src/package.json" "$TMPDIR/package.json"
# Preserve any npm configuration from the tarball when generating the lockfile
if [[ -f "$TMPDIR/src/.npmrc" ]]; then
cp "$TMPDIR/src/.npmrc" "$TMPDIR/.npmrc"
fi
(cd "$TMPDIR" && npm install --package-lock-only --ignore-scripts) || {
echo "Error: Failed to generate package-lock.json"
exit 1
}
# Verify package-lock.json was generated
if [[ ! -f "$TMPDIR/package-lock.json" ]]; then
echo "Error: package-lock.json was not generated"
exit 1
fi
cp "$TMPDIR/package-lock.json" package-lock.json
fi

# Compute npmDepsHash using prefetch-npm-deps
Expand Down
Loading