From 13bc09769d122a64f75aa5037256f6f2d78be8c4 Mon Sep 17 00:00:00 2001 From: Peter Evans <18365890+peter-evans@users.noreply.github.com> Date: Wed, 31 Jan 2024 19:33:27 +0900 Subject: [PATCH] feat: update runtime to node 20 (#316) * feat: update runtime to node 20 * fix jest exit code issue --- .github/workflows/ci.yml | 2 +- .github/workflows/hello-world-command.yml | 2 +- .github/workflows/ping-command.yml | 2 +- .github/workflows/update-major-version.yml | 31 ++++++++++++++++++++++ README.md | 14 +++++----- __test__/command-helper.unit.test.ts | 16 +++++++---- action.yml | 2 +- dist/index.js | 17 ++++++------ docs/advanced-configuration.md | 6 ++--- docs/examples.md | 28 +++++++++---------- docs/getting-started.md | 6 ++--- docs/updating.md | 13 ++++++++- docs/workflow-dispatch.md | 10 +++---- package-lock.json | 4 +-- package.json | 2 +- src/command-helper.ts | 15 ++++------- src/main.ts | 5 +++- 17 files changed, 110 insertions(+), 65 deletions(-) create mode 100644 .github/workflows/update-major-version.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d82a71a9a..351a796f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: 16.x + node-version: 20.x cache: npm - run: npm ci - run: npm run build diff --git a/.github/workflows/hello-world-command.yml b/.github/workflows/hello-world-command.yml index ba8fee371..2583f5f1a 100644 --- a/.github/workflows/hello-world-command.yml +++ b/.github/workflows/hello-world-command.yml @@ -10,7 +10,7 @@ jobs: uses: peter-evans/create-or-update-comment@v4 with: comment-id: ${{ github.event.client_payload.github.payload.comment.id }} - reaction-type: hooray + reactions: hooray - name: Create URL to the run output id: vars diff --git a/.github/workflows/ping-command.yml b/.github/workflows/ping-command.yml index fb071aaea..5cc307da3 100644 --- a/.github/workflows/ping-command.yml +++ b/.github/workflows/ping-command.yml @@ -12,4 +12,4 @@ jobs: comment-id: ${{ github.event.client_payload.github.payload.comment.id }} body: | >pong ${{ github.event.client_payload.slash_command.args.all }} - reaction-type: hooray + reactions: hooray diff --git a/.github/workflows/update-major-version.yml b/.github/workflows/update-major-version.yml new file mode 100644 index 000000000..3a4146ee8 --- /dev/null +++ b/.github/workflows/update-major-version.yml @@ -0,0 +1,31 @@ +name: Update Major Version +run-name: Update ${{ github.event.inputs.main_version }} to ${{ github.event.inputs.target }} + +on: + workflow_dispatch: + inputs: + target: + description: The target tag or reference + required: true + main_version: + type: choice + description: The major version tag to update + options: + - v4 + +jobs: + tag: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.ACTIONS_BOT_TOKEN }} + fetch-depth: 0 + - name: Git config + run: | + git config user.name actions-bot + git config user.email actions-bot@users.noreply.github.com + - name: Tag new target + run: git tag -f ${{ github.event.inputs.main_version }} ${{ github.event.inputs.target }} + - name: Push new tag + run: git push origin ${{ github.event.inputs.main_version }} --force diff --git a/README.md b/README.md index 720209c23..ec820c239 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ See it in action with the following live demos. - [Standard configuration](#standard-configuration) - [Advanced configuration](docs/advanced-configuration.md) - [Workflow dispatch](docs/workflow-dispatch.md) -- [Updating to v3](docs/updating.md) +- [Updating to v4](docs/updating.md) ## Dispatching commands @@ -54,7 +54,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Slash Command Dispatch - uses: peter-evans/slash-command-dispatch@v3 + uses: peter-evans/slash-command-dispatch@v4 with: token: ${{ secrets.PAT }} commands: | @@ -102,7 +102,7 @@ You can use a [PAT](https://docs.github.com/en/github/authenticating-to-github/c ```yml - name: Slash Command Dispatch - uses: peter-evans/slash-command-dispatch@v3 + uses: peter-evans/slash-command-dispatch@v4 with: token: ${{ secrets.PAT }} reaction-token: ${{ secrets.PAT }} @@ -178,7 +178,7 @@ It will also contain any static arguments if configured. To demonstrate, take the following configuration as an example. ```yml - - uses: peter-evans/slash-command-dispatch@v3 + - uses: peter-evans/slash-command-dispatch@v4 with: token: ${{ secrets.PAT }} commands: | @@ -248,12 +248,12 @@ The simplest response is to add a :tada: reaction to the comment. ```yml - name: Add reaction - uses: peter-evans/create-or-update-comment@v2 + uses: peter-evans/create-or-update-comment@v4 with: token: ${{ secrets.PAT }} repository: ${{ github.event.client_payload.github.payload.repository.full_name }} comment-id: ${{ github.event.client_payload.github.payload.comment.id }} - reaction-type: hooray + reactions: hooray ``` Another option is to reply with a new comment containing a link to the run output. @@ -264,7 +264,7 @@ Another option is to reply with a new comment containing a link to the run outpu run: echo "run-url=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT - name: Create comment - uses: peter-evans/create-or-update-comment@v2 + uses: peter-evans/create-or-update-comment@v4 with: token: ${{ secrets.PAT }} repository: ${{ github.event.client_payload.github.payload.repository.full_name }} diff --git a/__test__/command-helper.unit.test.ts b/__test__/command-helper.unit.test.ts index e2ded3f40..8cff531fc 100644 --- a/__test__/command-helper.unit.test.ts +++ b/__test__/command-helper.unit.test.ts @@ -153,7 +153,7 @@ describe('command-helper tests', () => { dispatch_type: 'repository' } ] - expect(configIsValid(config)).toBeTruthy() + expect(configIsValid(config)).toEqual(null) }) test('invalid permission level in config', async () => { @@ -169,7 +169,9 @@ describe('command-helper tests', () => { dispatch_type: 'repository' } ] - expect(configIsValid(config)).toBeFalsy() + expect(configIsValid(config)).toEqual( + `'test-case-invalid-permission' is not a valid 'permission'.` + ) }) test('invalid issue type in config', async () => { @@ -185,7 +187,9 @@ describe('command-helper tests', () => { dispatch_type: 'repository' } ] - expect(configIsValid(config)).toBeFalsy() + expect(configIsValid(config)).toEqual( + `'test-case-invalid-issue-type' is not a valid 'issue-type'.` + ) }) test('invalid dispatch type in config', async () => { @@ -193,7 +197,7 @@ describe('command-helper tests', () => { { command: 'test', permission: 'write', - issue_type: 'test-case-invalid-issue-type', + issue_type: 'both', allow_edits: false, repository: 'peter-evans/slash-command-dispatch', event_type_suffix: '-command', @@ -201,7 +205,9 @@ describe('command-helper tests', () => { dispatch_type: 'test-case-invalid-dispatch-type' } ] - expect(configIsValid(config)).toBeFalsy() + expect(configIsValid(config)).toEqual( + `'test-case-invalid-dispatch-type' is not a valid 'dispatch-type'.` + ) }) test('actor does not have permission', async () => { diff --git a/action.yml b/action.yml index 7c4ced52d..7e85af811 100644 --- a/action.yml +++ b/action.yml @@ -41,7 +41,7 @@ outputs: error-message: description: 'Validation errors when using `workflow` dispatch.' runs: - using: 'node16' + using: 'node20' main: 'dist/index.js' branding: icon: 'target' diff --git a/dist/index.js b/dist/index.js index c282d9940..e9d289dab 100644 --- a/dist/index.js +++ b/dist/index.js @@ -147,19 +147,16 @@ exports.getCommandsConfigFromJson = getCommandsConfigFromJson; function configIsValid(config) { for (const command of config) { if (!['none', 'read', 'triage', 'write', 'maintain', 'admin'].includes(command.permission)) { - core.setFailed(`'${command.permission}' is not a valid 'permission'.`); - return false; + return `'${command.permission}' is not a valid 'permission'.`; } if (!['issue', 'pull-request', 'both'].includes(command.issue_type)) { - core.setFailed(`'${command.issue_type}' is not a valid 'issue-type'.`); - return false; + return `'${command.issue_type}' is not a valid 'issue-type'.`; } if (!['repository', 'workflow'].includes(command.dispatch_type)) { - core.setFailed(`'${command.dispatch_type}' is not a valid 'dispatch-type'.`); - return false; + return `'${command.dispatch_type}' is not a valid 'dispatch-type'.`; } } - return true; + return null; } exports.configIsValid = configIsValid; function actorHasPermission(actorPermission, commandPermission) { @@ -454,8 +451,10 @@ function run() { const config = (0, command_helper_1.getCommandsConfig)(inputs); core.debug(`Commands config: ${(0, util_1.inspect)(config)}`); // Check the config is valid - if (!(0, command_helper_1.configIsValid)(config)) - return; + const configError = (0, command_helper_1.configIsValid)(config); + if (configError) { + throw new Error(configError); + } // Get the comment body and id const commentBody = github.context.payload.comment.body; const commentId = github.context.payload.comment.id; diff --git a/docs/advanced-configuration.md b/docs/advanced-configuration.md index b864b1b06..e6b2c8cca 100644 --- a/docs/advanced-configuration.md +++ b/docs/advanced-configuration.md @@ -8,7 +8,7 @@ For example, the following basic configuration means that all commands must have ```yml - name: Slash Command Dispatch - uses: peter-evans/slash-command-dispatch@v3 + uses: peter-evans/slash-command-dispatch@v4 with: token: ${{ secrets.PAT }} commands: | @@ -38,7 +38,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Slash Command Dispatch - uses: peter-evans/slash-command-dispatch@v3 + uses: peter-evans/slash-command-dispatch@v4 with: token: ${{ secrets.PAT }} config: > @@ -84,7 +84,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Slash Command Dispatch - uses: peter-evans/slash-command-dispatch@v3 + uses: peter-evans/slash-command-dispatch@v4 with: token: ${{ secrets.PAT }} config-from-file: .github/slash-command-dispatch.json diff --git a/docs/examples.md b/docs/examples.md index a31857611..4e52e08c8 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -50,12 +50,12 @@ jobs: # Add reaction to the comment - name: Add reaction - uses: peter-evans/create-or-update-comment@v2 + uses: peter-evans/create-or-update-comment@v4 with: token: ${{ secrets.PAT }} repository: ${{ github.event.client_payload.github.payload.repository.full_name }} comment-id: ${{ github.event.client_payload.github.payload.comment.id }} - reaction-type: hooray + reactions: hooray ``` ### pytest @@ -111,12 +111,12 @@ jobs: # Add reaction to the comment - name: Add reaction - uses: peter-evans/create-or-update-comment@v2 + uses: peter-evans/create-or-update-comment@v4 with: token: ${{ secrets.PAT }} repository: ${{ github.event.client_payload.github.payload.repository.full_name }} comment-id: ${{ github.event.client_payload.github.payload.comment.id }} - reaction-type: hooray + reactions: hooray ``` ## Use case: Execute command to modify a pull request branch @@ -158,12 +158,12 @@ jobs: git push - name: Add reaction - uses: peter-evans/create-or-update-comment@v2 + uses: peter-evans/create-or-update-comment@v4 with: token: ${{ secrets.PAT }} repository: ${{ github.event.client_payload.github.payload.repository.full_name }} comment-id: ${{ github.event.client_payload.github.payload.comment.id }} - reaction-type: hooray + reactions: hooray ``` ### rebase @@ -204,28 +204,28 @@ jobs: git push --force-with-lease - name: Update comment - uses: peter-evans/create-or-update-comment@v2 + uses: peter-evans/create-or-update-comment@v4 with: token: ${{ secrets.PAT }} repository: ${{ github.event.client_payload.github.payload.repository.full_name }} comment-id: ${{ github.event.client_payload.github.payload.comment.id }} body: | >Pull request successfully rebased - reaction-type: hooray + reactions: hooray notRebaseable: if: github.event.client_payload.pull_request.rebaseable != true runs-on: ubuntu-latest steps: - name: Update comment - uses: peter-evans/create-or-update-comment@v2 + uses: peter-evans/create-or-update-comment@v4 with: token: ${{ secrets.PAT }} repository: ${{ github.event.client_payload.github.payload.repository.full_name }} comment-id: ${{ github.event.client_payload.github.payload.comment.id }} body: | >Pull request is not rebaseable - reaction-type: hooray + reactions: hooray ``` ### black @@ -279,12 +279,12 @@ jobs: git push - name: Add reaction - uses: peter-evans/create-or-update-comment@v2 + uses: peter-evans/create-or-update-comment@v4 with: token: ${{ secrets.PAT }} repository: ${{ github.event.client_payload.github.payload.repository.full_name }} comment-id: ${{ github.event.client_payload.github.payload.comment.id }} - reaction-type: hooray + reactions: hooray ``` ## Help command @@ -301,7 +301,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Update comment - uses: peter-evans/create-or-update-comment@v2 + uses: peter-evans/create-or-update-comment@v4 with: token: ${{ secrets.ACTIONS_BOT_TOKEN }} repository: ${{ github.event.client_payload.github.payload.repository.full_name }} @@ -313,5 +313,5 @@ jobs: > /ping [\ ...] | Echos back a list of arguments > /hello-world-local | Receive a greeting from the world (local execution) > /ping-local [\ ...] | Echos back a list of arguments (local execution) - reaction-type: hooray + reactions: hooray ``` diff --git a/docs/getting-started.md b/docs/getting-started.md index 11b946c49..0944f9a52 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -19,12 +19,12 @@ Follow this guide to get started with a working `/example` command. runs-on: ubuntu-latest steps: - name: Add reaction - uses: peter-evans/create-or-update-comment@v2 + uses: peter-evans/create-or-update-comment@v4 with: token: ${{ secrets.PAT }} repository: ${{ github.event.client_payload.github.payload.repository.full_name }} comment-id: ${{ github.event.client_payload.github.payload.comment.id }} - reaction-type: hooray + reactions: hooray ``` 3. Create a `repo` scoped Personal Access Token (PAT) by following [this guide](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). @@ -56,7 +56,7 @@ Command processing setup is complete! Now we need to setup command dispatch for runs-on: ubuntu-latest steps: - name: Slash Command Dispatch - uses: peter-evans/slash-command-dispatch@v3 + uses: peter-evans/slash-command-dispatch@v4 with: token: ${{ secrets.PAT }} commands: example diff --git a/docs/updating.md b/docs/updating.md index e4bfe43c7..acb321bad 100644 --- a/docs/updating.md +++ b/docs/updating.md @@ -1,4 +1,4 @@ -## Updating from `v2` to `v3` +## Updating from `v3` to `v4` ### Breaking changes @@ -6,6 +6,17 @@ ### What's new +- Updated runtime to Node.js 20 + - The action now requires a minimum version of [v2.308.0](https://github.com/actions/runner/releases/tag/v2.308.0) for the Actions runner. Update self-hosted runners to v2.308.0 or later to ensure compatibility. + +## Updating from `v2` to `v3` + +### Breaking changes + +- If using self-hosted runners or GitHub Enterprise Server, there are minimum requirements for `v3` to run. See "What's new" below for details. + +### What's new + - Updated runtime to Node.js 16 - The action now requires a minimum version of v2.285.0 for the [Actions Runner](https://github.com/actions/runner/releases/tag/v2.285.0). - If using GitHub Enterprise Server, the action requires [GHES 3.4](https://docs.github.com/en/enterprise-server@3.4/admin/release-notes) or later. diff --git a/docs/workflow-dispatch.md b/docs/workflow-dispatch.md index a4227ccec..c6508652d 100644 --- a/docs/workflow-dispatch.md +++ b/docs/workflow-dispatch.md @@ -36,7 +36,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Slash Command Dispatch - uses: peter-evans/slash-command-dispatch@v3 + uses: peter-evans/slash-command-dispatch@v4 with: token: ${{ secrets.PAT }} commands: | @@ -85,12 +85,12 @@ The simplest response is to add a :tada: reaction to the comment. ```yml - name: Add reaction - uses: peter-evans/create-or-update-comment@v2 + uses: peter-evans/create-or-update-comment@v4 with: token: ${{ secrets.PAT }} repository: ${{ github.event.inputs.repository }} comment-id: ${{ github.event.inputs.comment-id }} - reaction-type: hooray + reactions: hooray ``` ## Validation errors @@ -107,7 +107,7 @@ The `error-message` output can be used to provide feedback to the user as follow ```yml - name: Slash Command Dispatch id: scd - uses: peter-evans/slash-command-dispatch@v3 + uses: peter-evans/slash-command-dispatch@v4 with: token: ${{ secrets.PAT }} commands: | @@ -118,7 +118,7 @@ The `error-message` output can be used to provide feedback to the user as follow - name: Edit comment with error message if: steps.scd.outputs.error-message - uses: peter-evans/create-or-update-comment@v2 + uses: peter-evans/create-or-update-comment@v4 with: comment-id: ${{ github.event.comment.id }} body: | diff --git a/package-lock.json b/package-lock.json index e6b211c4e..62af6d34e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "slash-command-dispatch", - "version": "3.0.0", + "version": "4.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "slash-command-dispatch", - "version": "3.0.0", + "version": "4.0.0", "license": "MIT", "dependencies": { "@actions/core": "^1.10.1", diff --git a/package.json b/package.json index 1b765807d..a271b1120 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "slash-command-dispatch", - "version": "3.0.0", + "version": "4.0.0", "private": true, "description": "Facilitates 'ChatOps' by creating dispatch events for slash commands", "main": "lib/main.js", diff --git a/src/command-helper.ts b/src/command-helper.ts index 42e7b3db3..6c2f31bac 100644 --- a/src/command-helper.ts +++ b/src/command-helper.ts @@ -155,28 +155,23 @@ export function getCommandsConfigFromJson(json: string): Command[] { return config } -export function configIsValid(config: Command[]): boolean { +export function configIsValid(config: Command[]): string | null { for (const command of config) { if ( !['none', 'read', 'triage', 'write', 'maintain', 'admin'].includes( command.permission ) ) { - core.setFailed(`'${command.permission}' is not a valid 'permission'.`) - return false + return `'${command.permission}' is not a valid 'permission'.` } if (!['issue', 'pull-request', 'both'].includes(command.issue_type)) { - core.setFailed(`'${command.issue_type}' is not a valid 'issue-type'.`) - return false + return `'${command.issue_type}' is not a valid 'issue-type'.` } if (!['repository', 'workflow'].includes(command.dispatch_type)) { - core.setFailed( - `'${command.dispatch_type}' is not a valid 'dispatch-type'.` - ) - return false + return `'${command.dispatch_type}' is not a valid 'dispatch-type'.` } } - return true + return null } export function actorHasPermission( diff --git a/src/main.ts b/src/main.ts index 889ac831d..86fb5a856 100644 --- a/src/main.ts +++ b/src/main.ts @@ -45,7 +45,10 @@ async function run(): Promise { core.debug(`Commands config: ${inspect(config)}`) // Check the config is valid - if (!configIsValid(config)) return + const configError = configIsValid(config) + if (configError) { + throw new Error(configError) + } // Get the comment body and id const commentBody: string = github.context.payload.comment.body