From f3283300df49f70783b208a7792610f77a12ca2a Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Wed, 16 Oct 2024 20:41:43 +0200 Subject: [PATCH 1/2] infra: inline preflight script --- .github/workflows/commentCodeGeneration.ts | 73 ---------- .github/workflows/pr.yml | 68 ++++++++- .github/workflows/preflight-comment.yml | 45 ------ package.json | 1 - pnpm-lock.yaml | 162 --------------------- 5 files changed, 65 insertions(+), 284 deletions(-) delete mode 100644 .github/workflows/commentCodeGeneration.ts delete mode 100644 .github/workflows/preflight-comment.yml diff --git a/.github/workflows/commentCodeGeneration.ts b/.github/workflows/commentCodeGeneration.ts deleted file mode 100644 index 2e8a115cd18..00000000000 --- a/.github/workflows/commentCodeGeneration.ts +++ /dev/null @@ -1,73 +0,0 @@ -import type { context as ctx, GitHub } from '@actions/github/lib/utils'; - -/** - * Notifies the PR about uncommitted changes generated by the `generate:*` commands. - * - * This script is used by github-script - * https://github.com/actions/github-script - * - * @param github A pre-authenticated octokit/rest.js client with pagination plugins - * @param context An object containing the context of the workflow run. - */ -export async function script( - github: InstanceType, - context: typeof ctx -): Promise { - const repoArgs = { owner: context.repo.owner, repo: context.repo.repo }; - - // Identify the PR that triggered the workflow - const head_branch: string = context.payload.workflow_run.head_branch; - const { data: prs } = await github.rest.pulls.list({ - ...repoArgs, - state: 'open', - head: head_branch, - }); - - if (prs.length === 0) { - console.log(`No PRs found for branch ${head_branch}`); - return; - } - - const pr_number = prs[0].number; - - // Check if the PR already has a comment from the bot - - const { data: comments } = await github.rest.issues.listComments({ - ...repoArgs, - issue_number: pr_number, - }); - - const body = `GitHub Actions has found some problems running the preflight checks. - -Please make sure to: - -- run \`pnpm run preflight\` locally -- fix all issues until the command completes without errors -- commit and push the changes -`; - - const botComment = comments.find( - (comment) => comment.user?.type === 'Bot' && comment.body?.includes(body) - ); - - const isSuccess = context.payload.workflow_run.conclusion === 'success'; - - if (isSuccess) { - // Delete the bot comment if present - if (botComment != null) { - await github.rest.issues.deleteComment({ - ...repoArgs, - comment_id: botComment.id, - }); - } - } else { - // Create the comment if missing - if (botComment == null) { - await github.rest.issues.createComment({ - ...repoArgs, - issue_number: pr_number, - body, - }); - } - } -} diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 21fcb1fee0d..dceef571c04 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,22 +1,29 @@ name: PR on: - pull_request: + pull_request_target: -permissions: - contents: read # to fetch code (actions/checkout) +permissions: {} # Permissions per job jobs: check-code-generation: runs-on: ubuntu-latest timeout-minutes: 10 name: 'Check Code Generation: node-22, ubuntu-latest' + permissions: + # Do not add any additional permissions here, as these can be used by third-party contributors + contents: read # to fetch code (actions/checkout) + outputs: + generate: ${{ steps.generate.outcome }} + diff: ${{ steps.diff.outcome }} steps: - name: Checkout uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 with: fetch-depth: 0 + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} - name: Install pnpm uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 @@ -54,3 +61,58 @@ jobs: - name: Status if: ${{ steps.generate.outcome == 'failure' || steps.diff.outcome == 'failure' }} run: exit 1 + + write-comment: + runs-on: ubuntu-latest + timeout-minutes: 1 + name: 'Comment Code Generation' + permissions: + pull-requests: write # to write the comment + needs: check-code-generation + if: ${{ always() }} + + steps: + - name: Write comment + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + with: + script: | + const repoArgs = { owner: context.repo.owner, repo: context.repo.repo }; + const issue_number = context.issue.number; + + // Check if the PR already has a comment from the bot + const { data: comments } = await github.rest.issues.listComments({ + ...repoArgs, + issue_number, + }); + + const body = `GitHub Actions has found some problems running the preflight checks. + Please make sure to: + - run \`pnpm run preflight\` locally + - fix all issues until the command completes without errors + - commit and push the changes + `; + + const botComment = comments.find( + (comment) => comment.user?.type === 'Bot' && comment.body?.includes(body) + ); + + const generateSuccess = ${{ needs.check-code-generation.outputs.generate == 'success' }}; + const diffSuccess = ${{ needs.check-code-generation.outputs.diff == 'success' }}; + if (generateSuccess && diffSuccess) { + // Delete the bot comment if present + if (botComment != null) { + await github.rest.issues.deleteComment({ + ...repoArgs, + comment_id: botComment.id, + }); + } + } else { + // Create the comment if missing + if (botComment == null) { + await github.rest.issues.createComment({ + ...repoArgs, + issue_number, + body, + }); + } + } diff --git a/.github/workflows/preflight-comment.yml b/.github/workflows/preflight-comment.yml deleted file mode 100644 index bb4b103116f..00000000000 --- a/.github/workflows/preflight-comment.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Preflight Comment - -on: - workflow_run: - workflows: 'PR' - types: - - completed - -permissions: - pull-requests: write - -jobs: - comment-code-generation: - runs-on: ubuntu-latest - timeout-minutes: 5 - name: 'Comment Code Generation' - steps: - - name: Checkout - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 - with: - ref: 'next' - - - name: Install pnpm - uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 - - - name: Set node version to 22 - uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4 - with: - node-version: 22 - cache: 'pnpm' - - - name: Install deps - run: pnpm install - env: - CYPRESS_INSTALL_BINARY: 0 - - - name: Transpile ts - run: pnpm tsup-node .github/workflows/commentCodeGeneration.ts --format cjs --clean false --out-dir .github/workflows - - - name: Comment - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 - with: - script: | - const { script } = require('${{ github.workspace }}/.github/workflows/commentCodeGeneration.cjs') - await script(github, context) diff --git a/package.json b/package.json index ec539cbec12..858d5aee33d 100644 --- a/package.json +++ b/package.json @@ -103,7 +103,6 @@ "dist" ], "devDependencies": { - "@actions/github": "6.0.0", "@eslint/compat": "1.2.0", "@eslint/js": "9.12.0", "@stylistic/eslint-plugin": "2.9.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 588f215beeb..a5d91f4b2cb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,9 +8,6 @@ importers: .: devDependencies: - '@actions/github': - specifier: 6.0.0 - version: 6.0.0 '@eslint/compat': specifier: 1.2.0 version: 1.2.0(eslint@9.12.0(jiti@1.21.6)) @@ -128,12 +125,6 @@ importers: packages: - '@actions/github@6.0.0': - resolution: {integrity: sha512-alScpSVnYmjNEXboZjarjukQEzgCRmjMv6Xj47fsdnqGS73bjJNDpiiXmp8jr0UZLdUB6d9jW63IcmddUP+l0g==} - - '@actions/http-client@2.2.3': - resolution: {integrity: sha512-mx8hyJi/hjFvbPokCg4uRd4ZX78t+YyRPtnKWwIl+RzNaVuFpQHfmlGVfsKEJN8LwTCvL+DfVgAM04XaHkm6bA==} - '@algolia/autocomplete-core@1.9.3': resolution: {integrity: sha512-009HdfugtGCdC4JdXUbVJClA0q0zh24yyePn+KUGk3rP7j8FEe/m5Yo/z65gn6nP/cM39PxpzqKrL7A6fP6PPw==} @@ -594,10 +585,6 @@ packages: resolution: {integrity: sha512-vH9PiIMMwvhCx31Af3HiGzsVNULDbyVkHXwlemn/B0TFj/00ho3y55efXrUZTfQipxoHC5u4xq6zblww1zm1Ig==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - '@fastify/busboy@2.1.1': - resolution: {integrity: sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==} - engines: {node: '>=14'} - '@humanfs/core@0.19.0': resolution: {integrity: sha512-2cbWIHbZVEweE853g8jymffCA+NCMiuqeECeBBLm8dg2oFdjuGJhgN4UAbI+6v0CKbbhvtXA4qV8YR5Ji86nmw==} engines: {node: '>=18.18.0'} @@ -656,54 +643,6 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} - '@octokit/auth-token@4.0.0': - resolution: {integrity: sha512-tY/msAuJo6ARbK6SPIxZrPBms3xPbfwBrulZe0Wtr/DIY9lje2HeV1uoebShn6mx7SjCHif6EjMvoREj+gZ+SA==} - engines: {node: '>= 18'} - - '@octokit/core@5.2.0': - resolution: {integrity: sha512-1LFfa/qnMQvEOAdzlQymH0ulepxbxnCYAKJZfMci/5XJyIHWgEYnDmgnKakbTh7CH2tFQ5O60oYDvns4i9RAIg==} - engines: {node: '>= 18'} - - '@octokit/endpoint@9.0.5': - resolution: {integrity: sha512-ekqR4/+PCLkEBF6qgj8WqJfvDq65RH85OAgrtnVp1mSxaXF03u2xW/hUdweGS5654IlC0wkNYC18Z50tSYTAFw==} - engines: {node: '>= 18'} - - '@octokit/graphql@7.1.0': - resolution: {integrity: sha512-r+oZUH7aMFui1ypZnAvZmn0KSqAUgE1/tUXIWaqUCa1758ts/Jio84GZuzsvUkme98kv0WFY8//n0J1Z+vsIsQ==} - engines: {node: '>= 18'} - - '@octokit/openapi-types@20.0.0': - resolution: {integrity: sha512-EtqRBEjp1dL/15V7WiX5LJMIxxkdiGJnabzYx5Apx4FkQIFgAfKumXeYAqqJCj1s+BMX4cPFIFC4OLCR6stlnA==} - - '@octokit/openapi-types@22.2.0': - resolution: {integrity: sha512-QBhVjcUa9W7Wwhm6DBFu6ZZ+1/t/oYxqc2tp81Pi41YNuJinbFRx8B133qVOrAaBbF7D/m0Et6f9/pZt9Rc+tg==} - - '@octokit/plugin-paginate-rest@9.2.1': - resolution: {integrity: sha512-wfGhE/TAkXZRLjksFXuDZdmGnJQHvtU/joFQdweXUgzo1XwvBCD4o4+75NtFfjfLK5IwLf9vHTfSiU3sLRYpRw==} - engines: {node: '>= 18'} - peerDependencies: - '@octokit/core': '5' - - '@octokit/plugin-rest-endpoint-methods@10.4.1': - resolution: {integrity: sha512-xV1b+ceKV9KytQe3zCVqjg+8GTGfDYwaT1ATU5isiUyVtlVAO3HNdzpS4sr4GBx4hxQ46s7ITtZrAsxG22+rVg==} - engines: {node: '>= 18'} - peerDependencies: - '@octokit/core': '5' - - '@octokit/request-error@5.1.0': - resolution: {integrity: sha512-GETXfE05J0+7H2STzekpKObFe765O5dlAKUTLNGeH+x47z7JjXHfsHKo5z21D/o/IOZTUEI6nyWyR+bZVP/n5Q==} - engines: {node: '>= 18'} - - '@octokit/request@8.4.0': - resolution: {integrity: sha512-9Bb014e+m2TgBeEJGEbdplMVWwPmL1FPtggHQRkV+WVsMggPtEkLKPlcVYm/o8xKLkpJ7B+6N8WfQMtDLX2Dpw==} - engines: {node: '>= 18'} - - '@octokit/types@12.6.0': - resolution: {integrity: sha512-1rhSOfRa6H9w4YwK0yrf5faDaDTb+yLyBUKOCV4xtCDB5VmIPqd/v9yr9o6SAzOAlRxMiRiCic6JVM1/kunVkw==} - - '@octokit/types@13.6.1': - resolution: {integrity: sha512-PHZE9Z+kWXb23Ndik8MKPirBPziOc0D2/3KH1P+6jK5nGWe96kadZuE4jev2/Jq7FvIfTlT2Ltg8Fv2x1v0a5g==} - '@pkgjs/parseargs@0.11.0': resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} engines: {node: '>=14'} @@ -1237,9 +1176,6 @@ packages: bcrypt-pbkdf@1.0.2: resolution: {integrity: sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w==} - before-after-hook@2.2.3: - resolution: {integrity: sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==} - binary-extensions@2.3.0: resolution: {integrity: sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==} engines: {node: '>=8'} @@ -1616,9 +1552,6 @@ packages: resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} engines: {node: '>=0.4.0'} - deprecation@2.3.1: - resolution: {integrity: sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==} - dequal@2.0.3: resolution: {integrity: sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==} engines: {node: '>=6'} @@ -3286,10 +3219,6 @@ packages: tunnel-agent@0.6.0: resolution: {integrity: sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==} - tunnel@0.0.6: - resolution: {integrity: sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==} - engines: {node: '>=0.6.11 <=0.7.0 || >=0.7.3'} - tweetnacl@0.14.5: resolution: {integrity: sha512-KXXFFdAbFXY4geFIwoyNK+f5Z1b7swfXABfL7HXCmoIWMKU3dmS26672A4EeQtDzLKy7SXmfBu51JolvEKwtGA==} @@ -3338,10 +3267,6 @@ packages: undici-types@6.19.8: resolution: {integrity: sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==} - undici@5.28.4: - resolution: {integrity: sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==} - engines: {node: '>=14.0'} - unist-util-is@6.0.0: resolution: {integrity: sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==} @@ -3357,9 +3282,6 @@ packages: unist-util-visit@5.0.0: resolution: {integrity: sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==} - universal-user-agent@6.0.1: - resolution: {integrity: sha512-yCzhz6FN2wU1NiiQRogkTQszlQSlpWaw8SvVegAc+bDxbzHgh1vX8uIe8OYyMH6DwH+sdTJsgMl36+mSMdRJIQ==} - universalify@0.2.0: resolution: {integrity: sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==} engines: {node: '>= 4.0.0'} @@ -3630,18 +3552,6 @@ packages: snapshots: - '@actions/github@6.0.0': - dependencies: - '@actions/http-client': 2.2.3 - '@octokit/core': 5.2.0 - '@octokit/plugin-paginate-rest': 9.2.1(@octokit/core@5.2.0) - '@octokit/plugin-rest-endpoint-methods': 10.4.1(@octokit/core@5.2.0) - - '@actions/http-client@2.2.3': - dependencies: - tunnel: 0.0.6 - undici: 5.28.4 - '@algolia/autocomplete-core@1.9.3(@algolia/client-search@4.24.0)(algoliasearch@4.24.0)(search-insights@2.17.2)': dependencies: '@algolia/autocomplete-plugin-algolia-insights': 1.9.3(@algolia/client-search@4.24.0)(algoliasearch@4.24.0)(search-insights@2.17.2) @@ -4024,8 +3934,6 @@ snapshots: dependencies: levn: 0.4.1 - '@fastify/busboy@2.1.1': {} - '@humanfs/core@0.19.0': {} '@humanfs/node@0.16.5': @@ -4079,64 +3987,6 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.17.1 - '@octokit/auth-token@4.0.0': {} - - '@octokit/core@5.2.0': - dependencies: - '@octokit/auth-token': 4.0.0 - '@octokit/graphql': 7.1.0 - '@octokit/request': 8.4.0 - '@octokit/request-error': 5.1.0 - '@octokit/types': 13.6.1 - before-after-hook: 2.2.3 - universal-user-agent: 6.0.1 - - '@octokit/endpoint@9.0.5': - dependencies: - '@octokit/types': 13.6.1 - universal-user-agent: 6.0.1 - - '@octokit/graphql@7.1.0': - dependencies: - '@octokit/request': 8.4.0 - '@octokit/types': 13.6.1 - universal-user-agent: 6.0.1 - - '@octokit/openapi-types@20.0.0': {} - - '@octokit/openapi-types@22.2.0': {} - - '@octokit/plugin-paginate-rest@9.2.1(@octokit/core@5.2.0)': - dependencies: - '@octokit/core': 5.2.0 - '@octokit/types': 12.6.0 - - '@octokit/plugin-rest-endpoint-methods@10.4.1(@octokit/core@5.2.0)': - dependencies: - '@octokit/core': 5.2.0 - '@octokit/types': 12.6.0 - - '@octokit/request-error@5.1.0': - dependencies: - '@octokit/types': 13.6.1 - deprecation: 2.3.1 - once: 1.4.0 - - '@octokit/request@8.4.0': - dependencies: - '@octokit/endpoint': 9.0.5 - '@octokit/request-error': 5.1.0 - '@octokit/types': 13.6.1 - universal-user-agent: 6.0.1 - - '@octokit/types@12.6.0': - dependencies: - '@octokit/openapi-types': 20.0.0 - - '@octokit/types@13.6.1': - dependencies: - '@octokit/openapi-types': 22.2.0 - '@pkgjs/parseargs@0.11.0': optional: true @@ -4711,8 +4561,6 @@ snapshots: dependencies: tweetnacl: 0.14.5 - before-after-hook@2.2.3: {} - binary-extensions@2.3.0: {} birpc@0.2.19: {} @@ -5142,8 +4990,6 @@ snapshots: delayed-stream@1.0.0: {} - deprecation@2.3.1: {} - dequal@2.0.3: {} detect-indent@6.1.0: {} @@ -6885,8 +6731,6 @@ snapshots: dependencies: safe-buffer: 5.2.1 - tunnel@0.0.6: {} - tweetnacl@0.14.5: {} type-check@0.4.0: @@ -6921,10 +6765,6 @@ snapshots: undici-types@6.19.8: {} - undici@5.28.4: - dependencies: - '@fastify/busboy': 2.1.1 - unist-util-is@6.0.0: dependencies: '@types/unist': 3.0.3 @@ -6948,8 +6788,6 @@ snapshots: unist-util-is: 6.0.0 unist-util-visit-parents: 6.0.1 - universal-user-agent@6.0.1: {} - universalify@0.2.0: {} universalify@2.0.1: {} From ee45594a88e85f9dc888eac08c7ebd5979a765d1 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sat, 26 Oct 2024 18:51:56 +0200 Subject: [PATCH 2/2] chore: remove comment --- .github/workflows/pr.yml | 70 +++------------------------------------- 1 file changed, 4 insertions(+), 66 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index dceef571c04..6811b0c52d4 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,29 +1,22 @@ name: PR on: - pull_request_target: + pull_request: -permissions: {} # Permissions per job +permissions: + contents: read # to fetch code (actions/checkout) jobs: check-code-generation: runs-on: ubuntu-latest timeout-minutes: 10 - name: 'Check Code Generation: node-22, ubuntu-latest' - permissions: - # Do not add any additional permissions here, as these can be used by third-party contributors - contents: read # to fetch code (actions/checkout) - outputs: - generate: ${{ steps.generate.outcome }} - diff: ${{ steps.diff.outcome }} + name: 'Check Code Generation: node-22, ubuntu-latest' steps: - name: Checkout uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 with: fetch-depth: 0 - ref: ${{ github.event.pull_request.head.ref }} - repository: ${{ github.event.pull_request.head.repo.full_name }} - name: Install pnpm uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 @@ -61,58 +54,3 @@ jobs: - name: Status if: ${{ steps.generate.outcome == 'failure' || steps.diff.outcome == 'failure' }} run: exit 1 - - write-comment: - runs-on: ubuntu-latest - timeout-minutes: 1 - name: 'Comment Code Generation' - permissions: - pull-requests: write # to write the comment - needs: check-code-generation - if: ${{ always() }} - - steps: - - name: Write comment - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 - with: - script: | - const repoArgs = { owner: context.repo.owner, repo: context.repo.repo }; - const issue_number = context.issue.number; - - // Check if the PR already has a comment from the bot - const { data: comments } = await github.rest.issues.listComments({ - ...repoArgs, - issue_number, - }); - - const body = `GitHub Actions has found some problems running the preflight checks. - Please make sure to: - - run \`pnpm run preflight\` locally - - fix all issues until the command completes without errors - - commit and push the changes - `; - - const botComment = comments.find( - (comment) => comment.user?.type === 'Bot' && comment.body?.includes(body) - ); - - const generateSuccess = ${{ needs.check-code-generation.outputs.generate == 'success' }}; - const diffSuccess = ${{ needs.check-code-generation.outputs.diff == 'success' }}; - if (generateSuccess && diffSuccess) { - // Delete the bot comment if present - if (botComment != null) { - await github.rest.issues.deleteComment({ - ...repoArgs, - comment_id: botComment.id, - }); - } - } else { - // Create the comment if missing - if (botComment == null) { - await github.rest.issues.createComment({ - ...repoArgs, - issue_number, - body, - }); - } - }