Skip to content

Deploying v0.0.3 (API) to test #3

Deploying v0.0.3 (API) to test

Deploying v0.0.3 (API) to test #3

name: Deploy reserve-rec-api Test
run-name: Deploying ${{ github.ref_name }} (API) 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:
runs-on: ubuntu-latest
environment: test
strategy:
max-parallel: 1
matrix:
node-version: [20.x]
defaults:
run:
working-directory: "./${{ vars.PDR_API_DIRECTORY }}"
steps:
### Checkout GitHub Repo
- name: Checkout repo
uses: actions/checkout@v4
# - shell: bash
# env:
# WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
# run: |
# curl -X POST -H 'Content-Type: application/json' $WEBHOOK_URL --data '{"text":"Reserve Rec API Test"}'
### Tag not found
- name: Tag not found
if: ${{ failure() }}
run: |
echo "::error::Git Tag not found, please double check input"
exit 1
### 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@v4
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@v4
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.STACK_NAME }}
TABLE_NAME: ${{ vars.TABLE_NAME }}
TABLE_NAME_AUDIT: ${{ vars.TABLE_NAME_AUDIT }}
STAGE: ${{ vars.STAGE }}
ACCOUNT_ID: ${{ secrets.ACCOUNT_ID }}
DOMAIN_NAME: ${{ vars.DOMAIN_NAME }}
KMS_KEY_ID: ${{ secrets.KMS_KEY_ID }}
INSTANCE_COUNT: ${{ vars.INSTANCE_COUNT }}
INSTANCE_TYPE: ${{ vars.INSTANCE_TYPE }}
OPEN_SEARCH_MAIN_INDEX: ${{ vars.OPEN_SEARCH_MAIN_INDEX }}
EBS_IOPS: ${{ vars.EBS_IOPS }}
run: |
sam deploy --stack-name $STACK_NAME --no-confirm-changeset --no-fail-on-empty-changeset --parameter-overrides "TableName=$TABLE_NAME" "TableNameAudit=$TABLE_NAME_AUDIT" "Stage=$STAGE" "AccountId=$ACCOUNT_ID" "DomainName=$DOMAIN_NAME" "KMSKeyId=$KMS_KEY_ID" "InstanceCount=$INSTANCE_COUNT" "InstanceType=$INSTANCE_TYPE" "OpenSearchMainIndex=$OPEN_SEARCH_MAIN_INDEX" "EBSIops=$EBS_IOPS"
# - shell: bash
# env:
# WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
# run: |
# curl -X POST -H 'Content-Type: application/json' $WEBHOOK_URL --data '{"text":"Data Register - Deploy Reserve Rec API Test Complete"}'