This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
183 lines (162 loc) · 5.45 KB
/
publish-docsite.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# Runs Cypress tests locally, deploys the doc site to an S3 bucket and runs post deployment cypress tests again
name: Publish Docsite
on:
release:
types:
- published
workflow_dispatch:
jobs:
cypress:
name: Cypress Tests
runs-on: ubuntu-latest
container:
image: cypress/browsers:node-18.16.0-chrome-114.0.5735.133-1-ff-114.0.2-edge-114.0.1823.51-1
options: --user 1001 --shm-size=2g
strategy:
fail-fast: false
matrix:
node-version: [16, 18, 20.5.1]
browser: [chrome]
exclude:
- node-version: 16
browser: firefox
steps:
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: Checkout
uses: actions/checkout@v3
- name: Cypress run
uses: cypress-io/[email protected]
timeout-minutes: 20
with:
browser: ${{ matrix.browser }}
start: yarn start
wait-on: http://localhost:3000
wait-on-timeout: 180
working-directory: ./site
config-file: cypress.config.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOOGLE_ANALYTICS_TRACKING_ID: "12345"
GTAG_TRACKING_ID: "12345"
publish:
name: Publish Docsite
needs: cypress
runs-on: ubuntu-latest
if: ${{ !github.event.release.prerelease && github.event.release.target_commitish == 'main' }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: Generate Static Site
run: |
cd site
yarn install --pure-lockfile
npm run build
env:
GOOGLE_ANALYTICS_TRACKING_ID: ${{ secrets.GOOGLE_ANALYTICS_TRACKING_ID }}
GTAG_TRACKING_ID: ${{ secrets. GTAG_TRACKING_ID}}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Sync zip to Bucket
run: |
aws s3 sync ./site/build s3://$BUCKET_NAME --acl public-read --delete
env:
BUCKET_NAME: ${{ secrets.BUCKET_NAME }}
- name: Invalidate Cloudfront Cache
id: invalidate1
continue-on-error: true
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID}} --paths "/" "/*"
- name: Invalidate Cloudfront Cache Attempt 2
id: invalidate2
if: steps.invalidate1.outcome=='failure'
continue-on-error: true
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID}} --paths "/" "/*"
- name: Invalidate Cloudfront Cache Attempt 3
continue-on-error: true
id: invalidate3
if: steps.invalidate2.outcome=='failure'
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID}} --paths "/" "/*"
- name: Cloudfront Cache Invalidation Status
if: always()
run: |
if ${{ steps.invalidate1.outcome=='success' || steps.invalidate2.outcome=='success' || steps.invalidate3.outcome=='success' }}; then
echo invalidation successful
else
exit 1
fi
cypress_post_tests:
name: Cypress run on prod
needs: [cypress, publish]
runs-on: ubuntu-latest
container:
image: cypress/browsers:node-18.16.0-chrome-114.0.5735.133-1-ff-114.0.2-edge-114.0.1823.51-1
options: --user 1001 --shm-size=2g
strategy:
fail-fast: false
matrix:
node-version: [16, 18, 20.5.1]
browser: [chrome]
exclude:
- node-version: 16
browser: firefox
steps:
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: Checkout
uses: actions/checkout@v3
- name: Cypress Post Deployment Test
uses: cypress-io/[email protected]
timeout-minutes: 20
with:
browser: ${{ matrix.browser }}
working-directory: ./site
config-file: prod-cypress.config.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOOGLE_ANALYTICS_TRACKING_ID: "12345"
GTAG_TRACKING_ID: "12345"
notify_for_failures:
name: Notify for Failures
needs: [cypress_post_tests]
if: failure()
runs-on: ubuntu-latest
steps:
- name: Notify Slack of Failures
uses: Bandwidth/[email protected]
with:
job-status: failure
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
slack-channel: ${{ secrets.SLACK_CHANNEL }}
rollback_if_failed:
needs: [cypress, publish, cypress_post_tests]
name: Rollback Release
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install Dependencies
run: |
cd ./.github/actions/rollback_release
npm install
- name: Rollback For Failed Cypress Tests
id: rollback
uses: ./.github/actions/rollback_release
env:
GITHUB_TOKEN: ${{ secrets.DX_GITHUB_TOKEN }}