|
9 | 9 |
|
10 | 10 | permissions:
|
11 | 11 | statuses: write
|
| 12 | + pull-requests: write |
12 | 13 |
|
13 | 14 | jobs:
|
14 | 15 | report-success:
|
|
62 | 63 | target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}'
|
63 | 64 | })).data;
|
64 | 65 | core.info(`${name} is ${state}`);
|
| 66 | +
|
| 67 | + manage-labels: |
| 68 | + name: Manage PR labels |
| 69 | + if: github.event.workflow_run.event == 'pull_request' |
| 70 | + runs-on: ubuntu-latest |
| 71 | + steps: |
| 72 | + - name: Download and Extract Artifacts |
| 73 | + uses: dawidd6/action-download-artifact@07ab29fd4a977ae4d2b275087cf67563dfdf0295 # v9 |
| 74 | + continue-on-error: true |
| 75 | + with: |
| 76 | + run_id: ${{ github.event.workflow_run.id }} |
| 77 | + name: pr-artifacts |
| 78 | + path: ./pr-artifacts |
| 79 | + |
| 80 | + - name: Get PR information |
| 81 | + id: pr-info |
| 82 | + run: | |
| 83 | + if [ -f "./pr-artifacts/pr_number.txt" ]; then |
| 84 | + pr_number=$(cat ./pr-artifacts/pr_number.txt | tr -cd '[:digit:]') |
| 85 | + pre_commit_outcome=$(cat ./pr-artifacts/pre_commit_outcome.txt | tr -cd '[:alpha:]_') |
| 86 | + pending_commit=$(cat ./pr-artifacts/pending_commit.txt | tr -cd '[:digit:]') |
| 87 | + has_retrigger_label=$(cat ./pr-artifacts/has_retrigger_label.txt | tr -cd '[:alpha:]') |
| 88 | +
|
| 89 | + echo "pr_number=$pr_number" >> $GITHUB_OUTPUT |
| 90 | + echo "pre_commit_outcome=$pre_commit_outcome" >> $GITHUB_OUTPUT |
| 91 | + echo "pending_commit=$pending_commit" >> $GITHUB_OUTPUT |
| 92 | + echo "has_retrigger_label=$has_retrigger_label" >> $GITHUB_OUTPUT |
| 93 | + echo "artifacts_found=true" >> $GITHUB_OUTPUT |
| 94 | +
|
| 95 | + echo "PR number: $pr_number" |
| 96 | + echo "Pre-commit outcome: $pre_commit_outcome" |
| 97 | + echo "Pending commit: $pending_commit" |
| 98 | + echo "Has retrigger label: $has_retrigger_label" |
| 99 | + else |
| 100 | + echo "No PR artifacts found" |
| 101 | + echo "artifacts_found=false" >> $GITHUB_OUTPUT |
| 102 | + fi |
| 103 | +
|
| 104 | + - name: Remove re-trigger label if it was present |
| 105 | + if: | |
| 106 | + steps.pr-info.outputs.artifacts_found == 'true' && |
| 107 | + steps.pr-info.outputs.has_retrigger_label == 'true' |
| 108 | + continue-on-error: true |
| 109 | + run: | |
| 110 | + gh pr edit ${{ steps.pr-info.outputs.pr_number }} --repo ${{ github.repository }} --remove-label 'Re-trigger Pre-commit Hooks' |
| 111 | + env: |
| 112 | + GH_TOKEN: ${{ github.token }} |
| 113 | + |
| 114 | + - name: Add label if pre-commit fixes are required |
| 115 | + if: | |
| 116 | + steps.pr-info.outputs.artifacts_found == 'true' && |
| 117 | + steps.pr-info.outputs.pre_commit_outcome == 'failure' && |
| 118 | + steps.pr-info.outputs.pending_commit == '0' |
| 119 | + continue-on-error: true |
| 120 | + run: | |
| 121 | + gh pr edit ${{ steps.pr-info.outputs.pr_number }} --repo ${{ github.repository }} --add-label 'Status: Pre-commit fixes required ⚠️' |
| 122 | + env: |
| 123 | + GH_TOKEN: ${{ github.token }} |
| 124 | + |
| 125 | + - name: Remove label if pre-commit was successful |
| 126 | + if: | |
| 127 | + steps.pr-info.outputs.artifacts_found == 'true' && |
| 128 | + steps.pr-info.outputs.pre_commit_outcome == 'success' |
| 129 | + continue-on-error: true |
| 130 | + run: | |
| 131 | + gh pr edit ${{ steps.pr-info.outputs.pr_number }} --repo ${{ github.repository }} --remove-label 'Status: Pre-commit fixes required ⚠️' |
| 132 | + env: |
| 133 | + GH_TOKEN: ${{ github.token }} |
0 commit comments