Skip to content

build-and-deploy-site #542

build-and-deploy-site

build-and-deploy-site #542

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 && (cd eczoo_sitegen && git log -1)
# --------------------------------
# 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: zoodb-citations-cache-LOCAL-${{ github.sha }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
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.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@v4
with:
name: eczoo_website_files
path: ./eczoo_website_files.zip
retention-days: 5
include-hidden-files: true