Deploy Jekyll site to AWS Production #112
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: Deploy Jekyll site to AWS Production | |
on: | |
workflow_dispatch: | |
inputs: | |
invalidate-cache: | |
description: "Invalidate CloudFront cache" | |
required: true | |
type: boolean | |
default: false | |
schedule: | |
# Run daily at 03:15 UTC (10:15/11:15 ET) | |
- cron: 15 3 * * * | |
permissions: | |
contents: read | |
id-token: write | |
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
concurrency: | |
group: "aws-prod" | |
cancel-in-progress: false | |
jobs: | |
# Build job | |
deploy: | |
runs-on: ubuntu-latest | |
environment: | |
name: production | |
url: https://oscal.io | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup Ruby | |
uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0 | |
with: | |
ruby-version: '3.1' | |
bundler-cache: true | |
cache-version: 0 | |
- name: Build with Jekyll | |
run: bundle exec jekyll build | |
env: | |
JEKYLL_ENV: production | |
- name: Upload artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: oscalio-content-prod | |
path: _site/ | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
role-to-assume: ${{ secrets.ROLE_ARN }} | |
aws-region: ${{ vars.AWS_REGION }} | |
- name: Copy files to the production environment | |
run: | | |
aws s3 sync . s3://${{ secrets.S3_BUCKET_NAME }} | |
working-directory: _site | |
- name: Invalidate CloudFront cache | |
if: ${{ inputs.invalidate-cache }} | |
run: | | |
aws cloudfront create-invalidation --distribution-id ${{ vars.DISTRIBUTION_ID }} --paths "/*" |