Skip to content

Merge pull request #9 from Axcient/staging #17

Merge pull request #9 from Axcient/staging

Merge pull request #9 from Axcient/staging #17

Workflow file for this run

name: Deploy
on:
workflow_dispatch:
push:
branches:
- main
- staging
- production
defaults:
run:
shell: bash
permissions:
id-token: write
contents: read
jobs:
set-environment:
runs-on: ubuntu-latest
steps:
- name: Set environment based on ref
id: set_environment
run: |
echo "Starting environment setup..."
echo "Running on branch ${{ github.ref_name }}"
if [ "${{ github.ref_name }}" = "production" ]; then
echo "Setting environment to Production"
echo "env_name=Production" >> $GITHUB_OUTPUT
echo "using Production environment"
elif [ "${{ github.ref_name }}" = "staging" ]; then
echo "Setting environment to Staging"
echo "env_name=Staging" >> $GITHUB_OUTPUT
echo "using Staging environment"
else
echo "Setting environment to Development"
echo "env_name=Development" >> $GITHUB_OUTPUT
echo "using Development environment"
fi
echo "Environment setup complete."
outputs:
env_name: ${{steps.set_environment.outputs.env_name}}
deploy:
needs: set-environment
runs-on: ubuntu-latest
environment:
name: ${{ needs.set-environment.outputs.env_name }}
steps:
- name: Checking out files
uses: actions/checkout@v3
- name: Configuring AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.IAM_ROLE_GITHUB }}
role-session-name: GitHub-Action-Role
aws-region: ${{ vars.AWS_REGION }}
- name: Deploying files
env:
S3_BUCKET: ${{ vars.S3_BUCKET }}
run: |
echo "Starting S3 deployment..."
echo "Deploying files from ./dist/ to s3://$S3_BUCKET/"
aws s3 cp ./dist/ s3://$S3_BUCKET/dist/ --recursive --only-show-errors
echo "Deploying files from ./specs/ to s3://$S3_BUCKET/dist/"
aws s3 cp ./specs/ s3://$S3_BUCKET/specs/ --recursive --only-show-errors
echo "Deploying index.html to s3://$S3_BUCKET/specs/"
aws s3 cp ./index.html s3://$S3_BUCKET/ --only-show-errors
echo "S3 deployment complete."
- name: Invalidate CloudFront Cache
env:
AWS_REGION: ${{ vars.AWS_REGION }}
DISTRIBUTION_ID: ${{ vars.DISTRIBUTION_ID }}
run: |
echo "Invalidating CloudFront cache..."
aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths '/*' --region $AWS_REGION
echo "CloudFront cache invalidation complete."