This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
128 lines (117 loc) · 4.85 KB
/
pr-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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: pr-preview
on:
pull_request:
branches: ['main']
jobs:
deploy:
runs-on: ubuntu-latest
env:
PR_PATH: pull/${{ github.event.number }}
TERRA_DEV_SITE_PUBLIC_PATH: "/terra-clinical/pull/${{ github.event.number }}/"
BASE_URL: "https://engineering.cerner.com/${{ github.event.repository.name }}/pull/${{ github.event.number }}/"
ENVIRONMENT_NAME: preview-pr-${{ github.event.number }}
steps:
- name: check for previous deployment
id: check-previous
uses: octokit/[email protected]
with:
route: GET /repos/{repository}/deployments
repository: ${{ github.repository }}
ref: ${{ github.event.pull_request.head.ref }}
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- name: set previous deployment as inactive
if: |
steps.check-previous.outputs.status != '404' &&
toJSON(fromJSON(steps.check-previous.outputs.data)) != '[]'
uses: octokit/[email protected]
with:
route: POST /repos/{repository}/deployments/{deployment}/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJSON(steps.check-previous.outputs.data)[0].id }}
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: inactive
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- name: get pull request
id: get-pull-request
uses: octokit/[email protected]
with:
route: GET /repos/{repository}/pulls/{issue_id}
repository: ${{ github.repository }}
issue_id: ${{ github.event.number }}
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- name: create deployment
id: create-deployment
uses: octokit/[email protected]
if: |
steps.check-previous.outputs.status != '404'
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
with:
route: POST /repos/{repository}/deployments
repository: ${{ github.repository }}
ref: ${{ github.event.pull_request.head.ref }}
transient_environment: true
auto_merge: false
environment: ${{env.ENVIRONMENT_NAME}}
required_contexts: '[]'
- name: set deployment status to in progress
id: start_deployment
uses: octokit/[email protected]
if: |
steps.check-previous.outputs.status != '404'
with:
route: POST /repos/{repository}/deployments/{deployment}/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJSON(steps.create-deployment.outputs.data).id }}
environment: ${{ env.ENVIRONMENT_NAME }}
environment_url: ${{ env.BASE_URL }}
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: in_progress
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- uses: actions/checkout@v3
with:
ref: ${{ fromJSON(steps.get-pull-request.outputs.data).head.sha }}
- name: setup project
uses: ./.github/actions/setup
- name: build project
env:
TERRA_DEV_SITE_NEW_RELIC_LICENSE_KEY: ${{ secrets.TERRA_DEV_SITE_NEW_RELIC_LICENSE_KEY }}
TERRA_DEV_SITE_NEW_RELIC_APPLICATION_ID: "144458769"
run: npm run compile:prod
- name: deploy the pull request
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build
destination_dir: ${{ env.PR_PATH }}
- name: set deployment status to success
id: successful_deployment
uses: octokit/[email protected]
with:
route: POST /repos/{repository}/deployments/{deployment}/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJson(steps.create-deployment.outputs.data).id }}
environment: ${{ env.ENVIRONMENT_NAME }}
environment_url: ${{ env.BASE_URL }}
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: success
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- name: set deployment status to failure
id: failed_deployment
uses: octokit/[email protected]
if: failure()
with:
route: POST /repos/{repository}/deployments/{deployment}/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJson(steps.create-deployment.outputs.data).id }}
environment: ${{ env.ENVIRONMENT_NAME }}
environment_url: ${{ env.BASE_URL }}
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: failure
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'