-
Notifications
You must be signed in to change notification settings - Fork 114
221 lines (174 loc) · 6.93 KB
/
Copy pathdevsite-build-and-deploy.yml
File metadata and controls
221 lines (174 loc) · 6.93 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
name: 'devsite-build-and-deploy'
on:
workflow_dispatch:
inputs:
eczoo_data_repo:
description: 'eczoo_data repo:'
required: true
type: string
default: 'errorcorrectionzoo/eczoo_data'
eczoo_data_commit:
description: 'eczoo_data branch/ref/commit:'
required: true
type: string
default: 'main'
eczoo_sitegen_repo:
description: 'eczoo_sitegen repo:'
required: true
type: string
default: 'errorcorrectionzoo/eczoo_sitegen'
eczoo_sitegen_commit:
description: 'eczoo_sitegen branch/ref/commit:'
required: true
type: string
default: 'main'
jobs:
devsite-build-and-deploy:
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:
- name: 'Message & devsite info'
run: |
echo 'DATA: ${{ inputs.eczoo_data_repo }} - ${{ inputs.eczoo_data_commit }}' >>ECZOO_DEVSITE_INFO.txt
echo 'SITEGEN: ${{ inputs.eczoo_sitegen_repo }} - ${{ inputs.eczoo_sitegen_commit }}' >>ECZOO_DEVSITE_INFO.txt
cat ECZOO_DEVSITE_INFO.txt
- name: 'Check out eczoo_data code'
run: |
git clone https://github.com/${{ inputs.eczoo_data_repo }} eczoo_data
(cd eczoo_data && git checkout '${{ inputs.eczoo_data_commit }}')
# Check out site generation code
- name: 'Check out eczoo_sitegen code'
run: |
git clone https://github.com/${{ inputs.eczoo_sitegen_repo }} eczoo_sitegen
(cd eczoo_sitegen && git checkout '${{ inputs.eczoo_sitegen_commit }}')
# --------------------------------
# Install NodeJS
- uses: actions/setup-node@v3
with:
#cache: 'yarn'
node-version: '22'
- name: 'Enable Yarn (corepack enable)'
run: 'corepack enable'
working-directory: ./eczoo_sitegen/
- name: 'Inspect Yarn version'
run: 'yarn --version'
working-directory: ./eczoo_sitegen/
# --------------------------------
# Install Ruby Gems for the 'anystyle' command-line utility.
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.4
- name: Install AnyStyle.io for parsing manually-formatted citations
run: gem install anystyle-cli
# --------------------------------
#
# SET UP CACHES
#
# !!!! Make sure "key:" is unique to the setting! A cache hit from the primary key
# causes the cache not to be saved back, as Github assumes that the cache was already
# computed.
# 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: devsite-zoodb-citations-cache-LOCAL-${{ hashFiles('ECZOO_DEVSITE_INFO.txt') }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
devsite-zoodb-citations-cache-LOCAL-
- name: Initialize local citation information cache if applicable
run: |
mkdir -p _zoodb_citations_cache_LOCAL
for f in _zoodb_citations_cache/*.json; do
if [ ! -e "_zoodb_citations_cache_LOCAL/$(basename "$f")" ] ; then
echo "Citations cache file ‘$f’ not found, using sitegen repo cache file"
cp "$f" _zoodb_citations_cache_LOCAL/
fi
done
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.DEVSITE_S3_BUCKET }}'
# bucket-region: '${{ secrets.DEVSITE_S3_BUCKET_REGION }}'
# dist-id: '${{ secrets.DEVSITE_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.DEVSITE_S3_BUCKET }}' \
--region '${{ secrets.DEVSITE_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.DEVSITE_S3_BUCKET }}' \
--region '${{ secrets.DEVSITE_S3_BUCKET_REGION }}' \
--cwd ./site/_site \
--distId '${{ secrets.DEVSITE_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_devsite_website_files.zip ./'
working-directory: ./eczoo_sitegen/site/_site/
- uses: actions/upload-artifact@v4
with:
name: eczoo_devsite_website_files
path: ./eczoo_devsite_website_files.zip
retention-days: 5
include-hidden-files: true