diff --git a/README.md b/README.md index 3cb76f1..3504fd8 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,11 @@ A GitHub Action for reporting benchmark data and comparing it against a baseline ## The basics -This action reads benchmark metrics on GitHub pull requests and commits, and reports them by adding a comment with any metrics found. It also compares then against the latest commit on the main branch, treating it as the baseline. +This action reads benchmark metrics on GitHub pull requests and commits, and reports them by adding a comment with any +metrics found. It also compares then against the latest commit on the main branch, treating it as the baseline. -The action looks for benchmark data in files on the repository root. These should be named in the format `.delta.` — e.g. `.delta.install_time` will create a metric called `install_time`. +The action looks for benchmark data in files on the repository root. These should be named in the format +`.delta.` — e.g. `.delta.install_time` will create a metric called `install_time`. These files should contain: @@ -17,6 +19,7 @@ These files should contain: - A human-friendly name of the metric (optional) _Example: `.delta.install_time`_ + ``` 350ms (Installation time) ``` @@ -29,17 +32,19 @@ The units will determine how the values will be formatted in the benchmark repor - Storage (formatted with [`pretty-bytes`](https://www.npmjs.com/package/pretty-bytes)) - `b` / `bytes` - `kb` / `kilobytes` -- Unitless (formatted with [`Number.prototype.toLocaleString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)) +- Unitless (formatted with + [`Number.prototype.toLocaleString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)) ## Configuration -The action supports the following inputs: +The action supports the following optional inputs: -| Name | Description | Default | -| ------------- | ---------------------------------------- | -------------------- | -| `base_branch` | Name of the base branch | `main` | -| `title` | Title/heading to include in the comments | Delta results | -| `token` | GitHub access token | | +| Name | Description | Default | +| ------------- | ------------------------------------------------------- | ------------- | +| `base_branch` | Name of the base branch, if not auto detected | autodetect | +| `title` | Title/heading to include in the comments | Delta results | +| `token` | GitHub access token | GITHUB_TOKEN | +| `pr_number` | The PR this run is associated with (for `workflow_run`) | autodetect | ## Usage diff --git a/action.yml b/action.yml index 175865b..0fd1766 100644 --- a/action.yml +++ b/action.yml @@ -4,12 +4,19 @@ inputs: base_branch: default: main description: 'Name of the base branch' + required: false title: default: Delta results description: 'Title used in the comments' + required: false token: description: 'GitHub access token' - required: true + required: false + default: ${{ github.token }} + pr_number: + description: 'The PR this run is associated with (for `workflow_run`)' + required: false + default: '' runs: using: 'node16' main: 'dist/index.js' diff --git a/src/lib/inputs.js b/src/lib/inputs.js index 4e79813..1f18071 100644 --- a/src/lib/inputs.js +++ b/src/lib/inputs.js @@ -10,12 +10,9 @@ const getPrNumber = () => { return payload.number } - if ( - eventName === 'workflow_run' && - payload?.workflow_run?.event === 'pull_request' && - payload?.workflow_run?.pull_requests?.length === 1 - ) { - return payload.workflow_run.pull_requests[0].number + const prNumberInput = Number.parseInt(core.getInput('pr_number')) + if (Number.isInteger(prNumberInput)) { + return prNumberInput } } @@ -23,14 +20,13 @@ export const getInputs = () => { const { GITHUB_DEV_BASE_BRANCH: envBaseBranch, GITHUB_REPOSITORY: repository, - GITHUB_TOKEN: envToken, GITHUB_WORKSPACE: rootPath = process.cwd(), } = process.env const { job, ref, sha: commitSha } = context const baseBranch = envBaseBranch || core.getInput('base_branch') - const title = core.getInput('title') + const title = core.getInput('title', { required: true }) const [owner, repo] = repository.split('/') - const token = envToken || core.getInput('token') + const token = core.getInput('token', { required: true }) const prNumber = getPrNumber() return {