-
Notifications
You must be signed in to change notification settings - Fork 91
174 lines (135 loc) · 5.08 KB
/
build-and-deploy-site.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
name: 'build-and-deploy-site'
on:
# push:
# branches: [ "main" ]
workflow_dispatch: {}
jobs:
build-and-deploy-site:
runs-on: 'ubuntu-latest'
environment: 's3-deploy'
env:
AWS_ACCESS_KEY_ID: '${{ secrets.AWS_ACCESS_KEY_ID }}'
AWS_SECRET_ACCESS_KEY: '${{ secrets.AWS_SECRET_ACCESS_KEY }}'
steps:
- uses: actions/checkout@v3
with:
path: ./eczoo_data
# Check out site generation code
- name: 'Check out eczoo_sitegen code'
run: |
git clone https://github.com/errorcorrectionzoo/eczoo_sitegen.git --depth=1 eczoo_sitegen
# --------------------------------
# Install NodeJS
- uses: actions/setup-node@v3
with:
#cache: 'yarn'
node-version: '20'
- name: 'Enable Yarn (corepack enable)'
run: 'corepack enable'
working-directory: ./eczoo_sitegen/
- name: 'Inspect Yarn version'
run: 'yarn --version'
working-directory: ./eczoo_sitegen/
# --------------------------------
#
# SET UP CACHES
#
# Cache Yarn Modules
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
shell: bash
working-directory: ./eczoo_sitegen
- name: Restore yarn modules cache
uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: yarn-cache-folder-${{ hashFiles('**/yarn.lock', '.yarnrc.yml') }}
#restore-keys: |
# yarn-cache-folder-
# Cache citation information (downloaded information & compiled citations)
- name: Restore citations information cache
uses: actions/cache@v3
with:
path: eczoo_sitegen/_zoodb_citations_cache_LOCAL
#key: zoodb-citations-cache-LOCAL-${{ github.sha }}-${{ hashFiles('**/yarn.lock') }}
key: zoodb-citations-cache-LOCAL
#restore-keys: |
# zoodb-citations-cache-LOCAL-
- name: Initialize local citation information cache if applicable
run: |
if [ ! -e _zoodb_citations_cache_LOCAL/cache_downloaded_info.json ]; then
mkdir -p _zoodb_citations_cache_LOCAL/
cp _zoodb_citations_cache/*.json _zoodb_citations_cache_LOCAL/
fi
working-directory: ./eczoo_sitegen
# --------------------------------
#
# Install any missing modules via yarn
#
- name: Yarn install
run: 'yarn'
working-directory: ./eczoo_sitegen/
# --------------------------------
#
# Build the site!
#
- name: Build Site (yarn buildall)
run: 'yarn buildall'
working-directory: ./eczoo_sitegen/
env:
ECZOO_CITATIONS_CACHE_DIR: "_zoodb_citations_cache_LOCAL"
# ## To Debug S3 deployment w/o building the full site ...
#
# - name: 'DUMMY CREATE SITE FILES'
# run: 'mkdir -p site/_site/ && echo "<html>TEST</html>" >site/_site/index.html'
# working-directory: ./eczoo_sitegen/
# --------------------------------
# ### Old deploy script command, results in crude cache management
# - name: 'Deploy site to S3/Cloudfront'
# uses: reggionick/s3-deploy@v3
# with:
# folder: _site
# bucket: '${{ secrets.S3_BUCKET }}'
# bucket-region: '${{ secrets.S3_BUCKET_REGION }}'
# dist-id: '${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }}'
# invalidation: /
# delete-removed: true
# private: true
# #no-cache: true
# cache: 86400
- name: 'Deploy versioned assets to S3 with durable cache'
working-directory: ./eczoo_sitegen/
run: |-
yarn s3-deploy \
"./site/_site/vv/**" \
--bucket '${{ secrets.S3_BUCKET }}' \
--region '${{ secrets.S3_BUCKET_REGION }}' \
--cwd "./site/_site/" \
--etag \
--gzip xml,html,htm,js,css,ttf,otf,svg,txt \
--cacheControl 'max-age=31536000, s-max-age=31536000' \
--private
- name: 'Deploy site to S3/Cloudfront'
working-directory: ./eczoo_sitegen/
run: |-
yarn s3-deploy \
"./site/_site/**" \
--bucket '${{ secrets.S3_BUCKET }}' \
--region '${{ secrets.S3_BUCKET_REGION }}' \
--cwd ./site/_site \
--distId '${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }}' \
--etag \
--gzip xml,html,htm,js,css,ttf,otf,svg,txt \
--cacheControl 'max-age=7200, s-max-age=31536000' \
--invalidate "/*" \
--private
# --------------------------------
- name: Make archive of zoo files
run: 'zip -r ../../../eczoo_website_files.zip ./'
working-directory: ./eczoo_sitegen/site/_site/
- uses: actions/upload-artifact@v3
with:
name: eczoo_website_files
path: ./eczoo_website_files.zip
retention-days: 5