-
Notifications
You must be signed in to change notification settings - Fork 3
199 lines (195 loc) · 7.27 KB
/
workflow.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
name: Workflow
on:
push:
branches:
- master
- main
- develop
- 'hotfix/**'
- 'release/**'
- 'feature/**'
- 'prototype/**'
tags:
- '*'
pull_request:
workflow_call:
inputs:
app_path:
description: Is there a path prefix for the app
required: false
type: string
default: "./"
jobs:
build:
name: Build, Test and Upload Artifacts
runs-on: ubuntu-20.04
defaults:
run:
working-directory: ${{ format('./{0}', inputs.app_path) }}
steps:
## Setup variables for build info
- name: Set Variables
id: set_vars
working-directory: "./"
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}}
REPO_NAME: ${{steps.set_vars.outputs.repo_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 testing site](https://react-app-dev.cancer.gov/${ process.env.REPO_NAME }/${ process.env.BUILD_NAME }/)
`
})
## This clones and checks out.
- name: Checkout branch
uses: actions/checkout@v3
## Setup node and npm caching.
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '${{ inputs.app_path }}.nvmrc'
cache: 'npm'
registry-url: https://npm.pkg.github.com
scope: '@nciocpl'
cache-dependency-path: '**/package-lock.json'
## Install using CI
- name: Install Dependencies
run: npm ci
env:
CI: true
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
## Lint Codebase
- name: Lint Codebase
run: npm run lint
env:
CI: true
## Runs jest unit and cypress e2e testing and merges coverage reports
- name: Run Tests
run: npm test
env:
CI: true
## Build the app in prep for publishing
- name: Build App
run: npm run build
env:
CI: true
## This is used by web pack and NEEDs to be the URL that will ultimately
## be in netstorage
PUBLIC_URL: ${{ format('/{0}/{1}/', steps.set_vars.outputs.repo_name, steps.set_vars.outputs.build_name) }}
## 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 > ./build/build-info.json
## Upload the test results artifact
- name: Archive production artifacts
uses: actions/upload-artifact@v1
with:
name: test-results
path: ${{ inputs.app_path }}coverage
## Upload the test results artifact
- name: Archive production artifacts
uses: actions/upload-artifact@v1
with:
name: build-artifact
path: ${{ inputs.app_path }}build
deploy-test:
name: Deploy built artifacts to test 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
steps:
- name: Download built app
uses: actions/download-artifact@v1
with:
name: build-artifact
## Setup vars from Build Info from build job
- name: Setup Job env
run: |
## Set Vars
BUILD_NAME=$(jq -r '.build_name' < ./build-artifact/build-info.json)
BRANCH_NAME=$(jq -r '.branch_name' < ./build-artifact/build-info.json)
COMMIT_HASH=$(jq -r '.commit_hash' < ./build-artifact/build-info.json)
REPO_OWNER=$(jq -r '.repo_owner' < ./build-artifact/build-info.json)
REPO_NAME=$(jq -r '.repo_name' < ./build-artifact/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 Build Artifact
run: |
pushd build-artifact
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}/{1}.zip', env.REPO_NAME, env.BUILD_NAME) }}
- 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}', secrets.ns_cpcode, secrets.prop_cpcode) }}