Skip to content

Merge pull request #26 from CityOfLosAngeles/ghi-25 #301

Merge pull request #26 from CityOfLosAngeles/ghi-25

Merge pull request #26 from CityOfLosAngeles/ghi-25 #301

name: Build and Deploy Development Static Site Dev # run this workflow when a push has been made. if a push has been made to the development branch it will deploy the site to the hosting environment
on: # run this workflow when a push has been made to `development` branch
push:
branches-ignore:
- production
repository_dispatch: # Listen for repository dispatch event from open-sdg-data-starter workflow
types: [dev_triggered_from_open-sdg-data-starter]
jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2' # Version range or exact version of a Ruby version to use, using semvers version range syntax.
- name: Install Ruby dependencies
run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle
- name: Install Jekyll and Build
run: bundle exec jekyll build --config _config.yml
- name: Test the HTML # test our rendered html files
run: bash scripts/test/html_proofer_staging.sh
- name: Zip site artifact # only zip the site if the push was made to the development branch
if: ${{ github.ref == 'refs/heads/development' }}
run: zip -r _site.zip _site
- name: Upload site artifact # only upload the zip if the push was made to the development branch
if: ${{ github.ref == 'refs/heads/development' }}
uses: actions/upload-artifact@v4
with:
name: site-deployment-dev
path: _site.zip
retention-days: 1 # delete the artifact after 1 day
deploy:
runs-on: ubuntu-22.04
needs: [build]
if: (github.ref == 'refs/heads/development')
environment:
name: development
url: https://${{ vars.SITE_DOMAIN_NAME }}
steps:
- name: Install AWS CLI
run: pip3 install awscli --upgrade --user # install the cli with upgrade to any requirements and into the subdir of the user
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4 # use the official GitHub Action from AWS to setup credentials
with:
role-to-assume: ${{ secrets.ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}
mask-aws-account-id: true
- name: Fetch site artifact
uses: actions/download-artifact@v4
with:
name: site-deployment-dev
- name: Unzip site artifact
run: unzip _site.zip
- name: Push Contents to S3 # push the current working directory to the S3 bucket
run: aws s3 sync _site/ s3://${{ secrets.S3_BUCKET_NAME }} --exclude ".git/*" --exclude ".github/*" --delete # have the bucket have the same content in the repo & exclude the git related directories.
- name: Invalidate CloudFront Cache # Invalidate the CloudFront Distribution Cache to get contents from the S3 bucket
run: aws cloudfront create-invalidation --distribution-id "$CDN_DISTRIBUTION_ID" --paths "/*"