Skip to content

Commit 7d8f33d

Browse files
soodokuclaude
andcommitted
ci: fix the nightly dependency-updates job, untrack outdated.json
Three bugs in one job. 1. `npm outdated --json` prints `{}` when nothing is outdated, and `{}` is 3 bytes, so `[ -s outdated.json ]` was always true and updates_available was effectively hardcoded to true. 2. The job wrote outdated.json into the working tree and then used `git status --porcelain` over the whole tree to decide changes_made, so its own scratch file influenced the answer. 3. Because create-pull-request had no add-paths, that scratch file got swept into the commit. outdated.json is tracked in git today and this workflow has committed it to main five times (#28, #29, #47, ...). Scratch now goes to $RUNNER_TEMP, the {} case is handled, changes_made is scoped to package.json and package-lock.json, and add-paths pins the PR contents to those two files. Also allow workflow_dispatch. Under `if: github.event_name == 'schedule'` this job could not be tested without waiting for 2 AM UTC. `npx --yes` because the log shows npm-check-updates being resolved via an interactive install prompt, and the step is renamed to match what `--target patch` actually does. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent e8bfe90 commit 7d8f33d

3 files changed

Lines changed: 25 additions & 255 deletions

File tree

.github/workflows/security-and-updates.yml

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
dependency-updates:
8989
name: Update Dependencies
9090
runs-on: ubuntu-latest
91-
if: github.event_name == 'schedule'
91+
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
9292

9393
steps:
9494
- name: Checkout code
@@ -105,27 +105,32 @@ jobs:
105105
- name: Check for updates
106106
id: updates
107107
run: |
108-
npm outdated --json > outdated.json || true
109-
if [ -s outdated.json ]; then
110-
echo "updates_available=true" >> $GITHUB_OUTPUT
108+
# Written to RUNNER_TEMP, not the repo, so it can never dirty
109+
# git status or get swept into the PR.
110+
npm outdated --json > "$RUNNER_TEMP/outdated.json" || true
111+
# `npm outdated --json` prints {} when nothing is outdated, so a
112+
# bare -s test is always true.
113+
if [ -s "$RUNNER_TEMP/outdated.json" ] &&
114+
[ "$(tr -d '[:space:]' < "$RUNNER_TEMP/outdated.json")" != '{}' ]; then
115+
echo "updates_available=true" >> "$GITHUB_OUTPUT"
111116
else
112-
echo "updates_available=false" >> $GITHUB_OUTPUT
117+
echo "updates_available=false" >> "$GITHUB_OUTPUT"
113118
fi
114119
115-
- name: Update minor and patch versions
120+
- name: Update patch versions
121+
id: patch_updates
116122
if: steps.updates.outputs.updates_available == 'true'
117123
run: |
118-
# Update patch versions (safe)
119-
npx npm-check-updates -u --target patch
124+
npx --yes npm-check-updates -u --target patch
120125
npm install
121126
122-
# Check if changes were made
123-
if [ -n "$(git status --porcelain)" ]; then
124-
echo "changes_made=true" >> $GITHUB_OUTPUT
127+
# Scoped to the two manifests so changes_made reflects only what
128+
# the PR would actually contain.
129+
if [ -n "$(git status --porcelain -- package.json package-lock.json)" ]; then
130+
echo "changes_made=true" >> "$GITHUB_OUTPUT"
125131
else
126-
echo "changes_made=false" >> $GITHUB_OUTPUT
132+
echo "changes_made=false" >> "$GITHUB_OUTPUT"
127133
fi
128-
id: patch_updates
129134
130135
- name: Run tests after updates
131136
if: steps.patch_updates.outputs.changes_made == 'true'
@@ -161,3 +166,7 @@ jobs:
161166
Please review the changes before merging.
162167
branch: 'automated/dependency-updates'
163168
delete-branch: true
169+
# Hard guarantee the PR contains nothing but the manifests.
170+
add-paths: |
171+
package.json
172+
package-lock.json

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
.DS_Store
2020
*.pem
2121

22+
# CI scratch output
23+
outdated.json
24+
2225
# debug
2326
npm-debug.log*
2427
yarn-debug.log*

outdated.json

Lines changed: 0 additions & 242 deletions
This file was deleted.

0 commit comments

Comments
 (0)