Skip to content
Merged
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
14 changes: 13 additions & 1 deletion pkg/workflow/imported_steps_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/goccy/go-yaml"

"github.com/github/gh-aw/pkg/actionpins"
"github.com/github/gh-aw/pkg/console"
"github.com/github/gh-aw/pkg/logger"
)
Expand Down Expand Up @@ -92,10 +93,21 @@ func (c *Compiler) validateCheckoutPersistCredentials(frontmatter map[string]any
return nil
}

checkoutVersion := "v4"
if pin, ok := actionpins.GetLatestActionPinByRepo("actions/checkout"); ok && pin.Version != "" {
checkoutVersion = pin.Version
}

persistCredentialsExample := fmt.Sprintf(` # example (keep your existing "uses:" ref):
- uses: actions/checkout@%s
with:
persist-credentials: false`, checkoutVersion)
Comment on lines +101 to +104

msg := fmt.Sprintf(
"actions/checkout step(s) without 'persist-credentials: false' detected in the agent job: %s. "+
"Without this setting the git token is stored in .git/config and leaked to the agent. "+
"Add 'persist-credentials: false' to the 'with:' block of each checkout step. "+
"Add 'persist-credentials: false' to the 'with:' block of each checkout step, for example:\n"+
persistCredentialsExample+"\n"+

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
"pull_request_number": 54957,
"path": "pkg/workflow/imported_steps_validation.go",
"line": 110,
"body": "[/tdd] The new YAML example snippet has no test asserting its presence or format. A future refactor of the fmt.Sprintf assembly could silently drop the user-facing example without any test failure.\n\n

\n💡 Suggested test assertions\n\nAdd to the existing validateCheckoutPersistCredentials tests or a new small test:\n\ngo\nassert.Contains(t, err.Error(), \"- uses: actions/checkout@\")\nassert.Contains(t, err.Error(), \"persist-credentials: false\")\nassert.Contains(t, err.Error(), \"# example\")\n\n\nThese string-contains checks are version-agnostic and add virtually no maintenance cost.\n\n
\n\n@copilot please address this."
}

"See: https://github.github.com/gh-aw/reference/steps/",
strings.Join(offendingStepNames, ", "),
)
Expand Down
Loading