1
1
name : web-admin ui
2
2
on :
3
3
push :
4
+ branches :
5
+ - main
6
+ - master
7
+ - develop
8
+ - cicd/adminui-prod
9
+
10
+ pull_request :
11
+ types :
12
+ - open
13
+ - synchronized
14
+
15
+ release :
16
+ types :
17
+ - published
18
+
4
19
5
20
jobs :
6
- adminui :
21
+ whatisthecontext :
7
22
runs-on : ubuntu-latest
8
- strategy :
9
- matrix :
10
- node-version : [12.x]
11
- name : build & deploy adminui
12
-
23
+ name : display the current build & deploy CI context and export useful values
24
+ outputs :
25
+ sha : ${{ steps.contextvals.outputs.sha }}
26
+ built_at : ${{ steps.contextvals.outputs.built_at }}
27
+ is_dev_deploy : ${{ github.ref == 'master' }}
28
+ api_url : ${{ steps.contextvals.outputs.api_url }}
29
+ target_bucket : ${{ steps.contextvals.outputs.target_bucket }}
30
+ is_github_release : ${{ github.event_name == 'release' }}
13
31
steps :
14
- - name : Context
15
- uses : docker://busybox
16
- - name : export context values
32
+ - name : Export values
17
33
id : contextvals
18
34
run : |
19
35
SHA=${{ github.sha }}
20
- BUILT_AT=$(date +%Y-%m-%dT%H:%M:%S%z)
36
+ BUILT_AT=$(date "+%Y-%m-%d %H:%M:%S%z")
37
+ if [ ${{ github.event_name == 'release' }} ]; then
38
+ API_URL=https://api.dev.ballotnav.org
39
+ TARGET_BUCKET=admin.ballotnav.org
40
+ else
41
+ API_URL=https://api.ballotnav.org
42
+ TARGET_BUCKET=admin.dev.ballotnav.org
43
+ fi
44
+
45
+ # print these to the console for sanity checking
46
+ printf "%s\n" "SHA: ${SHA:0:8}"
47
+ printf "%s\n" "Target bucket ${TARGET_BUCKET}"
48
+ printf "%s\n" "API url ${API_URL}"
49
+ printf "%s\n" "Built at ${BUILT_AT}"
50
+
51
+ # export them to github action outputs
21
52
echo ::set-output name=sha::${SHA:0:8}
22
53
echo ::set-output name=artifactbucket::ballotnav-dev-adminui-dev-logs
23
- echo ::set-output name=targetbucket::admin.dev.ballotnav.org
24
- echo ::set-output name=apiurl::https://api.dev.ballotnav.org
54
+ echo ::set-output name=targetbucket::${TARGET_BUCKET}
55
+ echo ::set-output name=apiurl::${API_URL}
25
56
echo ::set-output name=built_at::${BUILT_AT}
26
57
58
+ adminui :
59
+ runs-on : ubuntu-latest
60
+ needs : [whatisthecontext]
61
+ strategy :
62
+ matrix :
63
+ node-version : [12.x]
64
+ name : build & deploy adminui to dev
65
+
66
+ steps :
27
67
- uses : actions/checkout@v2
28
68
- name : Setup node
29
69
uses : actions/setup-node@v1
@@ -34,18 +74,21 @@ jobs:
34
74
run : npm ci
35
75
36
76
- name : Build the app
77
+ # we do not build the app again on release, instead we will unpack the already built artifact saved with the git SHA
78
+ if : ${{ needs.whatisthecontext.outputs.is_github_release != true }}
37
79
working-directory : ./client/web-admin
38
80
run : |
39
- REACT_APP_API_URL=${{ steps.contextvals .outputs.apiurl }} npm run build
40
- printf "%s\n" '{"version": "${{ steps.contextvals .outputs.sha }}", "built_at" : "${{ steps.contextvals .outputs.built_at }}" }' > build/version.json
81
+ REACT_APP_API_URL=${{ needs.whatisthecontext .outputs.apiurl }} npm run build
82
+ printf "%s\n" '{"version": "${{ needs.whatisthecontext .outputs.sha }}", "built_at" : "${{ needs.whatisthecontext .outputs.built_at }}" }' > build/version.json
41
83
42
84
- name : Create artifact
85
+ if : ${{ needs.whatisthecontext.outputs.is_github_release != true }}
43
86
uses : docker://busybox
44
87
- name : tarball
45
88
if : ${{ github.ref == 'refs/heads/master' }}
46
89
working-directory : ./client/web-admin
47
90
run : |
48
- tar -czf adminui-${{ steps.contextvals .outputs.sha }}.tar.gz build
91
+ tar -czf adminui-${{ needs.whatisthecontext .outputs.sha }}.tar.gz build
49
92
50
93
- name : Configure AWS credentials
51
94
uses : aws-actions/configure-aws-credentials@v1
@@ -58,12 +101,42 @@ jobs:
58
101
if : ${{ github.ref == 'refs/heads/master' }}
59
102
working-directory : ./client/web-admin
60
103
run : |
61
- aws s3 cp adminui-${{ steps.contextvals .outputs.sha }}.tar.gz s3://${{ steps.contextvals .outputs.artifactbucket }}/artifacts/
104
+ aws s3 cp adminui-${{ needs.whatisthecontext .outputs.sha }}.tar.gz s3://${{ needs.whatisthecontext .outputs.artifactbucket }}/artifacts/
62
105
63
- - name : Deploy to the web admin app
106
+ - name : Deploy to the web admin app to dev
64
107
if : ${{ github.ref == 'refs/heads/master' }}
65
108
working-directory : ./client/web-admin
66
109
run : |
67
- aws s3 sync build s3://${{ steps.contextvals.outputs.targetbucket }}
110
+ aws s3 sync build s3://${{ needs.whatisthecontext.outputs.targetbucket }}
111
+ aws s3 cp build/index.html s3://${{ needs.whatisthecontext.outputs.targetbucket }}/ --cache-control no-cache
112
+ aws s3 cp build/version.json s3://${{ needs.whatisthecontext.outputs.targetbucket }}/ --cache-control no-cache
113
+
114
+ deploy_prd :
115
+ name : deploy to the production environment
116
+ runs-on : ubuntu-latest
117
+ needs : [whatisthecontext]
118
+ if : ${{ needs.whatisthecontext.outputs.is_github_release == true }}
119
+ steps :
120
+ - name : Configure AWS credentials
121
+ uses : aws-actions/configure-aws-credentials@v1
122
+ with :
123
+ aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
124
+ aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
125
+ aws-region : us-west-2
126
+
127
+ - name : Pull down the built artifact
128
+ working-directory : ./client/web-admin
129
+ run : |
130
+ aws s3 cp s3://${{ needs.whatisthecontext.outputs.artifactbucket }}/adminui-${{ needs.whatisthecontext.outputs.sha }}.tar.gz .
131
+
132
+ - name : unpack the tarball
133
+ working-directory : ./client/web-admin
134
+ run : |
135
+ tar -xzf adminui-${{ needs.whatisthecontext.outputs.sha }}.tar.gz .
136
+
137
+ - name : Deploy to the web admin app to prod
138
+ working-directory : ./client/web-admin
139
+ run : |
140
+ aws s3 sync build s3://${{ needs.whatisthecontext.outputs.targetbucket }}
68
141
aws s3 cp build/index.html s3://${{ steps.contextvals.outputs.targetbucket }}/ --cache-control no-cache
69
142
aws s3 cp build/version.json s3://${{ steps.contextvals.outputs.targetbucket }}/ --cache-control no-cache
0 commit comments