From 25f52d77cceca2f1ba5a4a150bc11b88e18716e7 Mon Sep 17 00:00:00 2001 From: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com> Date: Thu, 16 Jun 2022 13:16:45 +1000 Subject: [PATCH 1/5] Add comment-key input --- action.yml | 3 +++ src/index.js | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 25e0b6f..5e513f7 100644 --- a/action.yml +++ b/action.yml @@ -39,6 +39,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 mutliple bundle calculations to be posted in separate comments.' + runs: using: 'node12' main: 'index.js' diff --git a/src/index.js b/src/index.js index db19514..e773ba1 100644 --- a/src/index.js +++ b/src/index.js @@ -169,11 +169,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') { @@ -197,9 +199,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 (c.user.type === 'Bot' && /[\s\n]*(compressed|gzip)-size-action/.test(c.body)) { + if (c.user.type === 'Bot' && commentRegExp.test(c.body)) { commentId = c.id; break; } From 3ef50203b54ae6932f62cfa758b1d762c3f58aae Mon Sep 17 00:00:00 2001 From: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com> Date: Wed, 12 Jul 2023 16:40:10 +1000 Subject: [PATCH 2/5] Fix typo Co-authored-by: Bruno Bodian --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 5e513f7..e5848b9 100644 --- a/action.yml +++ b/action.yml @@ -40,7 +40,7 @@ inputs: 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 mutliple bundle calculations to be posted in separate comments.' + description: 'Optional key to include in the bot comment to allow for multiple bundle calculations to be posted in separate comments.' runs: using: 'node12' From d292e11408a70e7f4ae40f652c493c8a6699fef4 Mon Sep 17 00:00:00 2001 From: sarayourfriend Date: Thu, 26 Sep 2024 09:30:43 -0600 Subject: [PATCH 3/5] Prevent mixing up comments with and without keys --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index e773ba1..93d3cdc 100644 --- a/src/index.js +++ b/src/index.js @@ -199,7 +199,7 @@ 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}` : ''}`) + const commentRegExp = new RegExp(`[\s\n]*(compressed|gzip)-size-action${commentKey ? `::${commentKey}` : ''}`) for (let i = comments.length; i--; ) { const c = comments[i]; if (c.user.type === 'Bot' && commentRegExp.test(c.body)) { From 2fc32c127313f22529f026ae858e5fd1a17a154c Mon Sep 17 00:00:00 2001 From: sarayourfriend Date: Thu, 26 Sep 2024 19:10:05 -0600 Subject: [PATCH 4/5] Add docs to readme for the comment-key option --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/README.md b/README.md index f21584a..6794556 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: + +```yaml +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. From 53ce63f9af30956fb7960986a2436aa43a8e406b Mon Sep 17 00:00:00 2001 From: Ryan Christian <33403762+rschristian@users.noreply.github.com> Date: Thu, 26 Sep 2024 20:30:45 -0500 Subject: [PATCH 5/5] Apply suggestions from code review --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6794556..b79fcb9 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ compression: "none" 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: -```yaml +```diff name: Compressed Size on: [pull_request] jobs: @@ -195,7 +195,7 @@ jobs: - uses: preactjs/compressed-size-action@v2 with: build-script: "build:modern" - comment-key: modern ++ comment-key: modern legacy-bundle-size-check: runs-on: ubuntu-latest @@ -204,7 +204,7 @@ jobs: - uses: preactjs/compressed-size-action@v2 with: build-script: "build:legacy" - comment-key: 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.