Skip to content

Prevent scheduled app-test workflow rebase failures from lockfile drift - #196

Merged
shazron merged 4 commits into
masterfrom
copilot/fix-github-action-lockfile-issue
Apr 21, 2026
Merged

Prevent scheduled app-test workflow rebase failures from lockfile drift#196
shazron merged 4 commits into
masterfrom
copilot/fix-github-action-lockfile-issue

Conversation

Copilot AI commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Scheduled app-test runs were failing in Log to File because package-lock.json was modified earlier in the job, leaving the worktree dirty before git pull --rebase. This change keeps the existing lockfile-generation step and explicitly clears lockfile changes before git sync/commit operations.

  • Workflow hardening (.github/workflows/app-test.yml)

    • In Log to File (scheduled-only path), added a pre-sync cleanup command to discard package-lock.json changes before git fetch/checkout/pull.
    • This prevents error: cannot pull with rebase: You have unstaged changes. and keeps the commit scope focused on logs/run.md unless there are real additional changes.
  • Behavioral impact

    • Scheduled logging step is no longer blocked by lockfile mutations produced earlier in the job.
    • Existing npm i --package-lock --package-lock-only behavior is preserved.
- name: Log to File
  if: ${{ always() && (github.event_name == 'schedule') }}
  run: |
    set -euo pipefail
    git config user.name adobe-bot
    git config user.email grp-opensourceoffice@adobe.com
    git restore --worktree --staged package-lock.json || true
    git fetch origin master
    git checkout master
    git pull --rebase origin master
    echo "- $(date) Node ${{ matrix.node-version }} ${{ job.status == 'success' && 'success' ||  job.status }}" >> logs/run.md
    git add logs/run.md
Original prompt

Implement the alternative fix in the GitHub Actions workflow to undo the lockfile change before git operations.

Context:

  • Repo: adobe/aio-e2e-tests
  • Failing job logs show package-lock.json becomes modified before the Log to File step runs git pull --rebase, causing: error: cannot pull with rebase: You have unstaged changes.
  • Workflow file: .github/workflows/app-test.yml
  • Commit ref for current file version: aeb837c

Required change:

  • Keep the existing npm i --package-lock --package-lock-only step.
  • In the Log to File step (runs only when always() && github.event_name == 'schedule'), add commands BEFORE git fetch/checkout/pull to ensure the working tree is clean by discarding changes to package-lock.json.
  • Use a safe approach compatible with GitHub-hosted runners:
    • Prefer git restore --worktree --staged package-lock.json || true.
    • If needed, you may also include git checkout -- package-lock.json || true for older git, but keep it minimal.

Acceptance criteria:

  • The workflow no longer fails with exit code 128 due to unstaged changes when running scheduled jobs.
  • Only logs/run.md should be staged/committed in that step (unless there are genuine changes to commit).

Files to modify:

  • .github/workflows/app-test.yml

Create a pull request with the fix.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

Assistant: The job is failing in the “Log to File” step because the workflow makes the working tree dirty before it tries to git pull --rebase.

What’s happening

In .github/workflows/app-test.yml (ref aeb837c906576f146f4459e0f732241543eaa2c4):

- run: npm i --package-lock --package-lock-only
- run: npm ci
...
- run: git pull --rebase origin master

npm i --package-lock --package-lock-only modifies package-lock.json. The logs show exactly that:

  • M package-lock.json
  • then error: cannot pull with rebase: You have unstaged changes.

So when the scheduled run reaches:

git pull --rebase origin master

Git refuses because package-lock.json has local modifications.


Solution (recommended): stop generating a new lockfile in CI

Unless the intent is to update the lockfile, you shouldn’t run npm i --package-lock --package-lock-only in CI. npm ci already installs strictly from the committed lockfile and will fail if it’s out of sync (which is what you want for reproducibility).

Patch

Remove the lockfile-generation step:

diff --git a/.github/workflows/app-test.yml b/.github/workflows/app-test.yml
index ... ..f
--- a/.github/workflows/app-test.yml
+++ b/.github/workflows/app-test.yml
@@ -27,7 +27,6 @@ jobs:
       uses: actions/setup-node@v3
       with:
         node-version: ${{ matrix.node-version }}
-    - run: npm i --package-lock --package-lock-only
     - run: npm ci

This will keep the checkout clean and allow the later git pull --rebase + commit of logs/run.md to work.


Alternative (if you must keep that step): undo the lockfile change before git operations

If there’s a reason you need that command, you can discard the resulting change before the git pull:

- name: Clean working tree before logging
  if: ${{ always() && (github.event_name == 'schedule') }}
  run: |
    git restore --worktree --staged package-lock.json || true

Place it right before the git fetch/checkout/pull lines in “Log to File”.


Why this fixes the failure

The immediate error is “cannot pull with rebase: You have unstaged changes.” Eliminating (or restoring) the package-lock.json modification ensures the repo is clean, so git pull --rebase origin master can proceed and the job can commit/push only logs/run.md.

User: Do the "Alternative (if you must keep that step): undo the lockfile change before git operations" step

Assistant: I can’t proceed with applying that change right now because I’m waiting on the pending approval/confirmation dialog for the repository change; once you approve it, I’ll update .github/workflows/app-test.yml to restore package-lock.json (before the git pull --rebase) in the “Log to File” step.

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Fix GitHub Actions workflow to prevent lockfile modification Prevent scheduled app-test workflow rebase failures from lockfile drift Apr 21, 2026
Copilot AI requested a review from shazron April 21, 2026 03:13
@shazron
shazron marked this pull request as ready for review April 21, 2026 03:18
@shazron
shazron merged commit de7f1cf into master Apr 21, 2026
11 checks passed
@shazron
shazron deleted the copilot/fix-github-action-lockfile-issue branch April 21, 2026 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants