Move roles and bots to on.roles and on.bots#16672
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot fix all compilation syntax errors (ai-moderator...) |
There was a problem hiding this comment.
Pull request overview
Migrates workflow frontmatter roles and bots from top-level keys to on.roles and on.bots, removing legacy support and providing an automated codemod path.
Changes:
- Extend schema and parsing to recognize
on.botsand stop reading top-levelbots. - Add a
bots-to-on-botscodemod and register it ingh aw fix. - Update workflow/compiler tests and fixtures to use
on.roles/on.bots.
Reviewed changes
Copilot reviewed 15 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/role_checks.go | Updates bot extraction to read only on.bots and adds a parseBotsValue helper. |
| pkg/workflow/frontmatter_types.go | Removes top-level Roles/Bots fields and omits them from ToMap(). |
| pkg/parser/schemas/main_workflow_schema.json | Adds bots under the on object in the JSON schema. |
| pkg/cli/fix_codemods.go | Registers the new bots-to-on-bots codemod. |
| pkg/cli/codemod_bots.go | Implements codemod to move top-level bots into on.bots. |
| pkg/cli/codemod_bots_test.go | Adds unit tests for the new bots codemod (inline, multiline, no on, no-op cases). |
| pkg/workflow/bots_test.go | Updates bots extraction tests to use on.bots. |
| pkg/workflow/role_checks_test.go | Updates role/bot checks fixture to use on.bots. |
| pkg/workflow/compiler_orchestrator_test.go | Updates orchestrator config extraction fixture to on.roles/on.bots and expands on: to a mapping. |
| pkg/workflow/compiler_orchestrator_workflow_test.go | Updates “complete workflow” fixture to put roles/bots under on: (but currently drops other fields the test asserts on). |
| pkg/workflow/permission_restriction_test.go | Moves roles into on.roles across permission restriction scenarios. |
| pkg/workflow/pre_activation_custom_fields_test.go | Moves roles into on.roles in pre-activation job fixtures. |
| pkg/workflow/stop_time_check_job_test.go | Moves roles into on.roles in stop-time fixtures. |
| pkg/workflow/skip_if_match_test.go | Moves roles into on.roles in skip-if-match fixtures. |
| pkg/workflow/skip_if_no_match_test.go | Moves roles into on.roles in skip-if-no-match fixtures. |
| pkg/workflow/skip_bots_test.go | Moves roles into on.roles in skip-bots fixture. |
| pkg/workflow/task_job_generation_fix_test.go | Moves roles under on: in at least one fixture for activation/task job generation behavior. |
| pkg/workflow/processing_benchmark_test.go | Updates benchmark fixture to use a mapping on: so roles can be nested under it. |
Comments suppressed due to low confidence (2)
pkg/workflow/compiler_orchestrator_workflow_test.go:1114
- This test's
testContentfrontmatter no longer includes fields likedescription,source,permissions,network,concurrency,run-name,env,features,if,timeout-minutes,runs-on,environment,container, andcache, but the assertions below still expect all of those to be non-empty / set to specific values. Either restore the removed frontmatter fields intestContentor update the assertions to match the reduced fixture.
testContent := `---
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize]
draft: false
roles:
- admin
- maintainer
bots:
- copilot
- dependabot
engine: copilot
steps:
- name: Custom step
run: echo "test"
post-steps:
- name: Cleanup
run: echo "cleanup"
services:
pkg/cli/codemod_bots.go:100
- When collecting multi-line
bots:blocks, the loop unconditionally includes any subsequent blank or comment line (trimmed == "" || strings.HasPrefix(trimmed, "#")) as part of the bots block, even if it is a top-level comment (indentation <=bots:indentation). This can incorrectly move unrelated top-level comments/blank lines underon.botsduring migration. Consider only including comment/blank lines if they are actually nested under thebots:key (or use the existinghasExitedBlock()helper to detect block termination).
for j := botsLineIdx + 1; j < len(frontmatterLines); j++ {
line := frontmatterLines[j]
trimmed := strings.TrimSpace(line)
// Empty lines or comments might be part of the block
if trimmed == "" || strings.HasPrefix(trimmed, "#") {
botsLines = append(botsLines, line)
botsEndIdx = j
continue
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "bots": { | ||
| "type": "array", | ||
| "description": "Allow list of bot identifiers that can trigger the workflow even if they don't meet the required role permissions. When the actor is in this list, the bot must be active (installed) on the repository to trigger the workflow.", | ||
| "items": { | ||
| "type": "string", | ||
| "minLength": 1, | ||
| "description": "Bot identifier/name (e.g., 'dependabot[bot]', 'renovate[bot]', 'github-actions[bot]')" | ||
| } | ||
| }, |
There was a problem hiding this comment.
The schema adds on.bots, but the root schema still defines a top-level bots property (see main_workflow_schema.json around line ~6436). If this PR removes legacy support for top-level bots, the top-level schema entry should be removed to ensure validation rejects deprecated placement.
| "bots": { | |
| "type": "array", | |
| "description": "Allow list of bot identifiers that can trigger the workflow even if they don't meet the required role permissions. When the actor is in this list, the bot must be active (installed) on the repository to trigger the workflow.", | |
| "items": { | |
| "type": "string", | |
| "minLength": 1, | |
| "description": "Bot identifier/name (e.g., 'dependabot[bot]', 'renovate[bot]', 'github-actions[bot]')" | |
| } | |
| }, |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Fixed in commit 3ffec3e. The compiler now properly comments out Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Migration Plan: Move roles and bots to on.roles and on.bots
Phase 1: Code Analysis ✅
Phase 2: Update extractBots to support on.bots ✅
pkg/workflow/role_checks.go::extractBots()to checkon.botsfirstparseBotsValue()helper function similar toparseRolesValue()on.botsformatPhase 3: Create bots-to-on-bots codemod ✅
pkg/cli/codemod_bots.gofollowing roles codemod patternpkg/cli/codemod_bots_test.gowith comprehensive testspkg/cli/fix_codemods.goPhase 4: Remove top-level support (no legacy compatibility) ✅
Rolesfield fromFrontmatterConfigstructBotsfield fromFrontmatterConfigstructextractRoles()- already only checkson.rolesextractBots()- now only checkson.botsToMap()functionPhase 5: Update JSON Schema ✅
botsproperty toonobject in schemarolesalready exists inonobjectPhase 6: Update Tests ✅
Phase 7: Final Validation ✅
make fmtPhase 8: Fix Compilation Errors ✅
rolesandbotsfields inonsectioncommentOutProcessedFieldsInOnSectionto handlerolesandbotsinRolesArrayandinBotsArray.invalid.ymlfiles generatedSummary
Successfully migrated
rolesandbotsfields from top-level toon.rolesandon.bots. Key changes:bots-to-on-botscodemod alongside existingroles-to-on-rolescodemodbotsproperty toonobject in JSON schemaextractBots()to only checkon.bots(removed top-level support)RolesandBotsfields fromFrontmatterConfigstructparseBotsValue()helper function for consistent parsingon.rolesandon.botsformatrolesandbotsfields in theonsection🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.