-
Notifications
You must be signed in to change notification settings - Fork 5
285 lines (281 loc) · 11.8 KB
/
workflow.yml
File metadata and controls
285 lines (281 loc) · 11.8 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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
name: Workflow
on:
push:
branches:
- master
- main
- develop
- 'hotfix/**'
- 'release/**'
- 'feature/**'
- 'prototype/**'
tags:
- '*'
pull_request:
jobs:
build:
name: Build, Test and Upload Artifacts
runs-on: ubuntu-22.04
services:
apache:
image: httpd:2.4
ports:
- 8080:80
permissions:
contents: read
packages: read
pull-requests: write
steps:
## Setup variables for build info
- name: Set Variables
id: set_vars
run: |
## PUSH
if [ "${{ github.event_name }}" == "push" ]; then
BUILD_NAME=$(sed -E 's/refs\/(heads|tags)\///; s/\//__/g;' <<< $GITHUB_REF)
BRANCH_NAME=$(sed -E 's/refs\/(heads|tags)\///;' <<< $GITHUB_REF)
COMMIT_HASH=$(echo "${GITHUB_SHA}")
## PULL_REQUEST
elif [ "${{ github.event_name }}" == "pull_request" ]; then
BUILD_NAME=$(echo "pr-${{ github.event.pull_request.number }}")
BRANCH_NAME=$(echo "pr-${{ github.event.pull_request.number }}")
COMMIT_HASH=$(echo "${{ github.event.pull_request.head.sha }}")
else
## ERROR
exit 1
fi
## For step checks and artifact deployment path.
## Same for push and PR
export REPO_FULL=${{ github.repository }}
export REPO_RE='([^/]+)/(.*)'
[[ "$REPO_FULL" =~ $REPO_RE ]]
REPO_OWNER=$(echo "${BASH_REMATCH[1]}")
REPO_NAME=$(echo "${BASH_REMATCH[2]}")
## Set step outputs for later use
echo "build_name=${BUILD_NAME}" >> $GITHUB_OUTPUT
echo "branch_name=${BRANCH_NAME}" >> $GITHUB_OUTPUT
echo "commit_hash=${COMMIT_HASH}" >> $GITHUB_OUTPUT
echo "repo_owner=${REPO_OWNER}" >> $GITHUB_OUTPUT
echo "repo_name=${REPO_NAME}" >> $GITHUB_OUTPUT
- name: Add Comment on Where to Test
uses: actions/github-script@v6
if: startsWith(github.repository, 'NCIOCPL') && github.event_name == 'pull_request' && github.event.action == 'opened'
env:
BUILD_NAME: ${{steps.set_vars.outputs.build_name}}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
## NOTE: The script below is JavaScript
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `
## Viewing Information
* [The documentation site](https://designsystem-dev.cancer.gov/${ process.env.BUILD_NAME }/)
* [NCIDS JS Documentation](https://designsystem-dev.cancer.gov/${ process.env.BUILD_NAME }/ncids-js/)
* [The storybook site](https://designsystem-dev.cancer.gov/${ process.env.BUILD_NAME }/storybook/)
* [The example site](https://designsystem-dev.cancer.gov/${ process.env.BUILD_NAME }/example-site/)
`
})
## This clones and checks out.
- name: Checkout branch
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
## Setup node and npm caching.
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
registry-url: https://npm.pkg.github.com
scope: '@nciocpl'
## Install Packages
- name: Install packages
run: pnpm install --frozen-lockfile
env:
CI: true
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
## Lint the code
- name: Run Lint
run: pnpm run lint
env:
CI: true
## Download twigcs docker image
- name: Setup twigcs
run: docker pull --quiet ghcr.io/nciocpl/twigcs-docker:v1.0.1 > /dev/null 2>&1
env:
CI: true
## Lint the twig
- name: Run twig code sniffer
run: pnpm run test:twig
env:
CI: true
## Now test the code
- name: Run Tests
run: pnpm run test
env:
CI: true
## Build all the things for publishing. This is a proxy for testing.
- name: Build Doc Site
run: pnpm run docs-artifact
env:
CI: true
## This is used by Gatsby and NEEDs to be the path that will ultimately
## be in netstorage for designsystem-dev. NOTE: this should not get
## set for production builds.
DOCS_PREFIX_PATH: ${{ format('/{0}', steps.set_vars.outputs.build_name) }}
## This is used by Storybook and NEEDs to be the path that will ultimately
## be in netstorage for designsystem-dev. NOTE: this should **still** get
## set for production builds, but without the build_name.
STORYBOOK_BASE_HREF: ${{ format('/{0}/storybook', steps.set_vars.outputs.build_name) }}
## This is used by the example site and NEEDs to be the path that will ultimately
## be in netstorage for designsystem-dev. NOTE: this should **still** get
## set for production builds, but without the build_name.
EXAMPLE_SITE_PUBLIC_PATH: ${{ format('/{0}/example-site', steps.set_vars.outputs.build_name) }}
## The for dev cdn will be something like /cdn/pr-1234/ncids-css/ncids.min.css.
## For prod the cdn will be something like /cdn/v3.4.0/ncids-css/ncids.min.css.
EXAMPLE_SITE_CDN_BASE_PATH: ${{ format('/cdn/{0}', steps.set_vars.outputs.build_name) }}
## This is used by the SitewideSearchApp and NEEDs to be the path that will ultimately
## be in netstorage for designsystem-dev. NOTE: this should **still** get
## set for production builds, but without the build_name.
SITE_DOMAIN: "designsystem-dev.cancer.gov"
## Generate build-info.json to house information about this specific build.
## Used for product test deployment
- name: Create Build Information
env:
BUILD_INFO: ${{ toJson(steps.set_vars.outputs) }}
run: |
echo $BUILD_INFO
echo $BUILD_INFO > ./dist/documentation-site/build-info.json
## Put the built site on to apache for testing.
- name: Copy built storybook to apache
working-directory: ./dist/documentation-site
run: |
CONTAINER_ID=$(docker ps -q --filter "ancestor=httpd:2.4")
# Make the branch/tag/pr directory.
docker exec $CONTAINER_ID mkdir "/usr/local/apache2/htdocs/${{steps.set_vars.outputs.build_name}}"
docker cp . "$CONTAINER_ID:/usr/local/apache2/htdocs/${{steps.set_vars.outputs.build_name}}"
## Test a11y
- name: Run accessibility tests
working-directory: ./testing/ncids-js-testing
run: pnpm run test-pa11y
env:
CI: true
PA11Y_BASE_URL: ${{ format('http://localhost:8080/{0}/example-site/', steps.set_vars.outputs.build_name) }}
## Now test the css
- name: Run css tests
working-directory: ./testing/ncids-css-testing
run: pnpm backstop test --config='backstop.config.cjs' --docker
env:
CI: true
BACKSTOP_BASE_URL: ${{ format('http://localhost:8080/{0}/storybook/', steps.set_vars.outputs.build_name) }}
## Upload failed css tests
- uses: actions/upload-artifact@v4
name: Upload failed tests
if: failure()
with:
name: failed-backstopjs
path: /home/runner/work/ncids/ncids/testing/ncids-css-testing/.backstop/
include-hidden-files: true
## Upload successful css tests
- uses: actions/upload-artifact@v4
name: Upload successful tests
with:
name: success-backstopjs
path: /home/runner/work/ncids/ncids/testing/ncids-css-testing/.backstop/test/**/report.json
include-hidden-files: true
## TODO: Upload the test results artifact
# - name: Archive production artifacts
# uses: actions/upload-artifact@v1
# with:
# name: test-results
# path: coverage
## Upload the documentation site
- name: Archive production artifacts
uses: actions/upload-artifact@v4
with:
name: documentation-site
path: dist/documentation-site/
include-hidden-files: true
deploy-doc-site:
name: Deploy documentation site and downloads to dev server
## Only do this if the repo is NCIOCPL
if: startsWith(github.repository, 'NCIOCPL')
## This job depends on build completing
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Download built site
uses: actions/download-artifact@v4
with:
name: documentation-site
path: documentation-site
## Setup vars from Build Info from build job
- name: Setup Job env
run: |
## Set Vars
BUILD_NAME=$(jq -r '.build_name' < ./documentation-site/build-info.json)
BRANCH_NAME=$(jq -r '.branch_name' < ./documentation-site/build-info.json)
COMMIT_HASH=$(jq -r '.commit_hash' < ./documentation-site/build-info.json)
REPO_OWNER=$(jq -r '.repo_owner' < ./documentation-site/build-info.json)
REPO_NAME=$(jq -r '.repo_name' < ./documentation-site/build-info.json)
## Set Action Env
echo "BUILD_NAME=${BUILD_NAME}" >> $GITHUB_ENV
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
echo "COMMIT_HASH=${COMMIT_HASH}" >> $GITHUB_ENV
echo "REPO_OWNER=${REPO_OWNER}" >> $GITHUB_ENV
echo "REPO_NAME=${REPO_NAME}" >> $GITHUB_ENV
######## ERROR IF PR FROM FORK
if [ "$REPO_OWNER" != "NCIOCPL" ]; then
echo "YOU SHOULD NOT SEND PR FROM FORK!!!"
exit 1
fi
## We need to create the zip for netstorage
- name: Zip documentation site
run: |
pushd documentation-site
zip -r ../${BUILD_NAME}.zip *
popd
- name: Upload artifact to netstorage
uses: nciocpl/netstorage-upload-action@v1.0.0
with:
hostname: ${{ secrets.ns_hostname }}
cp-code: ${{ secrets.ns_cpcode }}
key-name: ${{ secrets.ns_keyname }}
key: ${{ secrets.ns_key }}
index-zip: true
local-path: ${{ format('{0}.zip', env.BUILD_NAME) }}
## Note this action automatically prepends the cpcode to the path.
destination-path: ${{ format('/{0}.zip', env.BUILD_NAME) }}
# The CDN artifact is named with the version from package-lock so we need to find that to upload it.
- name: Get CDN artifact name
id: cdn-name
run: |
FILE=$(ls documentation-site/downloads/ncids-v*.zip 2>/dev/null | head -n 1)
FILENAME=$(basename "$FILE")
echo "filename=$FILENAME" >> "$GITHUB_OUTPUT"
- name: Upload CDN artifact to netstorage
uses: nciocpl/netstorage-upload-action@v1.0.0
with:
hostname: ${{ secrets.ns_hostname }}
cp-code: ${{ secrets.ns_cdn_cpcode }}
key-name: ${{ secrets.ns_keyname }}
key: ${{ secrets.ns_key }}
index-zip: true
local-path: ${{ format('documentation-site/downloads/{0}', steps.cdn-name.outputs.filename) }}
## Note this action automatically prepends the cpcode to the path.
destination-path: ${{ format('/{0}.zip', env.BUILD_NAME, steps.cdn-name.outputs.filename) }}
- name: Clear Site Cache
uses: nciocpl/akamai-purge-action@v1.0.2
with:
hostname: ${{ secrets.eg_hostname }}
client-token: ${{ secrets.eg_client_token }}
client-secret: ${{ secrets.eg_client_secret }}
access-token: ${{ secrets.eg_access_token }}
type: "cpcodes"
ref: ${{ format('{0},{1},{2}', secrets.ns_cpcode, secrets.ns_cdn_cpcode, secrets.prop_cpcode) }}