-
Notifications
You must be signed in to change notification settings - Fork 52
80 lines (75 loc) · 3.55 KB
/
Copy pathdeploy.yml
File metadata and controls
80 lines (75 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: Deployment
on:
push:
branches:
- website
pull_request_target:
types: [opened, synchronize, reopened, closed, labeled]
workflow_dispatch:
permissions:
contents: read
issues: write # For label revoke
pull-requests: write
jobs:
check-approval:
runs-on: ubuntu-latest
outputs:
approved: ${{ steps.check.outputs.approved }}
revoked: ${{ steps.check.outputs.revoked }}
steps:
- id: check
env:
IS_PUSH_OR_DISPATCH: ${{ contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) }}
AUTHOR_TRUSTED: ${{ contains(fromJSON('["MEMBER","OWNER","COLLABORATOR","CONTRIBUTOR"]'), github.event.pull_request.author_association) }}
HAS_APPROVAL_LABEL: ${{ contains(github.event.pull_request.labels.*.name, 'preview-approved') }}
IS_PR_PUSH: ${{ github.event_name == 'pull_request_target' && github.event.action == 'synchronize' }}
run: |
if [ "$IS_PUSH_OR_DISPATCH" = "true" ] || [ "$AUTHOR_TRUSTED" = "true" ] || ( [ "$HAS_APPROVAL_LABEL" = "true" ] && [ "$IS_PR_PUSH" != "true" ] ); then
echo "approved=true" >> "$GITHUB_OUTPUT"
else
echo "approved=false" >> "$GITHUB_OUTPUT"
fi
if [ "$IS_PR_PUSH" = "true" ] && [ "$HAS_APPROVAL_LABEL" = "true" ] && [ "$AUTHOR_TRUSTED" != "true" ]; then
echo "revoked=true" >> "$GITHUB_OUTPUT"
else
echo "revoked=false" >> "$GITHUB_OUTPUT"
fi
- name: Revoke approval on new commits
if: ${{ github.event_name == 'pull_request_target' && github.event.action == 'synchronize' && contains(github.event.pull_request.labels.*.name, 'preview-approved') }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
gh pr edit "$PR_NUMBER" --remove-label preview-approved
deploy:
needs: [check-approval]
if: |
github.event_name == 'push' || github.event_name == 'workflow_dispatch' || (
github.event.action != 'closed' &&
(github.event.action != 'labeled' || github.event.label.name == 'preview-approved') &&
needs.check-approval.outputs.revoked != 'true'
)
uses: ./.github/workflows/ovh.yaml
with:
environment_name: ${{ contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) && 'production' || format('pull/{0}', github.event.pull_request.number) }}
url: ${{ contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) && format('https://{0}', vars.MAIN_WEBSITE) || format('https://{0}/pr/{1}', vars.PREVIEW_WEBSITE, github.event.pull_request.number) }}
target: ${{ contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) && 'www' || format('pulls/pr/{0}', github.event.pull_request.number) }}
ref: ${{ github.event.pull_request.head.sha || github.sha }}
approval_required: ${{ needs.check-approval.outputs.approved == 'false' }}
action: deploy
secrets: inherit
cleanup:
needs: [check-approval]
if: |
github.event_name == 'pull_request_target' && (
github.event.action == 'closed' ||
contains(github.event.pull_request.labels.*.name, 'stale') ||
needs.check-approval.outputs.revoked == 'true'
)
uses: ./.github/workflows/ovh.yaml
with:
environment_name: ${{ format('pull/{0}', github.event.pull_request.number) }}
target: ${{ format('pulls/pr/{0}', github.event.pull_request.number) }}
action: teardown
secrets: inherit