Skip to content

Commit ebcb6b4

Browse files
authored
Allow on.roles single-string role values (not just all) (#26789)
1 parent 35660d6 commit ebcb6b4

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

docs/src/content/docs/reference/frontmatter.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ on:
237237
roles: all # Allow any user (⚠️ use with caution)
238238
```
239239

240+
You can also use a single role string, for example `roles: write`.
241+
240242
Available roles: `admin`, `maintainer`/`maintain`, `write`, `triage`, `read`, `all`. Workflows with unsafe triggers (`push`, `issues`, `pull_request`) automatically enforce permission checks. Failed checks cancel the workflow with a warning.
241243

242244
> [!TIP]

pkg/parser/schemas/main_workflow_schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,8 +1840,8 @@
18401840
"oneOf": [
18411841
{
18421842
"type": "string",
1843-
"enum": ["all"],
1844-
"description": "Allow any authenticated user to trigger the workflow (\u26a0\ufe0f disables permission checking entirely - use with caution)"
1843+
"enum": ["admin", "maintainer", "maintain", "write", "triage", "read", "all"],
1844+
"description": "Single repository permission level that can trigger the workflow. Use 'all' to allow any authenticated user (\u26a0\ufe0f disables permission checking entirely - use with caution)"
18451845
},
18461846
{
18471847
"type": "array",

pkg/workflow/role_checks_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,43 @@ Test that role membership check uses GITHUB_TOKEN with bots.`
148148
}
149149
}
150150

151+
func TestRoleMembershipSupportsSingleRoleString(t *testing.T) {
152+
tmpDir := testutil.TempDir(t, "role-membership-single-role-string-test")
153+
154+
compiler := NewCompiler()
155+
156+
frontmatter := `---
157+
on:
158+
pull_request:
159+
types: [opened]
160+
roles: write
161+
---
162+
163+
# Test Workflow
164+
Test that on.roles supports a single string permission value.`
165+
166+
workflowPath := filepath.Join(tmpDir, "role-membership-single-role-string.md")
167+
err := os.WriteFile(workflowPath, []byte(frontmatter), 0644)
168+
if err != nil {
169+
t.Fatalf("Failed to write workflow file: %v", err)
170+
}
171+
172+
err = compiler.CompileWorkflow(workflowPath)
173+
if err != nil {
174+
t.Fatalf("Expected workflow with on.roles as a single string to compile successfully: %v", err)
175+
}
176+
177+
outputPath := filepath.Join(tmpDir, "role-membership-single-role-string.lock.yml")
178+
compiledContent, err := os.ReadFile(outputPath)
179+
if err != nil {
180+
t.Fatalf("Failed to read compiled workflow: %v", err)
181+
}
182+
183+
compiledStr := string(compiledContent)
184+
assert.Contains(t, compiledStr, "id: check_membership", "Compiled workflow should include membership checks for role-gated triggers")
185+
assert.Contains(t, compiledStr, "write", "Compiled workflow should require the single role provided as a string")
186+
}
187+
151188
func TestInferEventsFromTriggers(t *testing.T) {
152189
c := &Compiler{}
153190

0 commit comments

Comments
 (0)