diff --git a/.changeset/workflow-actions.md b/.changeset/workflow-actions.md new file mode 100644 index 00000000..c5923f7a --- /dev/null +++ b/.changeset/workflow-actions.md @@ -0,0 +1,5 @@ +--- +"gcb-core": minor +--- + +Add the workflow write actions: `workflow:run` (`gh workflow run `, with `--ref` and repeatable `--raw-field`), `workflow:enable` and `workflow:disable`. diff --git a/README.md b/README.md index ba4e7ab2..f4ff149b 100644 --- a/README.md +++ b/README.md @@ -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` | diff --git a/packages/core/src/actions.ts b/packages/core/src/actions.ts index b4dcb997..a8564d09 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -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', @@ -873,6 +909,9 @@ export const GH_ACTIONS: Readonly> = 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, diff --git a/test/unit/actions.test.ts b/test/unit/actions.test.ts index 2d5cef23..e95e533f 100644 --- a/test/unit/actions.test.ts +++ b/test/unit/actions.test.ts @@ -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', @@ -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', @@ -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,