-
Notifications
You must be signed in to change notification settings - Fork 0
176 lines (148 loc) · 5.92 KB
/
deploy-goes.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
name: Deploy GOES
on:
workflow_dispatch:
push:
branches: [ main, production, deploy-goes-to-prod ]
paths:
- goes-plume-viewer/**
jobs:
define-environment:
name: Set environment
runs-on: ubuntu-latest
outputs:
env_name: ${{ steps.define_environment.outputs.env_name }}
steps:
- name: Set the environment based on the branch
id: define_environment
run: |
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
echo "env_name=staging" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" = "refs/heads/deploy-goes-to-prod" ]; then
echo "env_name=production" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" = "refs/heads/production" ]; then
echo "env_name=production" >> $GITHUB_OUTPUT
fi
- name: Print the environment
run: echo "The environment is ${{ steps.define_environment.outputs.env_name }}"
build:
runs-on: ubuntu-latest
needs: define-environment
environment: ${{ needs.define-environment.outputs.env_name }}
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
with:
sparse-checkout: 'goes-plume-viewer/'
sparse-checkout-cone-mode: true
- name: Read Node.js version from .nvmrc
id: nvm
run: echo "::set-output name=NODE_VERSION::$(cat goes-plume-viewer/.nvmrc)"
- uses: actions/setup-node@v3
with:
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}
- name: Install Yarn
run: npm install -g yarn
- name: Validate required variables and secrets
run: |
missing_vars=()
# Check for required variables
[ -z "${{ secrets.REACT_APP_MAPBOX_ACCESS_TOKEN }}" ] && missing_vars+=("secrets.REACT_APP_MAPBOX_ACCESS_TOKEN")
[ -z "${{ secrets.REACT_APP_MAPBOX_STYLE_URL }}" ] && missing_vars+=("secrets.REACT_APP_MAPBOX_STYLE_URL")
[ -z "${{ vars.REACT_APP_BASE_PATH_GOES }}" ] && missing_vars+=("vars.REACT_APP_BASE_PATH_GOES")
[ -z "${{ secrets.DEPLOYMENT_ROLE_ARN }}" ] && missing_vars+=("secrets.DEPLOYMENT_ROLE_ARN")
[ -z "${{ secrets.CF_DISTRIBUTION_ID }}" ] && missing_vars+=("secrets.CF_DISTRIBUTION_ID")
# If any variables are missing, print them and exit with an error
if [ ${#missing_vars[@]} -ne 0 ]; then
echo "Error: The following required variables are missing:"
printf '%s\n' "${missing_vars[@]}"
exit 1
fi
shell: bash
- name: Building 🔧
working-directory: ./goes-plume-viewer
run: |
echo >> .env # add a new line to append the below variables
echo REACT_APP_MAPBOX_TOKEN="${{ secrets.REACT_APP_MAPBOX_ACCESS_TOKEN }}" >> .env
echo REACT_APP_MAPBOX_STYLE_URL="${{ secrets.REACT_APP_MAPBOX_STYLE_URL }}" >> .env
echo REACT_APP_BASE_PATH="${{ vars.REACT_APP_BASE_PATH_GOES }}" >> .env
yarn
CI=false yarn build
- name: Upload build folder
uses: actions/upload-artifact@v4
with:
name: build_folder
path: ./goes-plume-viewer/build
deploy-staging:
needs:
- build
- define-environment
if: github.ref == 'refs/heads/main'
environment: ${{ needs.define-environment.outputs.env_name }}
permissions:
id-token: write
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
- name: Download build folder
uses: actions/download-artifact@v4
with:
name: build_folder
path: ./goes-plume-viewer/build
- name: ConfigureAWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.DEPLOYMENT_ROLE_ARN }}
role-session-name: ${{ github.repository_owner}}
aws-region: us-west-2
- name: Upload to S3
run: |
export BASE_PATH=${{ vars.REACT_APP_BASE_PATH_GOES }}
echo "BASE_PATH=${BASE_PATH}" >> $GITHUB_ENV
aws s3 sync "./goes-plume-viewer/build" s3://ghgc-custom-interfaces-staging${BASE_PATH}/ --cache-control max-age=30,must-revalidate,s-maxage=604800 --delete
env:
BASE_PATH: ${{ vars.REACT_APP_BASE_PATH_GOES }}
- name: Request Invalidation to AWS Cloudfront
uses: oneyedev/aws-cloudfront-invalidation@v1
with:
distribution-id: ${{ secrets.CF_DISTRIBUTION_ID }}
paths: |
/ghgcenter/custom-interfaces/*
deploy-production:
needs:
- build
- define-environment
if: github.ref == 'refs/heads/production'
environment: ${{ needs.define-environment.outputs.env_name }}
permissions:
id-token: write
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
- name: Download build folder
uses: actions/download-artifact@v4
with:
name: build_folder
path: ./goes-plume-viewer/build
- name: ConfigureAWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.DEPLOYMENT_ROLE_ARN }}
role-session-name: ${{ github.repository_owner}}
aws-region: us-west-2
- name: Upload to S3
run: |
export BASE_PATH=${{ vars.REACT_APP_BASE_PATH_GOES }}
echo "BASE_PATH=${BASE_PATH}" >> $GITHUB_ENV
aws s3 sync "./goes-plume-viewer/build" s3://ghgc-custom-interfaces-production${BASE_PATH}/ --cache-control max-age=30,must-revalidate,s-maxage=604800 --delete
env:
BASE_PATH: ${{ vars.REACT_APP_BASE_PATH_GOES }}
- name: Request Invalidation to AWS Cloudfront
uses: oneyedev/aws-cloudfront-invalidation@v1
with:
distribution-id: ${{ secrets.CF_DISTRIBUTION_ID }}
paths: |
/ghgcenter/custom-interfaces/*