-
Notifications
You must be signed in to change notification settings - Fork 1
225 lines (200 loc) · 8.39 KB
/
build.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
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
# This is the main build pipeline that verifies and publishes the software
name: Build
# Controls when the workflow will run
on:
# Triggers the workflow on push events
push:
branches:
- main
- develop
- 'release/**'
- 'feature/**'
- 'issue/**'
- 'issues/**'
- 'dependabot/**'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
allow_same_version:
description: 'Allow the same version to be built'
required: false
default: 'false'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
PROJECT_ NAME: podaac/hitide-ui
jobs:
# First job in the workflow installs and verifies the software
build:
name: Build, Test, Deploy
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
# Checkout
- name: Checkout project to build and deploy
uses: actions/checkout@v4
## Read the json file into the environment variables
- name: JSON to variables
uses: rgarcia-phi/[email protected]
with:
filename: 'package.json'
prefix: project
## Set environment variables
- name: Configure Initial YAML file and environment variables
run: |
echo "THE_VERSION=${{ env.project_version }}" >> $GITHUB_ENV;
echo "GIT_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV;
GITHUB_REF_READABLE="${GITHUB_REF//\//-}"
echo "GITHUB_REF_READABLE=${GITHUB_REF_READABLE}" >> $GITHUB_ENV
## NPM Tagging
- name: Pre Alpha
if: |
startsWith(github.ref, 'refs/heads/issue') ||
startsWith(github.ref, 'refs/heads/dependabot/') ||
startsWith(github.ref, 'refs/heads/feature/')
run: |
echo "THE_ENV=sit" >> $GITHUB_ENV
echo "TARGET_ENV_UPPERCASE=SIT" >> $GITHUB_ENV
echo "THE_VERSION=$(npm --no-git-tag-version --allow-same-version version ${{ env.THE_VERSION }}-${GITHUB_SHA})" >> $GITHUB_ENV
## Set Alpha variables
- name: Alpha
if: github.ref == 'refs/heads/develop'
run: |
echo "THE_ENV=sit" >> $GITHUB_ENV
echo "TARGET_ENV_UPPERCASE=SIT" >> $GITHUB_ENV
echo "THE_VERSION=$(npm --no-git-tag-version version prerelease)" >> $GITHUB_ENV
## Bump RC Version
- name: Bump rc version
# If triggered by push to a release branch
if: ${{ startsWith(github.ref, 'refs/heads/release/') }}
env:
# True if the version already has a 'rc' pre-release identifier
BUMP_RC: ${{ contains(env.project_version, 'rc') }}
RELEASE_VERSION: ${THE_BRANCH//*\/}
run: |
if [ "$BUMP_RC" == true ]; then
echo "THE_VERSION=$(npm --no-git-tag-version version prerelease --preid rc)" >> $GITHUB_ENV
else
echo "THE_VERSION=$(npm --no-git-tag-version version ${GITHUB_REF#refs/heads/release/}-rc.1)" >> $GITHUB_ENV
fi
echo "THE_ENV=uat" >> $GITHUB_ENV
echo "TARGET_ENV_UPPERCASE=UAT" >> $GITHUB_ENV
## Set Release variables
- name: Release
if: ${{ (startsWith(github.ref, 'refs/heads/main')) && (github.event.inputs.allow_same_version != 'true') }}
run: |
echo "THE_ENV=ops" >> $GITHUB_ENV
echo "TARGET_ENV_UPPERCASE=OPS" >> $GITHUB_ENV
echo "Modifying version number ${{ env.project_version}}"
THE_VERSION=${{ env.project_version }}
echo "THE_VERSION=${THE_VERSION//-*}" >> $GITHUB_ENV
npm --no-git-tag-version version ${THE_VERSION//-*}
- name: Release - Allow same version
if: ${{ (startsWith(github.ref, 'refs/heads/main')) && (github.event.inputs.allow_same_version == 'true') }}
run: |
echo "THE_ENV=ops" >> $GITHUB_ENV
echo "TARGET_ENV_UPPERCASE=OPS" >> $GITHUB_ENV
echo "Modifying version number ${{ env.project_version}}"
THE_VERSION=${{ env.project_version }}
echo "THE_VERSION=${THE_VERSION//-*}" >> $GITHUB_ENV
npm --no-git-tag-version version --allow-same-version ${THE_VERSION//-*}
- name: Run Snyk as a blocking step
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: test
args: >
--org=${{ secrets.SNYK_ORG_ID }}
--project-name=${{ github.repository }}
--severity-threshold=high
--fail-on=all
- name: Run Snyk on Node
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: monitor
args: >
--org=${{ secrets.SNYK_ORG_ID }}
--project-name=${{ github.repository }}
- name: Commit Version Bump
# If building develop, a release branch, or main then we commit the version bump back to the repo
run: |
if ${{ github.event.inputs.allow_same_version != 'true' &&
(github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/release')) }}; then
git config --global user.name 'hitide-ui bot'
git config --global user.email '[email protected]'
git commit -am "/version ${{ env.THE_VERSION }}"
git push
fi
- name: Push Tag
if: |
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/release')
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git tag -f -a "${{ env.THE_VERSION }}" -m "Version ${{ env.THE_VERSION }}"
git push origin "${{ env.THE_VERSION }}" --force
- name: Publish UMM-T with new version
uses: podaac/[email protected]
if: |
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/release')
with:
umm-json: cmr/${{ env.THE_ENV }}_hitide_cmr_umm_t.json
provider: 'POCLOUD'
env: ${{ env.THE_ENV }}
version: ${{ env.THE_VERSION }}
timeout: 60
disable_removal: 'true'
umm_type: 'umm-t'
use_associations: 'false'
env:
LAUNCHPAD_TOKEN_SIT: ${{secrets.LAUNCHPAD_TOKEN_SIT}}
LAUNCHPAD_TOKEN_UAT: ${{secrets.LAUNCHPAD_TOKEN_UAT}}
LAUNCHPAD_TOKEN_OPS: ${{secrets.LAUNCHPAD_TOKEN_OPS}}
# Setup Node to install and test
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 14
- name: NPM install & NPM Lint
run: |
npm install
npm run build
## Deployment
- name: Deploy Env Override
if: |
github.event.head_commit.message == '/deploy sit' ||
github.event.head_commit.message == '/deploy uat'
run: |
message="${{ github.event.head_commit.message }}"
trimmed_message=${message:1} # Remove leading slash
override_env=$(echo "$trimmed_message" | grep -oE '[^[:space:]]+$')
override_env_upper=$(echo "$trimmed_message" | awk '{print toupper($NF)}')
echo "THE_ENV=${override_env}" >> $GITHUB_ENV
echo "TARGET_ENV_UPPERCASE=${override_env_upper}" >> $GITHUB_ENV
- name: Make Config Files
run: |
cat ./configs/hitideConfig-${{ env.THE_ENV }}.js > ./dist/hitideConfig.js
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-west-2
role-session-name: GitHubActions
aws-access-key-id: ${{ secrets[format('AWS_ACCESS_KEY_ID_SERVICES_{0}', env.TARGET_ENV_UPPERCASE)] }}
aws-secret-access-key: ${{ secrets[format('AWS_SECRET_ACCESS_KEY_SERVICES_{0}', env.TARGET_ENV_UPPERCASE)] }}
- name: Sync S3
if: |
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/release') ||
github.event.head_commit.message == '/deploy sit' ||
github.event.head_commit.message == '/deploy uat'
run:
aws s3 sync ./dist s3://podaac-services-${{ env.THE_ENV }}-hitide --exclude dataset-configs/* --exclude palettes/* --delete