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

infra: remove preflight failure comment #3188

Merged
merged 15 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
73 changes: 0 additions & 73 deletions .github/workflows/commentCodeGeneration.ts
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

68 changes: 65 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
});
}
}
45 changes: 0 additions & 45 deletions .github/workflows/preflight-comment.yml

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading