diff --git a/README.md b/README.md index f21584a..b79fcb9 100644 --- a/README.md +++ b/README.md @@ -179,3 +179,32 @@ By default, files are compared after gzip compression, but it's possible to use ```yaml compression: "none" ``` + +### Checking multiple bundles + +The action reuses the same comment each time it runs on a PR. In order to run the action multiple times against separate bundles for a single PR, you must provide a `comment-key` option, which the action will use to determine which comment to add or update for the run. The example below demonstrates this for separate "modern" and "legacy" bundles: + +```diff +name: Compressed Size +on: [pull_request] +jobs: + modern-bundle-size-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: preactjs/compressed-size-action@v2 + with: + build-script: "build:modern" ++ comment-key: modern + + legacy-bundle-size-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: preactjs/compressed-size-action@v2 + with: + build-script: "build:legacy" ++ comment-key: legacy +``` + +If you do not provide this key, the action will attempt to use (and therefore replace) the same comment for both bundles, hiding the output for whichever run finished last. diff --git a/action.yml b/action.yml index e3ea5f4..3ebf27e 100644 --- a/action.yml +++ b/action.yml @@ -42,6 +42,9 @@ inputs: default: '{**/*.map,**/node_modules/**}' cwd: description: 'A custom working directory to execute the action in relative to repo root (defaults to .)' + comment-key: + description: 'Optional key to include in the bot comment to allow for multiple bundle calculations to be posted in separate comments.' + runs: using: 'node20' main: 'index.js' \ No newline at end of file diff --git a/src/index.js b/src/index.js index 8d897a2..93d021d 100644 --- a/src/index.js +++ b/src/index.js @@ -185,11 +185,13 @@ async function run(octokit, context, token) { issue_number: pull_number }; + const commentKey = getInput('comment-key') + const comment = { ...commentInfo, body: markdownDiff + - '\n\ncompressed-size-action' + `\n\ncompressed-size-action${commentKey ? `::${commentKey}` : ''}` }; if (context.eventName !== 'pull_request' && context.eventName !== 'pull_request_target') { @@ -213,9 +215,10 @@ async function run(octokit, context, token) { let commentId; try { const comments = (await octokit.issues.listComments(commentInfo)).data; + const commentRegExp = new RegExp(`[\s\n]*(compressed|gzip)-size-action${commentKey ? `::${commentKey}` : ''}`) for (let i = comments.length; i--; ) { const c = comments[i]; - if (/[\s\n]*(compressed|gzip)-size-action/.test(c.body)) { + if (commentRegExp.test(c.body)) { commentId = c.id; break; }