diff options
Diffstat (limited to '.github/workflows')
| -rw-r--r-- | .github/workflows/commentCodeGeneration.ts | 73 | ||||
| -rw-r--r-- | .github/workflows/pr.yml | 2 | ||||
| -rw-r--r-- | .github/workflows/preflight-comment.yml | 45 |
3 files changed, 1 insertions, 119 deletions
diff --git a/.github/workflows/commentCodeGeneration.ts b/.github/workflows/commentCodeGeneration.ts deleted file mode 100644 index 2e8a115c..00000000 --- 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<typeof GitHub>, - context: typeof ctx -): Promise<void> { - 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 26b3967c..25c7cf5d 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -11,8 +11,8 @@ jobs: check-code-generation: runs-on: ubuntu-latest timeout-minutes: 10 - name: 'Check Code Generation: node-22, ubuntu-latest' + name: 'Check Code Generation: node-22, ubuntu-latest' steps: - name: Checkout uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 diff --git a/.github/workflows/preflight-comment.yml b/.github/workflows/preflight-comment.yml deleted file mode 100644 index ec25271c..00000000 --- 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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - ref: 'next' - - - name: Install pnpm - uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 - - - name: Set node version to 22 - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 - 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) |
