|
8 | 8 | types: [opened, synchronize, reopened, closed, labeled] |
9 | 9 | workflow_dispatch: |
10 | 10 |
|
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + issues: write # For label revoke |
| 14 | + pull-requests: write |
| 15 | + |
11 | 16 | jobs: |
12 | 17 | check-approval: |
13 | 18 | runs-on: ubuntu-latest |
14 | 19 | outputs: |
15 | 20 | approved: ${{ steps.check.outputs.approved }} |
| 21 | + revoked: ${{ steps.check.outputs.revoked }} |
16 | 22 | steps: |
17 | 23 | - id: check |
18 | 24 | env: |
19 | 25 | IS_PUSH_OR_DISPATCH: ${{ contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) }} |
20 | 26 | AUTHOR_TRUSTED: ${{ contains(fromJSON('["MEMBER","OWNER","COLLABORATOR","CONTRIBUTOR"]'), github.event.pull_request.author_association) }} |
21 | 27 | HAS_APPROVAL_LABEL: ${{ contains(github.event.pull_request.labels.*.name, 'preview-approved') }} |
| 28 | + IS_PR_PUSH: ${{ github.event_name == 'pull_request_target' && github.event.action == 'synchronize' }} |
22 | 29 | run: | |
23 | | - if [ "$IS_PUSH_OR_DISPATCH" = "true" ] || [ "$AUTHOR_TRUSTED" = "true" ] || [ "$HAS_APPROVAL_LABEL" = "true" ]; then |
| 30 | + if [ "$IS_PUSH_OR_DISPATCH" = "true" ] || [ "$AUTHOR_TRUSTED" = "true" ] || ( [ "$HAS_APPROVAL_LABEL" = "true" ] && [ "$IS_PR_PUSH" != "true" ] ); then |
24 | 31 | echo "approved=true" >> "$GITHUB_OUTPUT" |
25 | 32 | else |
26 | 33 | echo "approved=false" >> "$GITHUB_OUTPUT" |
27 | 34 | fi |
| 35 | + if [ "$IS_PR_PUSH" = "true" ] && [ "$HAS_APPROVAL_LABEL" = "true" ] && [ "$AUTHOR_TRUSTED" != "true" ]; then |
| 36 | + echo "revoked=true" >> "$GITHUB_OUTPUT" |
| 37 | + else |
| 38 | + echo "revoked=false" >> "$GITHUB_OUTPUT" |
| 39 | + fi |
| 40 | + - name: Revoke approval on new commits |
| 41 | + if: ${{ github.event_name == 'pull_request_target' && github.event.action == 'synchronize' && contains(github.event.pull_request.labels.*.name, 'preview-approved') }} |
| 42 | + env: |
| 43 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + GH_REPO: ${{ github.repository }} |
| 45 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 46 | + run: | |
| 47 | + gh pr edit "$PR_NUMBER" --remove-label preview-approved |
28 | 48 |
|
29 | 49 | deploy: |
30 | 50 | needs: [check-approval] |
31 | 51 | if: | |
32 | 52 | github.event_name == 'push' || github.event_name == 'workflow_dispatch' || ( |
33 | 53 | github.event.action != 'closed' && |
34 | | - (github.event.action != 'labeled' || github.event.label.name == 'preview-approved') |
| 54 | + (github.event.action != 'labeled' || github.event.label.name == 'preview-approved') && |
| 55 | + needs.check-approval.outputs.revoked != 'true' |
35 | 56 | ) |
36 | 57 | uses: ./.github/workflows/ovh.yaml |
37 | 58 | with: |
|
44 | 65 | secrets: inherit |
45 | 66 |
|
46 | 67 | cleanup: |
| 68 | + needs: [check-approval] |
47 | 69 | if: | |
48 | | - github.event_name == 'pull_request_target' && (github.event.action == 'closed' || contains(github.event.pull_request.labels.*.name, 'stale')) |
| 70 | + github.event_name == 'pull_request_target' && ( |
| 71 | + github.event.action == 'closed' || |
| 72 | + contains(github.event.pull_request.labels.*.name, 'stale') || |
| 73 | + needs.check-approval.outputs.revoked == 'true' |
| 74 | + ) |
49 | 75 | uses: ./.github/workflows/ovh.yaml |
50 | 76 | with: |
51 | 77 | environment_name: ${{ format('pull/{0}', github.event.pull_request.number) }} |
|
0 commit comments