Deploying v0.2.22 to test #119
Workflow file for this run
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 A&R-Admin Test | |
run-name: Deploying ${{ github.ref_name }} to test | |
on: | |
push: | |
tags: | |
- "*" | |
workflow_dispatch: | |
inputs: | |
releaseTag: | |
description: "Tag of version to be promoted to test" | |
required: true | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
deploy-admin: | |
runs-on: ubuntu-latest | |
environment: test | |
strategy: | |
max-parallel: 1 | |
matrix: | |
node-version: [18.x] | |
defaults: | |
run: | |
working-directory: "./" | |
steps: | |
### Checkout GitHub Repo | |
- name: Checkout repo | |
uses: actions/checkout@v3 | |
- shell: bash | |
env: | |
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} | |
run: | | |
curl -X POST -H 'Content-Type: application/json' $WEBHOOK_URL --data '{"text":"A&R - Deploy Admin Test"}' | |
### Install if no cache exists ### | |
- name: Setup node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: "yarn" | |
cache-dependency-path: "./yarn.lock" | |
- run: yarn install --silent --frozen-lockfile | |
### Build if no cache exists ### | |
- name: Cache Admin Build | |
id: cache-admin-build | |
uses: actions/cache@v3 | |
with: | |
path: | | |
./dist | |
key: ${{ github.sha }}-dist | |
- name: Run yarn build | |
if: steps.cache-admin-build.outputs.cache-hit != 'true' | |
env: | |
GH_HASH: ${{ github.sha }} | |
run: | | |
sed 's@localConfigEndpoint@'true'@g' src/env.js.template | sed 's@localGHHash@'"$GH_HASH"'@g' > src/env.js | |
yarn build | |
### Setup AWS SAM | |
- name: Setup AWS SAM | |
uses: aws-actions/setup-sam@v2 | |
with: | |
use-installer: true | |
### Assume AWS IAM Role | |
- name: Get AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} | |
role-session-name: GitHub_to_AWS_via_FederatedOIDC | |
aws-region: ${{ vars.AWS_REGION }} | |
### SAM Build | |
- name: Cache SAM Build | |
id: cache-sam-build | |
uses: actions/cache@v3 | |
with: | |
path: | | |
./.aws-sam | |
key: ${{ github.sha }}-sam-cache | |
- name: Run sam build | |
if: steps.cache-sam-build.outputs.cache-hit != 'true' | |
run: | | |
sam build --cached | |
### Prevent prompts and failure when the stack is unchanged | |
- name: SAM deploy | |
env: | |
STACK_NAME: ${{ vars.AR_ADMIN_STACK_NAME }} | |
PROJECT_NAME: ${{ vars.AR_ADMIN_PROJECT_NAME }} | |
DIST_ORIGIN_PATH: "latest" | |
API_GATEWAY_ID: ${{ vars.AR_API_ID }} | |
ENV: ${{ vars.ENVIRONMENT_STAGE }} | |
AWS_REGION: ${{ vars.AWS_REGION }} | |
API_STAGE: ${{ vars.AR_API_STAGE }} | |
DOMAIN_NAME: ${{ vars.DOMAIN_NAME }} | |
AWS_CERTIFICATE_ARN: ${{ vars.AWS_CERTIFICATE_ARN }} | |
BASE_HREF: "/" | |
run: | | |
sam deploy --stack-name $STACK_NAME --no-confirm-changeset --no-fail-on-empty-changeset --parameter-overrides \ | |
"ProjectName=$PROJECT_NAME \ | |
DistOriginPath=$DIST_ORIGIN_PATH \ | |
ApiGatewayId=$API_GATEWAY_ID \ | |
Env=$ENV \ | |
AWSRegion=$AWS_REGION \ | |
ApiStage=$API_STAGE \ | |
EnvDomainName=$DOMAIN_NAME \ | |
DomainCertificateArn=$AWS_CERTIFICATE_ARN \ | |
BaseHref=$BASE_HREF" | |
### Upload dist to S3 ### | |
- name: Deploy to S3 | |
env: | |
S3_BUCKET: ${{ vars.AR_ADMIN_PROJECT_NAME }}-${{ vars.ENVIRONMENT_STAGE }} | |
DIR_NAME: ${{ github.event.inputs.releaseTag || github.sha }} | |
WORKING_DIRECTORY: ./ | |
run: | | |
aws s3 sync dist/$WORKING_DIRECTORY s3://$S3_BUCKET/$DIR_NAME | |
aws s3 rm s3://$S3_BUCKET/ --recursive --exclude "*" --include "latest/*" | |
aws s3 sync dist/$WORKING_DIRECTORY s3://$S3_BUCKET/latest/ | |
- name: Invalidate CloudFront | |
uses: chetan/invalidate-cloudfront-action@v2 | |
env: | |
DISTRIBUTION: ${{ secrets.DISTRIBUTION }} | |
PATHS: "/*" | |
- shell: bash | |
env: | |
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} | |
run: | | |
curl -X POST -H 'Content-Type: application/json' $WEBHOOK_URL --data '{"text":"A&R Deploy Admin Test Complete"}' | |