Skip to content

Commit

Permalink
feat: update runtime to node 20 (#316)
Browse files Browse the repository at this point in the history
* feat: update runtime to node 20

* fix jest exit code issue
  • Loading branch information
peter-evans committed Jan 31, 2024
1 parent 128d8b9 commit 13bc097
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hello-world-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ping-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 31 additions & 0 deletions .github/workflows/update-major-version.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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: |
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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: |
Expand Down Expand Up @@ -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.
Expand All @@ -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 }}
Expand Down
16 changes: 11 additions & 5 deletions __test__/command-helper.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -185,23 +187,27 @@ 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 () => {
const config: Command[] = [
{
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',
static_args: [],
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 () => {
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
17 changes: 8 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions docs/advanced-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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: >
Expand Down Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 }}
Expand All @@ -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
```
6 changes: 3 additions & 3 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion docs/updating.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
## Updating from `v2` to `v3`
## Updating from `v3` to `v4`

### Breaking changes

- If using self-hosted runners or GitHub Enterprise Server, there are minimum requirements for `v4` to run. See "What's new" below for details.

### 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.
Expand Down

0 comments on commit 13bc097

Please sign in to comment.