Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/workflow-actions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gcb-core": minor
---

Add the workflow write actions: `workflow:run` (`gh workflow run <workflow>`, with `--ref` and repeatable `--raw-field`), `workflow:enable` and `workflow:disable`.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,9 @@ actions. Grant them on the App, then approve any changed permissions on each ins
| `run rerun` | `actions: write` |
| `release list` | `contents: read` |
| `release view` | `contents: read` |
| `workflow run` | `actions: write`, `contents: read` |
| `workflow enable` | `actions: write` |
| `workflow disable` | `actions: write` |
| `workflow list` | `actions: read` |
| `workflow view` | `actions: read`, `contents: read` |
| `label list` | `issues: read` |
Expand Down
39 changes: 39 additions & 0 deletions packages/core/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,42 @@ const RELEASE_VIEW: GhAction = {
appUser: true,
}

// GitHub: POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches
const WORKFLOW_RUN: GhAction = {
name: 'workflow:run',
command: ['workflow', 'run'],
positionals: [{ name: 'workflow', type: 'string', required: true }],
flags: [
{ name: 'ref', type: 'string' },
{ name: 'raw-field', type: 'string', repeatable: true },
],
permissions: { actions: 'write', contents: 'read' },
timeoutSeconds: 120,
appUser: true,
}

// GitHub: PUT /repos/{owner}/{repo}/actions/workflows/{workflow_id}/enable
const WORKFLOW_ENABLE: GhAction = {
name: 'workflow:enable',
command: ['workflow', 'enable'],
positionals: [{ name: 'workflow', type: 'string', required: true }],
flags: [],
permissions: { actions: 'write' },
timeoutSeconds: 60,
appUser: true,
}

// GitHub: PUT /repos/{owner}/{repo}/actions/workflows/{workflow_id}/disable
const WORKFLOW_DISABLE: GhAction = {
name: 'workflow:disable',
command: ['workflow', 'disable'],
positionals: [{ name: 'workflow', type: 'string', required: true }],
flags: [],
permissions: { actions: 'write' },
timeoutSeconds: 60,
appUser: true,
}

// GitHub: GET /repos/{owner}/{repo}/actions/workflows
const WORKFLOW_LIST: GhAction = {
name: 'workflow:list',
Expand Down Expand Up @@ -873,6 +909,9 @@ export const GH_ACTIONS: Readonly<Record<string, GhAction>> = Object.freeze({
'run:rerun': RUN_RERUN,
'release:list': RELEASE_LIST,
'release:view': RELEASE_VIEW,
'workflow:run': WORKFLOW_RUN,
'workflow:enable': WORKFLOW_ENABLE,
'workflow:disable': WORKFLOW_DISABLE,
'workflow:list': WORKFLOW_LIST,
'workflow:view': WORKFLOW_VIEW,
'label:list': LABEL_LIST,
Expand Down
47 changes: 47 additions & 0 deletions test/unit/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ describe('gh action catalog', () => {
'run:rerun',
'release:list',
'release:view',
'workflow:run',
'workflow:enable',
'workflow:disable',
'workflow:list',
'workflow:view',
'label:list',
Expand Down Expand Up @@ -114,6 +117,12 @@ describe('gh action catalog', () => {
assert.equal(getGhAction('issue:comment-edit').appUser, true)
assert.deepEqual(getGhAction('release:list').permissions, { contents: 'read' })
assert.deepEqual(getGhAction('release:view').permissions, { contents: 'read' })
assert.deepEqual(getGhAction('workflow:run').permissions, {
actions: 'write',
contents: 'read',
})
assert.deepEqual(getGhAction('workflow:enable').permissions, { actions: 'write' })
assert.deepEqual(getGhAction('workflow:disable').permissions, { actions: 'write' })
assert.deepEqual(getGhAction('workflow:list').permissions, { actions: 'read' })
assert.deepEqual(getGhAction('workflow:view').permissions, {
actions: 'read',
Expand Down Expand Up @@ -385,6 +394,44 @@ describe('buildGhArgv', () => {
const injected = buildGhArgv('release:view', { tag: '--web' }, 'acme/widget')
assert.deepEqual(injected.slice(-2), ['--', '--web'])
assert.throws(() => buildGhArgv('workflow:view', {}, 'acme/widget'), /needs workflow/u)
assert.deepEqual(
buildGhArgv(
'workflow:run',
{ workflow: 'ci.yml', ref: 'main', 'raw-field': ['a=1', 'b=@file'] },
'acme/widget',
),
[
'workflow',
'run',
'--ref',
'main',
'--raw-field',
'a=1',
'--raw-field',
'b=@file',
'--repo',
'acme/widget',
'--',
'ci.yml',
],
)
assert.deepEqual(buildGhArgv('workflow:enable', { workflow: 'ci.yml' }, 'acme/widget'), [
'workflow',
'enable',
'--repo',
'acme/widget',
'--',
'ci.yml',
])
assert.deepEqual(buildGhArgv('workflow:disable', { workflow: 'ci.yml' }, 'acme/widget'), [
'workflow',
'disable',
'--repo',
'acme/widget',
'--',
'ci.yml',
])
assert.throws(() => buildGhArgv('workflow:run', {}, 'acme/widget'), /needs workflow/u)
assert.throws(
() => buildGhArgv('workflow:view', { workflow: 'ci.yml', ref: 'main' }, 'acme/widget'),
/needs --yaml with --ref/u,
Expand Down
Loading