Skip to content

updated indicator 2-3-2 #294

updated indicator 2-3-2

updated indicator 2-3-2 #294

name: Build and Deploy Development Data
on: # 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
push:
branches-ignore:
- production
jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5 # sets up python in our environment
with:
python-version: '3.11' # install python version 3.x, default architecture is x64
# this Action should follow steps to set up Python build environment
- name: Install Python dependencies requirements
run: pip3 install -r scripts/requirements.txt
- name: Check site data
run: python3 scripts/check_data.py
- name: Build site data
run: python3 scripts/build_data.py
- 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 }}
env:
# Service Account info to trigger open-sdg-site-starter workflow
# PAT_USERNAME: ${{ secrets.PAT_USERNAME }}
# PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
CLOUDFRONT_DIST_ID: ${{ secrets.CDN_DISTRIBUTION_ID }}
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 "/*"
# TODO: Revisit the last two jobs later
# - name: Check Invalidation is Complete
# run: ./scripts/check_invalidations.sh
# - name: Trigger open-sdg-site-starter workflow
# run: |
# curl \
# -L \
# -X POST \
# -H "Accept: application/vnd.github+json" \
# -H "Authorization: Bearer $PAT_TOKEN"\
# -H "X-GitHub-Api-Version: 2022-11-28" \
# https://api.github.com/repos/CityOfLosAngeles/open-sdg-site-starter/actions/workflows/BuildNDeployDev.yml/dispatches \
# -d '{"ref":"ghi-23"}'2