Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Junk: Test comment key #112

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ jobs:
uses: ./
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
pattern: index.js
comment-key: "key-1"
pattern: index.js
- name: Report Compressed Size 2
uses: ./
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
comment-key: "key-2"
pattern: src/index.js
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
9 changes: 7 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { exec } from '@actions/exec';
import SizePlugin from 'size-plugin-core';
import { fileExists, diffTable, toBool, stripHash } from './utils.js';

// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

/**
* @typedef {ReturnType<typeof import("@actions/github").getOctokit>} Octokit
* @typedef {typeof import("@actions/github").context} ActionContext
Expand Down Expand Up @@ -185,11 +187,13 @@ async function run(octokit, context, token) {
issue_number: pull_number
};

const commentKey = getInput('comment-key')

const comment = {
...commentInfo,
body:
markdownDiff +
'\n\n<a href="https://github.com/preactjs/compressed-size-action"><sub>compressed-size-action</sub></a>'
`\n\n<a href="https://github.com/preactjs/compressed-size-action"><sub>compressed-size-action${commentKey ? `::${commentKey}` : ''}</sub></a>`
};

if (context.eventName !== 'pull_request' && context.eventName !== 'pull_request_target') {
Expand All @@ -213,9 +217,10 @@ async function run(octokit, context, token) {
let commentId;
try {
const comments = (await octokit.issues.listComments(commentInfo)).data;
const commentRegExp = new RegExp(`<sub>[\s\n]*(compressed|gzip)-size-action${commentKey ? `::${commentKey}` : ''}</sub>`)
for (let i = comments.length; i--; ) {
const c = comments[i];
if (c.user.type === 'Bot' && /<sub>[\s\n]*(compressed|gzip)-size-action/.test(c.body)) {
if (c.user.type === 'Bot' && commentRegExp.test(c.body)) {
commentId = c.id;
break;
}
Expand Down
Loading