-
Notifications
You must be signed in to change notification settings - Fork 298
Description
Fix checkout frontmatter: emit token (not github-token) for actions/checkout
Bug summary
When checkout frontmatter includes a custom github-token, the compiler emits an actions/checkout step with a github-token input. The actions/checkout action expects the input name token, so custom tokens do not work and checkout can fail or use the wrong credentials.
Analysis
Root cause: In pkg/workflow/checkout_manager.go, the YAML for the actions/checkout step is built with the literal key github-token in two places:
- Line 234 in
GenerateDefaultCheckoutStep: when applying user overrides (non–trial mode), it emitsfmt.Fprintf(&sb, " github-token: %s\n", override.token). - Line 277 in
generateCheckoutStepLines: for additional checkout steps it emitsfmt.Fprintf(&sb, " github-token: %s\n", entry.token).
The actions/checkout action only accepts the input token. The same file already uses token correctly for trial mode at line 222: fmt.Fprintf(&sb, " token: %s\n", effectiveToken). The fix is to emit token (not github-token) wherever the token is passed to actions/checkout. The frontmatter key can remain github-token (user-facing); only the emitted YAML key for the action input must be token.
Implementation plan
Please implement the following so an agent can execute it step by step.
1. Fix YAML emission in pkg/workflow/checkout_manager.go
-
In
GenerateDefaultCheckoutStep(around line 233–235): whenoverride.token != "", emit the input astoken, notgithub-token.
Change:
fmt.Fprintf(&sb, " github-token: %s\n", override.token)
to:
fmt.Fprintf(&sb, " token: %s\n", override.token). -
In
generateCheckoutStepLines(around line 276–278): whenentry.token != "", emit the input astoken, notgithub-token.
Change:
fmt.Fprintf(&sb, " github-token: %s\n", entry.token)
to:
fmt.Fprintf(&sb, " token: %s\n", entry.token).
No other changes in this file are required: struct fields and parsing can keep the name GitHubToken / github-token for frontmatter/schema; only the generated action input name must be token.
2. Update tests that assert on github-token in checkout steps
-
pkg/workflow/checkout_manager_test.go- Replace assertions that expect
github-token:in the generated checkout step YAML with expectations oftoken:(same value, different key). - Example (around line 127): change the expected string from
"github-token: ${{ secrets.MY_TOKEN }}"to"token: ${{ secrets.MY_TOKEN }}"(and similar cases in that file).
- Replace assertions that expect
-
pkg/workflow/checkout_optimization_test.go- It already expects
token: ${{ secrets.CUSTOM_TOKEN }}(line 94). Ensure no remaining expectations usegithub-tokenfor the checkout step; if any do, update them totoken.
- It already expects
-
pkg/workflow/trial_mode_test.go- Tests that look for “github-token in checkout step” (e.g. around lines 77–88, 136–208, 321–324) should be updated to look for
tokenin the checkout step’swith:block (since the correct input name istoken). Adjust comments and assertions accordingly.
- Tests that look for “github-token in checkout step” (e.g. around lines 77–88, 136–208, 321–324) should be updated to look for
-
pkg/workflow/pr_checkout_test.go- Around lines 406–408 the test expects
github-tokenin the “Checkout PR branch” step. That step usesactions/github-script, notactions/checkout. The actions/github-script action uses the inputgithub-token. So leave this test unchanged; only theactions/checkoutsteps should usetoken.
- Around lines 406–408 the test expects
3. Optional: add a regression test
- In
pkg/workflow/checkout_manager_test.go(or a dedicated test), add a case that:- Builds a checkout config with a custom token (e.g.
GitHubToken: "${{ secrets.MY_TOKEN }}"). - Calls
GenerateDefaultCheckoutStepor the helper that produces the additional checkout steps. - Asserts that the generated YAML contains
token: ${{ secrets.MY_TOKEN }}and does not containgithub-token:in the same step (to avoid regressing to the wrong input name).
- Builds a checkout config with a custom token (e.g.
4. Documentation
- In
pkg/workflow/checkout_manager.go, the comment around lines 19–21 shows an example withgithub-token:in the YAML. Update that example so it shows the emitted format: usetoken:in the example of the generated step (or add a short note that the frontmatter keygithub-tokenis emitted as thetokeninput foractions/checkout). - If
docs/orpkg/parser/schemasdocument the checkout step output format, ensure they state that the compiler emitstokenfor the token input ofactions/checkout(and that frontmatter still usesgithub-token).
5. Follow project guidelines
- Use console formatting from
pkg/consolefor any new CLI output. - Run
make agent-finish(or at leastmake build,make test,make recompile,make fmt,make lint) before considering the change done. - Error messages (if any) should follow the project style: [what’s wrong]. [what’s expected]. [example].
Verification
After the change:
- A workflow with frontmatter like:
checkout:- repository: my-repo
path: my-repo
ref: dev
github-token: ${{ secrets.GH_AW_GITHUB_TOKEN }}
- repository: my-repo
should compile to an actions/checkout step whose with: block includes token: ${{ secrets.GH_AW_GITHUB_TOKEN }}, and must not include github-token: for that step.