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
161 lines (140 loc) · 4.86 KB
/
pr-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
# Runs Cypress tests and if they pass then deploys the doc site to an S3 bucket
name: PR Publish Docsite
on:
pull_request:
branches:
- "main"
paths:
- "site/**"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true
jobs:
cypress:
name: Cypress Tests
if: github.event.pull_request.draft == false
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: ${{ matrix.node-version }}
- 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 Temp Docsite
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: Set Environment Variables
run: |
BRANCH_NAME=${GITHUB_HEAD_REF#refs/heads/}
BRANCH_NAME=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]')
BRANCH_NAME=$(echo "$BRANCH_NAME" | sed -e "s/[^a-z0-9]/-/g")
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
- 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: Generate Static Site
run: |
cd site
yarn install --pure-lockfile
npm run build
env:
GOOGLE_ANALYTICS_TRACKING_ID: "12345"
GTAG_TRACKING_ID: "12345"
- name: Sync Zip to Bucket
run: |
aws s3 sync ./site/build s3://staging-dev-docsite/$BRANCH_NAME --acl public-read
- name: Invalidate CF Cache
run: |
aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID}} --paths "/" "/*"
- name: Comment on PR
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'http://${{ env.BRANCH_NAME }}.staging-dev.bandwidth.com/'
})
alert_if_failure:
name: Alert for failure
needs: [cypress, publish]
if: failure() && !github.event.pull_request.draft
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get Branch Name
run: |
echo "BRANCH_NAME=${GITHUB_HEAD_REF#refs/heads/}" >> $GITHUB_ENV
- name: Check for Corresponding api-specs PR
run: |
response=$(curl \
-H "Accept: application/vnd.github.v3+json" \
-u ${{ secrets.DX_GITHUB_USERNAME }}:${{ secrets.DX_GITHUB_TOKEN }} \
https://api.github.com/repos/Bandwidth/api-specs/pulls?head=Bandwidth:$BRANCH_NAME)
url=$(echo $response | jq '.[0].url')
number=$(echo $response | jq '.[0].number')
if [ -z $number ]; then
echo "No Corresponding PR found on api-specs";
else
echo "URL=$url" >> $GITHUB_ENV;
echo "SPECS_PR_NUMBER=$number" >> $GITHUB_ENV;
echo "RESULT=true" >> $GITHUB_ENV;
fi
- name: Get Docs PR Number
if: ${{ env.RESULT == 'true' }}
run: |
echo "DOCS_PR_NUMBER=$(hub pr list -h ${{ env.BRANCH_NAME }} -f %I)" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.DX_GITHUB_TOKEN }}
- name: Comment on PR
if: ${{ env.RESULT == 'true' }}
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.issues.createComment({
issue_number: '${{ env.SPECS_PR_NUMBER }}',
owner: 'Bandwidth',
repo: 'api-specs',
body: 'http://$BUCKET_NAME.staging-dev.bandwidth.com/'
})