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

updated failed preview deploy #9884

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
53 changes: 28 additions & 25 deletions .github/workflows/label-deploy-failed.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
name: Auto label failed preview deploys

name: Auto label deploy preview status
permissions:
pull-requests: write
issues: write

on:
issue_comment:
types:
- created
- edited
types: [created, edited]

jobs:
auto-label-deploy-failed:
manage-deploy-labels:
runs-on: ubuntu-latest
if: |
github.repository == 'ohcnetwork/care_fe' && github.event.issue.pull_request &&
github.repository == 'ohcnetwork/care_fe' &&
github.event.issue.pull_request &&
contains(github.event.comment.body, 'Deploy Preview')

steps:
- name: Add 'Deploy-Failed'
if: contains(github.event.comment.body, 'failed')
- name: Check out the repository
uses: actions/checkout@v3

- name: Check deploy status
Comment on lines +19 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Update checkout action version.

The actions/checkout action has a newer version available.

-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Check out the repository
uses: actions/checkout@v3
- name: Check out the repository
uses: actions/checkout@v4
🧰 Tools
🪛 actionlint (1.7.4)

20-20: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

id: check-status
uses: actions/github-script@v6
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["Deploy-Failed"]
})
const comment = context.payload.comment.body;
return {
isDeployFailed: /deploy preview.*failed|failed to deploy/i.test(comment),
isDeploySuccessful: /deploy preview.*ready|successfully deployed/i.test(comment),
};

Comment on lines +22 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve deploy status check robustness.

The current implementation has several potential improvements:

  1. The github-script action should be updated to v7
  2. The output needs proper JSON stringification
  3. The regex patterns could be more precise
       - name: Check deploy status
         id: check-status
-        uses: actions/github-script@v6
+        uses: actions/github-script@v7
         with:
           script: |
             const comment = context.payload.comment.body;
-            return {
+            core.setOutput('result', JSON.stringify({
               isDeployFailed: /deploy preview.*failed|failed to deploy/i.test(comment),
               isDeploySuccessful: /deploy preview.*ready|successfully deployed/i.test(comment),
-            };
+            }));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Check deploy status
id: check-status
uses: actions/github-script@v6
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["Deploy-Failed"]
})
const comment = context.payload.comment.body;
return {
isDeployFailed: /deploy preview.*failed|failed to deploy/i.test(comment),
isDeploySuccessful: /deploy preview.*ready|successfully deployed/i.test(comment),
};
- name: Check deploy status
id: check-status
uses: actions/github-script@v7
with:
script: |
const comment = context.payload.comment.body;
core.setOutput('result', JSON.stringify({
isDeployFailed: /deploy preview.*failed|failed to deploy/i.test(comment),
isDeploySuccessful: /deploy preview.*ready|successfully deployed/i.test(comment),
}));
🧰 Tools
🪛 actionlint (1.7.4)

24-24: the runner of "actions/github-script@v6" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

- name: Remove 'Deploy-Failed' label
if: contains(github.event.comment.body, 'ready')
uses: actions/github-script@v6
- name: Add Deploy-Failed label if needed
if: steps.check-status.outputs.isDeployFailed == 'true'
uses: actions/labeler@v5
with:
script: |
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["Deploy-Failed"]
})
repo-token: "${{ secrets.GITHUB_TOKEN }}"

- name: Remove Deploy-Failed label if deploy is successful
Comment on lines +33 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

The review comment is correct - actions/labeler@v5 is the wrong action for this use case

The actions/labeler@v5 action is designed for pattern-based PR labeling and requires a labeler.yml configuration file. For adding a single "Deploy-Failed" label, you should use a simpler approach like actions/github-script or a dedicated label action similar to how the merge conflict workflow uses a specialized action.

Example fix:

      - name: Add Deploy-Failed label if needed
        if: steps.check-status.outputs.isDeployFailed == 'true'
        uses: actions/github-script@v6
        with:
          script: |
            github.rest.issues.addLabels({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.name,
              labels: ['Deploy-Failed']
            })
🔗 Analysis chain

Verify labeler configuration.

The actions/labeler@v5 usage appears incomplete. It requires a configuration file to specify label rules.

Please ensure you have a .github/labeler.yml file with appropriate rules. Run this script to check:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for labeler configuration
if [ -f ".github/labeler.yml" ]; then
  cat ".github/labeler.yml"
else
  echo "Warning: labeler.yml not found"
fi

Length of output: 103


Script:

#!/bin/bash
# Search for any label-related configuration files
fd -e yml -e yaml . .github/ | grep -i label

# Search for label-related actions in workflows
rg -l "label" .github/workflows/

Length of output: 534


Script:

#!/bin/bash
# Check implementation in other label workflows
for file in .github/workflows/label-*.yml .github/workflows/auto-testing-label.yml; do
  echo "=== $file ==="
  rg "uses:.*label" "$file" -A 2
done

Length of output: 1235

if: steps.check-status.outputs.isDeploySuccessful == 'true'
run: |
curl -X DELETE \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/labels/Deploy-Failed
Loading