Skip to content

Commit 07b6bd2

Browse files
committed
fixup! fix(OVH): add minimum approval logic to prevent abuse
1 parent bd4039d commit 07b6bd2

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,51 @@ on:
88
types: [opened, synchronize, reopened, closed, labeled]
99
workflow_dispatch:
1010

11+
permissions:
12+
contents: read
13+
issues: write # For label revoke
14+
pull-requests: write
15+
1116
jobs:
1217
check-approval:
1318
runs-on: ubuntu-latest
1419
outputs:
1520
approved: ${{ steps.check.outputs.approved }}
21+
revoked: ${{ steps.check.outputs.revoked }}
1622
steps:
1723
- id: check
1824
env:
1925
IS_PUSH_OR_DISPATCH: ${{ contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) }}
2026
AUTHOR_TRUSTED: ${{ contains(fromJSON('["MEMBER","OWNER","COLLABORATOR","CONTRIBUTOR"]'), github.event.pull_request.author_association) }}
2127
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' }}
2229
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
2431
echo "approved=true" >> "$GITHUB_OUTPUT"
2532
else
2633
echo "approved=false" >> "$GITHUB_OUTPUT"
2734
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
2848
2949
deploy:
3050
needs: [check-approval]
3151
if: |
3252
github.event_name == 'push' || github.event_name == 'workflow_dispatch' || (
3353
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'
3556
)
3657
uses: ./.github/workflows/ovh.yaml
3758
with:
@@ -44,8 +65,13 @@ jobs:
4465
secrets: inherit
4566

4667
cleanup:
68+
needs: [check-approval]
4769
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+
)
4975
uses: ./.github/workflows/ovh.yaml
5076
with:
5177
environment_name: ${{ format('pull/{0}', github.event.pull_request.number) }}

0 commit comments

Comments
 (0)