-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (94 loc) · 4.5 KB
/
preview.yml
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: Manage site previews
on:
pull_request:
types:
- closed
- opened
- reopened
- synchronize
concurrency:
group: ${{ github.workflow }}
jobs:
preview:
runs-on: ubuntu-latest
steps:
- name: Get branch's latest deployment
uses: octokit/request-action@v2.x
id: get_latest_deployment
if: contains('closed synchronize', github.event.action)
with:
route: GET /repos/{repo}/deployments
repo: ${{ github.repository }}
ref: ${{ github.event.pull_request.head.ref }}
environment: preview
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Mark branch's latest deployment as inactive
uses: octokit/request-action@v2.x
if: contains('closed synchronize', github.event.action)
with:
route: POST /repos/{repo}/deployments/{deployment}/statuses
repo: ${{ github.repository }}
deployment: ${{ fromJson(steps.get_latest_deployment.outputs.data)[0].id }}
state: inactive
headers: |
Accept: application/vnd.github.ant-man-preview+json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Clean up deployment artifacts
if: contains('closed', github.event.action) # leave untouched when commits are pushed
run: aws s3 rm --recursive s3://preview.nicholas.cloud/${{ github.event.pull_request.number }}/
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY_SECRET }}
AWS_DEFAULT_REGION: ap-southeast-2
- name: Create new deployment
uses: octokit/request-action@v2.x
id: create_deployment
if: contains('opened reopened synchronize', github.event.action)
with:
route: POST /repos/{repo}/deployments
repo: ${{ github.repository }}
ref: ${{ github.event.pull_request.head.ref }}
environment: preview
auto_merge: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check out source code
uses: actions/checkout@v2
if: contains('opened reopened synchronize', github.event.action)
with:
submodules: recursive
- name: Build
uses: docker://registry.gitlab.com/pages/hugo:latest
with:
args: --baseURL https://preview.nicholas.cloud/${{ github.event.pull_request.number }}/
if: contains('opened reopened synchronize', github.event.action)
- name: Deploy build artifacts
if: contains('opened reopened synchronize', github.event.action)
run: aws s3 sync --size-only public/ s3://preview.nicholas.cloud/${{ github.event.pull_request.number }}/
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY_SECRET }}
AWS_DEFAULT_REGION: ap-southeast-2
- name: Mark new deployment as a success
uses: octokit/request-action@v2.x
if: contains('opened reopened synchronize', github.event.action)
with:
route: POST /repos/{repo}/deployments/{deployment}/statuses
repo: ${{ github.repository }}
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
state: success
environment_url: https://preview.nicholas.cloud/${{ github.event.pull_request.number }}/
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Mark new deployment as failed
uses: octokit/request-action@v2.x
if: contains('opened reopened synchronize', github.event.action) && failure()
with:
route: POST /repos/{repo}/deployments/{deployment}/statuses
repo: ${{ github.repository }}
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
state: failure
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}