Skip to content

Update ci/cd

Update ci/cd #1

Workflow file for this run

name: Website Docs Deployment
on:
push:
branches:
- dev
- staging
- master
permissions:
id-token: write
contents: read
jobs:
build_and_deploy:
runs-on: ubuntu-latest
environment: ${{ github.ref == 'refs/heads/master' && 'prod' || github.ref == 'refs/heads/staging' && 'staging' || github.ref == 'refs/heads/dev' && 'dev' }}
env:
AWS_ACCOUNT_ID: ${{ vars.AWS_ACCOUNT_ID }}
AWS_REGION: ${{ vars.AWS_REGION }}
PRODUCT: ${{ vars.PRODUCT }}
APPLICATION: ${{ vars.APPLICATION }}
ENVIRONMENT: ${{ vars.ENVIRONMENT }}
AWS_S3_BUCKET: ${{ vars.PRODUCT }}-${{ vars.APPLICATION }}-${{ vars.ENVIRONMENT }}-${{ vars.AWS_ACCOUNT_ID }}-${{ vars.AWS_REGION }}
BUILD_DIR: ./build
ALGOLIA_API_KEY: ${{ vars.ALGOLIA_API_KEY }}
ALGOLIA_APP_ID: ${{ vars.ALGOLIA_APP_ID }}
ALGOLIA_INDEX_NAME: ${{ vars.ALGOLIA_INDEX_NAME }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Prepare .npmrc
run: |
echo "//npm.pkg.github.com/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}" >> .npmrc
cat .npmrc
- name: Install dependencies
run: yarn install --immutable
- name: Building sources
run: CI=false yarn build
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/${{ env.PRODUCT }}-${{ env.APPLICATION }}-deployer-${{ env.AWS_REGION }}-${{ env.ENVIRONMENT }}
aws-region: ${{ env.AWS_REGION }}
- name: Deploy to S3
run: |
aws s3 sync ${{ env.BUILD_DIR }} s3://${{ env.AWS_S3_BUCKET }} --follow-symlinks --delete --no-progress
- name: Dynamically retreive the CloudFront Distribution Ids
run: |
cloudfrontdistids=$(aws cloudfront list-distributions | jq -r ".DistributionList.Items[].ARN")
for dist in $cloudfrontdistids; do
if [ $(aws cloudfront list-tags-for-resource --resource $dist --query "Tags.Items[?Key=='Application'].Value[]" --output text) == ${{ env.APPLICATION }} ] &&
[ $(aws cloudfront list-tags-for-resource --resource $dist --query "Tags.Items[?Key=='Environment'].Value[]" --output text) == ${{ env.ENVIRONMENT }} ]; then
CLOUDFRONT_DISTRIBUTION_IDS="$CLOUDFRONT_DISTRIBUTION_IDS ${dist##*/}"
fi
done
echo "Cloudfront distributionids : $CLOUDFRONT_DISTRIBUTION_IDS"
echo "CLOUDFRONT_DISTRIBUTION_IDS=$CLOUDFRONT_DISTRIBUTION_IDS" >> $GITHUB_ENV
- name: Invalidate CloudFront cache of distributions ${{ env.CLOUDFRONT_DISTRIBUTION_IDS }}
run: |
for dist in $CLOUDFRONT_DISTRIBUTION_IDS; do
echo "Create invalidation for distribution-id $dist"
aws cloudfront create-invalidation --distribution-id $dist --paths "/*"
done