Skip to content

Commit 7bdf935

Browse files
Preserve workflow files when PAT_TOKEN is not available
- Stash and restore workflow files if PAT_TOKEN is not set - Prevents push failures when upstream changes include workflow files - Workflow files will remain at current version until PAT_TOKEN is configured
1 parent accab66 commit 7bdf935

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

.github/workflows/refresh_repository.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,25 @@ jobs:
7474
git checkout master
7575
echo "Current branch after checkout:"
7676
git branch -v
77+
78+
# Store current workflow files if PAT_TOKEN is not available
79+
if [[ -z "${{ secrets.PAT_TOKEN }}" ]]; then
80+
echo "PAT_TOKEN not set - will preserve current workflow files"
81+
git stash push -m "preserve_workflows" .github/workflows/ || true
82+
fi
83+
7784
# Merge instead of hard-reset to keep local-only files like workflows
7885
git merge --no-edit upstream/master || true
86+
87+
# Restore workflow files if PAT_TOKEN is not available
88+
if [[ -z "${{ secrets.PAT_TOKEN }}" ]]; then
89+
echo "Restoring workflow files to current version (PAT_TOKEN required to update them)"
90+
git checkout HEAD -- .github/workflows/ || true
91+
git stash pop || true
92+
fi
93+
7994
echo "Pushing merge to origin..."
80-
# Configure git to use token for push (needed for workflow file changes)
81-
# If PAT_TOKEN is not set, this will fail when trying to push workflow file changes
95+
# Configure git to use token for push
8296
git remote set-url origin https://${GIT_TOKEN}@github.com/${{ github.repository }}.git
8397
# Push the updated branch back to the fork without rewriting history
8498
git push origin master

0 commit comments

Comments
 (0)