build-and-deploy-site #409
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: '22' | |
- 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 |