Skip to content

Merge pull request #119 from mcliff1/mcliff1-patch-1 #220

Merge pull request #119 from mcliff1/mcliff1-patch-1

Merge pull request #119 from mcliff1/mcliff1-patch-1 #220

Workflow file for this run

# this workflow will publish to an AWS S3 Bucket
#
# based off branch we will look up and gain credentials from the environment
# DEPLOY_{env}_KEY, SECRET, ROLE
#
# ref: https://github.com/mcliff1/cliffconsulting/new/master?filename=.github%2Fworkflows%2Faws.yml&workflow_template=aws
name: AWS Publish
on:
#pull_request:
# branches:
# - master
# - release/dev
push:
branches:
- master
- release/dev
#on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [22.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
# https://github.com/marketplace/actions/configure-aws-credentials-action-for-github-actions
- name: Configuration for Test
uses: aws-actions/configure-aws-credentials@v4
if: ${{ github.ref == 'refs/heads/release/dev' }}
with:
aws-access-key-id: ${{ secrets.TEST_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.TEST_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
role-to-assume: ${{ secrets.TEST_AWS_ROLE_ARN }}
role-duration-seconds: 1800
- name: Configuration for Production
uses: aws-actions/configure-aws-credentials@v4
if: ${{ github.ref == 'refs/heads/master' }}
with:
aws-access-key-id: ${{ secrets.PROD_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.PROD_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
role-to-assume: ${{ secrets.PROD_AWS_ROLE_ARN }}
role-duration-seconds: 1800
- name: Build And Deploy
run: |
nodejs -v
aws sts get-caller-identity
ACCOUNT_NAME=$(aws ssm get-parameter --name /foundation/account/name --query 'Parameter.Value' --output text)
echo $ACCOUNT_NAME
BUCKET=$(aws ssm get-parameter --name /app/cdn/${ACCOUNT_NAME}-cliffconsulting/bucket --query 'Parameter.Value' --output text)
echo $BUCKET
npm install
npm run build
aws s3 sync ./build s3://${BUCKET}/ --delete
STACK_NAME=${ACCOUNT_NAME}-cliffconsulting
DISTRIBUTION=$(aws cloudformation --region us-east-1 describe-stacks --stack-name ${STACK_NAME} --query 'Stacks[0].Outputs[?OutputKey==`distributionid`].OutputValue' --output text)
aws cloudfront create-invalidation --distribution-id ${DISTRIBUTION} --paths "/*"
if: ${{ github.ref == 'refs/heads/release/dev' || github.ref == 'refs/heads/master' }}