-
Notifications
You must be signed in to change notification settings - Fork 8
202 lines (174 loc) · 6.8 KB
/
Copy pathbuild-deploy.yml
File metadata and controls
202 lines (174 loc) · 6.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
name: Build and deploy
on:
push:
branches-ignore:
- master
pull_request:
types: [closed]
branches:
- dev
- master
jobs:
set-vars:
if: |
github.event_name == 'push' ||
(github.event_name == 'pull_request' && github.event.pull_request.merged == true)
runs-on: ubuntu-latest
outputs:
cf_db_space: ${{ steps.set-vars.outputs.cf_db_space }}
cf_db_app_name: ${{ steps.set-vars.outputs.cf_db_app_name }}
cf_db_service_name: ${{ steps.set-vars.outputs.cf_db_service_name }}
gatsby_hasura_uri: ${{ steps.set-vars.outputs.gatsby_hasura_uri }}
stage: ${{ steps.set-vars.outputs.stage }}
steps:
- name: Set Cloud Foundry variables for connecting to the db
id: set-vars
run: |
branch="${GITHUB_BASE_REF:-${GITHUB_REF##*/}}"
if [ "$branch" = "master" ]; then
echo "cf_db_space=prod" >> $GITHUB_OUTPUT
echo "cf_db_app_name=nrrd" >> $GITHUB_OUTPUT
echo "cf_db_service_name=nrrd-a-psql" >> $GITHUB_OUTPUT
echo "gatsby_hasura_uri=https://hasura-prod.app.cloud.gov/v1/graphql" >> $GITHUB_OUTPUT
echo "stage=" >> $GITHUB_OUTPUT
elif [ "$branch" = "dev" ]; then
echo "cf_db_space=prod" >> $GITHUB_OUTPUT
echo "cf_db_app_name=hasura-dev" >> $GITHUB_OUTPUT
echo "cf_db_service_name=nrrd-b-psql" >> $GITHUB_OUTPUT
echo "gatsby_hasura_uri=https://hasura-dev.app.cloud.gov/v1/graphql" >> $GITHUB_OUTPUT
echo "stage=" >> $GITHUB_OUTPUT
else
echo "cf_db_space=dev" >> $GITHUB_OUTPUT
echo "cf_db_app_name=hasura-sandbox" >> $GITHUB_OUTPUT
echo "cf_db_service_name=nrrd-psql" >> $GITHUB_OUTPUT
echo "gatsby_hasura_uri=https://hasura-sandbox.app.cloud.gov/v1/graphql" >> $GITHUB_OUTPUT
echo "stage=nrrd-preview" >> $GITHUB_OUTPUT
fi
apply-database-updates:
if: |
github.event_name == 'push' ||
(github.event_name == 'pull_request' && github.event.pull_request.merged == true)
needs: set-vars
uses: ./.github/workflows/apply-database-changes.yml
with:
cf-space: ${{ needs.set-vars.outputs.cf_db_space }}
cf-app-name: ${{ needs.set-vars.outputs.cf_db_app_name }}
cf-service-name: ${{ needs.set-vars.outputs.cf_db_service_name }}
secrets: inherit
generate-downloads:
if: |
github.event_name == 'push' ||
(github.event_name == 'pull_request' && github.event.pull_request.merged == true)
needs: [set-vars, apply-database-updates]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install CF CLI
uses: doi-onrr/oddd-actions/.github/actions/cf-install@v1
- name: Log in to Cloud Foundry
shell: bash
run: |
cf login -u ${{ secrets.CF_USERNAME }} -p ${{ secrets.CF_PASSWORD }} -a api.fr.cloud.gov -o doi-onrr -s ${{ needs.set-vars.outputs.cf_db_space }}
- name: Install connect-to-service CF plugin
shell: bash
run: |
cf install-plugin -f https://github.com/cloud-gov/cf-service-connect/releases/download/1.1.0/cf-service-connect-linux-amd64
- name: Install gnumeric
run: |
sudo apt-get install --no-install-recommends -y gnumeric
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies in database directory
run: npm install
working-directory: .github/scripts/generate-downloads-json
- name: Open tunnel and generate downloads
run: .github/scripts/generate-downloads.sh
shell: bash
env:
CF_APP_NAME: ${{ needs.set-vars.outputs.cf_db_app_name }}
CF_SERVICE_NAME: ${{ needs.set-vars.outputs.cf_db_service_name }}
- name: Upload download files
uses: actions/upload-artifact@v4
with:
name: downloads
path: /tmp/downloads
build:
if: |
github.event_name == 'push' ||
(github.event_name == 'pull_request' && github.event.pull_request.merged == true)
needs: [set-vars, generate-downloads]
runs-on: ubuntu-latest
env:
GTM_ID: ${{ secrets.GTM_ID }}
GATSBY_HASURA_URI: ${{ needs.set-vars.outputs.gatsby_hasura_uri }}
STAGE: ${{ needs.set-vars.outputs.stage }}
BRANCH: ${{ github.base_ref || (github.ref_name == 'dev' && github.event_name == 'push' && 'dev') || (github.ref_name != 'master' && github.ref_name != 'dev' && github.ref_name) || 'master' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download downloads artifacts
uses: actions/download-artifact@v4
with:
name: downloads
path: static/downloads
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Install dependencies
run: npm ci --legacy-peer-deps
- name: Overwrite robots.txt
if: ${{ !(github.event_name == 'pull_request' && github.base_ref == 'master') }}
run: |
cp ./static/robots-dev.txt ./static/robots.txt
- name: Build application
run: npm run build --if-present
- name: Rename ~partytown directory
run: |
if [ -d public/~partytown ]; then
mv public/~partytown public/_partytown
fi
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: public
path: public
deploy-preview:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref != 'refs/heads/master' && github.ref != 'refs/heads/dev'
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: public
path: public
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Sync local folder to S3
run: |
branch="${GITHUB_REF##*/}"
aws s3 sync ./public s3://${{ secrets.AWS_BUCKET_NAME }}/sites/$branch --delete
deploy-dev:
needs: build
if: github.ref == 'refs/heads/dev' || (github.event_name == 'pull_request' && github.base_ref == 'dev')
uses: doi-onrr/oddd-actions/.github/workflows/cf-deploy.yml@v1
with:
manifest: manifest.dev.yml
secrets: inherit
deploy-prod:
needs: build
if: github.event_name == 'pull_request' && github.base_ref == 'master'
uses: doi-onrr/oddd-actions/.github/workflows/cf-deploy.yml@v1
with:
cf-space: prod
manifest: manifest.master.yml
secrets: inherit