From f6b06099722c33381fa224c71f2f869b36623137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= Date: Fri, 21 Feb 2025 02:14:59 +0100 Subject: [PATCH 1/7] ci: add version to pr comment --- .github/scripts/preview-comment.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/scripts/preview-comment.js b/.github/scripts/preview-comment.js index 9d4262e..22c2519 100644 --- a/.github/scripts/preview-comment.js +++ b/.github/scripts/preview-comment.js @@ -14,7 +14,7 @@ const generateUrls = ({ sha, owner, repo, commitUrl = null, prNumber = null }) = } } -const generateCommentBody = ({ sha, owner, repo, commitUrl, prNumber }) => { +const generateCommentBody = ({ sha, owner, repo, commitUrl, prNumber, version }) => { const { shortSha, shortUrl } = generateUrls({ sha, owner, repo, commitUrl, prNumber }) return `${BOT_COMMENT_IDENTIFIER} @@ -24,7 +24,13 @@ Try this version: bun add -g ${shortUrl} \`\`\` -###### _[${shortSha}](${commitUrl})_` +###### _[${shortSha}](${commitUrl})_ **_v${version}_**` +} + +const getNextVersion = (existingComment) => { + if (!existingComment) return 1 + const vIndex = existingComment.body.lastIndexOf("v") + return Number(existingComment.body.slice(vIndex + 1)) + 1 } const findBotComment = async ({ github, context, issueNumber }) => { @@ -96,7 +102,10 @@ const handlePush = async ({ logger, github, context, body, output, commitUrl }) export async function run(github, context, core) { const output = JSON.parse(readFileSync("output.json", "utf8")) - const sha = context.eventName === "pull_request" ? context.payload.pull_request.head.sha : context.payload.after + const sha = + context.eventName === "pull_request" + ? context.payload.pull_request.head.sha + : context.payload.after const prNumber = context.eventName === "pull_request" ? context.payload.pull_request.number : null const { commitUrl } = generateUrls({ @@ -106,12 +115,19 @@ export async function run(github, context, core) { prNumber, }) + const existingComment = await findBotComment({ + github, + context, + issueNumber: prNumber || context.issue.number, + }) + const body = generateCommentBody({ sha, owner: context.repo.owner, repo: context.repo.repo, commitUrl, prNumber, + version: getNextVersion(existingComment), }) const handlers = { From 5364dd5881a1a2975b786d639c729c02cfe8b569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= Date: Fri, 21 Feb 2025 02:18:54 +0100 Subject: [PATCH 2/7] refactor: change format --- .github/scripts/preview-comment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/preview-comment.js b/.github/scripts/preview-comment.js index 22c2519..c722970 100644 --- a/.github/scripts/preview-comment.js +++ b/.github/scripts/preview-comment.js @@ -24,7 +24,7 @@ Try this version: bun add -g ${shortUrl} \`\`\` -###### _[${shortSha}](${commitUrl})_ **_v${version}_**` +###### _[v${version} — ${shortSha}](${commitUrl})_ **_v${version}_**` } const getNextVersion = (existingComment) => { From 04107ef079123690fbea3fb893bd5c03d3f83984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= Date: Fri, 21 Feb 2025 02:20:37 +0100 Subject: [PATCH 3/7] fix: wip fix --- .github/scripts/preview-comment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/preview-comment.js b/.github/scripts/preview-comment.js index c722970..c485ff4 100644 --- a/.github/scripts/preview-comment.js +++ b/.github/scripts/preview-comment.js @@ -24,7 +24,7 @@ Try this version: bun add -g ${shortUrl} \`\`\` -###### _[v${version} — ${shortSha}](${commitUrl})_ **_v${version}_**` +###### _[v${version} — ${shortSha}](${commitUrl})_` } const getNextVersion = (existingComment) => { From d1a7355c4785ded69127ff2d20450e844bc7f026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= Date: Fri, 21 Feb 2025 02:24:25 +0100 Subject: [PATCH 4/7] fix: wip fix --- .github/scripts/preview-comment.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/scripts/preview-comment.js b/.github/scripts/preview-comment.js index c485ff4..16072fb 100644 --- a/.github/scripts/preview-comment.js +++ b/.github/scripts/preview-comment.js @@ -28,9 +28,12 @@ bun add -g ${shortUrl} } const getNextVersion = (existingComment) => { - if (!existingComment) return 1 - const vIndex = existingComment.body.lastIndexOf("v") - return Number(existingComment.body.slice(vIndex + 1)) + 1 + if (!existingComment?.body) return 1 + + const match = existingComment.body.match(/v(\d+) —/) + + const currentVersion = Number.parseInt(match[1], 10) + return currentVersion + 1 } const findBotComment = async ({ github, context, issueNumber }) => { From 481df85a97d7df5706d85a86c14cb6b2fc0d7310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= Date: Fri, 21 Feb 2025 02:32:30 +0100 Subject: [PATCH 5/7] ci: add test workflow --- .github/workflows/test.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..08af527 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,19 @@ +name: Test +on: + pull_request: + push: + branches: ["main"] +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Bun + uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + - name: Install dependencies + run: bun install + - name: Run tests + run: bun test From b432495ee8920dad68009153f33f41af344ee1f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= Date: Fri, 21 Feb 2025 02:34:47 +0100 Subject: [PATCH 6/7] chore: test change --- .github/scripts/preview-comment.js | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/scripts/preview-comment.js b/.github/scripts/preview-comment.js index 16072fb..b878bcd 100644 --- a/.github/scripts/preview-comment.js +++ b/.github/scripts/preview-comment.js @@ -29,7 +29,6 @@ bun add -g ${shortUrl} const getNextVersion = (existingComment) => { if (!existingComment?.body) return 1 - const match = existingComment.body.match(/v(\d+) —/) const currentVersion = Number.parseInt(match[1], 10) From 203c7256480f8d33a7e1e073c2d14f2442d2dd64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= Date: Fri, 21 Feb 2025 02:35:58 +0100 Subject: [PATCH 7/7] chore: anothe test change --- .github/scripts/preview-comment.js | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/scripts/preview-comment.js b/.github/scripts/preview-comment.js index b878bcd..e367fd2 100644 --- a/.github/scripts/preview-comment.js +++ b/.github/scripts/preview-comment.js @@ -30,7 +30,6 @@ bun add -g ${shortUrl} const getNextVersion = (existingComment) => { if (!existingComment?.body) return 1 const match = existingComment.body.match(/v(\d+) —/) - const currentVersion = Number.parseInt(match[1], 10) return currentVersion + 1 }