feat: update runtime to node 20 (#316)

* feat: update runtime to node 20

* fix jest exit code issue
This commit is contained in:
Peter Evans
2024-01-31 19:33:27 +09:00
committed by GitHub
parent 128d8b9272
commit 13bc09769d
17 changed files with 110 additions and 65 deletions
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
@@ -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 [email protected]
- 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
+7 -7
View File
@@ -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 }}
+11 -5
View File
@@ -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 () => {
+1 -1
View File
@@ -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'
+8 -9
View File
@@ -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;
+3 -3
View File
@@ -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
+14 -14
View File
@@ -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 [\<args\> ...] | Echos back a list of arguments
> /hello-world-local | Receive a greeting from the world (local execution)
> /ping-local [\<args\> ...] | Echos back a list of arguments (local execution)
reaction-type: hooray
reactions: hooray
```
+3 -3
View File
@@ -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
+12 -1
View File
@@ -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/[email protected]/admin/release-notes) or later.
+5 -5
View File
@@ -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: |
+2 -2
View File
@@ -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",
+1 -1
View File
@@ -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",
+5 -10
View File
@@ -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(
+4 -1
View File
@@ -45,7 +45,10 @@ async function run(): Promise<void> {
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