Merge pull request #339 from cagov/create-pull-request/patch #392
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: 11ty build Production Site | |
# site: http://odi-publishing-11ty-sandbox.ca.gov.s3-website-us-west-1.amazonaws.com/ | |
# s3 bucket: odi-publishing-11ty-sandbox.ca.gov | |
# editor: https://editor-dev-cannabis-ca-gov.pantheonsite.io/ | |
on: | |
workflow_run: | |
workflows: ["Update static content [main]"] | |
types: ['completed'] | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
concurrency: | |
group: sync_deployments | |
cancel-in-progress: true | |
jobs: | |
build_deploy: | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Use Node.js 16.x | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
cache: 'npm' | |
- name: Install packages | |
run: | | |
mkdir dist | |
npm ci --production --verbose | |
- name: Build 11ty | |
run: | | |
SITE_ENV=production DOMAIN=odi-publishing-11ty-sandbox.ca.gov npm run build | |
- name: Write robots.txt | |
run: | | |
echo 'User-agent: *' > docs/robots.txt | |
echo 'Disallow: /' >> docs/robots.txt | |
echo 'Sitemap: https://odi-publishing-11ty-sandbox.ca.gov/sitemap.xml' >> docs/robots.txt | |
# Deploy built files to separate branch that contains only built files that github pages uses to serve site | |
- name: Deploy to github pages branch | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./docs | |
publish_branch: deploy_production | |
# Set up AWS CLI | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-west-1 | |
node-version: 16.x | |
# Deploy to odi-publishing-11ty-sandbox.ca.gov | |
- name: Deploy to S3 (odi-publishing-11ty-sandbox.ca.gov) | |
# jbum added --exclude | |
run: aws s3 sync --follow-symlinks --delete ./docs s3://odi-publishing-11ty-sandbox.ca.gov --exclude 'wp-content/uploads/*' | |
# Reset the cache-control headers on static assets on production S3 bucket | |
- name: Reset cache-control on fonts | |
uses: prewk/s3-cp-action@v2 | |
with: | |
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws_region: 'us-west-1' # optional: defaults to us-east-1 | |
source: './docs/fonts' | |
dest: 's3://odi-publishing-11ty-sandbox.ca.gov/fonts' | |
flags: --recursive --cache-control max-age=15552000 | |
- name: Reset cache-control on assets | |
uses: prewk/s3-cp-action@v2 | |
with: | |
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws_region: 'us-west-1' # optional: defaults to us-east-1 | |
source: './docs/assets' | |
dest: 's3://odi-publishing-11ty-sandbox.ca.gov/assets' | |
flags: --recursive --cache-control max-age=15552000 | |
# - name: Reset cache-control on media | |
# uses: prewk/s3-cp-action@v2 | |
# with: | |
# aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
# aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
# aws_region: 'us-west-1' # optional: defaults to us-east-1 | |
# source: './docs/wp-content/uploads/sites/2' | |
# dest: 's3://odi-publishing-11ty-sandbox.ca.gov/wp-content/uploads/sites/2' | |
# flags: --recursive --cache-control max-age=15552000 | |
# - name: Invalidate Cloudfront (odi-publishing-11ty-sandbox.ca.gov) | |
# run: aws cloudfront create-invalidation --distribution-id XXXXXXXXXX --paths "/*" | |
- name: Deploy redirects | |
run: | | |
AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} npm run deploy:redirects | |