Add codemod to enforce persist-credentials: false on actions/checkout steps#31478
Merged
Merged
Conversation
4 tasks
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Codemod proposal to auto-add 'persist-credentials: false' to actions/checkout
Add codemod to enforce May 11, 2026
persist-credentials: false on actions/checkout steps
Collaborator
|
@copilot add fuzz tests |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new gh aw fix --write codemod to mechanically enforce with.persist-credentials: false on actions/checkout workflow steps to avoid leaving the Git token in .git/config.
Changes:
- Registered a new codemod (
checkout-persist-credentials-false) in the fix registry and codemod ordering lists. - Implemented a frontmatter line-transform codemod that updates
actions/checkoutsteps across step-like sections (pre-steps,steps,post-steps,pre-agent-steps). - Added unit tests covering key acceptance scenarios (no
with, existingwithmissing key, explicittrueno-op, multi-section updates).
Show a summary per file
| File | Description |
|---|---|
| pkg/cli/fix_codemods.go | Registers the new codemod in the overall codemod list. |
| pkg/cli/fix_codemods_test.go | Updates expected codemod presence and ordering assertions. |
| pkg/cli/codemod_checkout_persist_credentials_false.go | Implements the new codemod’s YAML frontmatter line transformation. |
| pkg/cli/codemod_checkout_persist_credentials_false_test.go | Adds unit tests for the new codemod behavior. |
| .github/workflows/issue-monster.lock.yml | Minor comment-only adjustment in a locked workflow file. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 5/5 changed files
- Comments generated: 2
Comment on lines
+197
to
+201
| if withStart != -1 { | ||
| insertAt := withEnd + 1 | ||
| insertLine := fmt.Sprintf("%spersist-credentials: false", withIndent+" ") | ||
| updated := append([]string{}, stepLines[:insertAt]...) | ||
| updated = append(updated, insertLine) |
Comment on lines
+236
to
+246
| lower := strings.ToLower(raw) | ||
| idx := strings.Index(lower, "persist-credentials:") | ||
| if idx == -1 { | ||
| return "" | ||
| } | ||
| rest := strings.TrimSpace(raw[idx+len("persist-credentials:"):]) | ||
| if rest == "" { | ||
| return "" | ||
| } | ||
|
|
||
| rest = strings.SplitN(rest, "#", 2)[0] |
Collaborator
|
@copilot review all comments |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cross-repo compile audits found strict-mode failures caused by
actions/checkoutsteps missingwith.persist-credentials: false, which can leave the git token in.git/config. This change adds a mechanical fix codemod sogh aw fix --writecan remediate affected workflows automatically.Registry and codemod wiring
checkout-persist-credentials-falseIntroducedInset to the current codemod release (1.0.44)Frontmatter step transformation
pre-steps,steps,post-steps,pre-agent-stepsuses: actions/checkout@*(andactions/checkout):with:block when missingpersist-credentials: falsewhenwith:exists but key is missingpersist-credentialsis already setpersist-credentials: trueis explicitly setUnit coverage for acceptance scenarios
withcheckout stepwithblock missingpersist-credentialspersist-credentials: trueno-oppre-steps/post-steps)Fuzz coverage
checkout-persist-credentials-falsecodemod behavior across supported sections and checkout/non-checkout step variants