Skip to content

DevOps: Create GitHub Actions CI Files #4

DevOps: Create GitHub Actions CI Files

DevOps: Create GitHub Actions CI Files #4

Workflow file for this run

name: 'Continuous Integration GitHub Actions Workflow'
on:
push:
pull_request:
workflow_dispatch:
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node: [20, 22]
name: Run tests on ${{ matrix.os }} with Node ${{ matrix.node }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Codebase
uses: actions/checkout@v4
- name: Setup Node ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
scans:
# do code scanning stuff here
needs: test
name: Code Scanning
runs-on: ubuntu-latest
steps:
- name: Checkout Codebase
uses: actions/checkout@v4
build-staging:
# build stuff here
needs: test
environment: staging
name: Build and Deploy Staging Environment
runs-on: ubuntu-latest
steps:
- name: Checkout Codebase
uses: actions/checkout@v4
- name: Setup Node 20
uses: actions/setup-node@v4
with:
node-version: 20
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Build and Deploy Frontend
working-directory: peer-prep
run: |
npm i
npm run build
- name: Upload to S3
working-directory: peer-prep/dist
run: |
aws s3 sync . s3://peerprep-frontend-bucket
build-production:
# build stuff here
needs: build-staging
environment: production
name: Build for Production Environment
runs-on: ubuntu-latest
steps:
- name: Checkout Codebase
uses: actions/checkout@v4
- name: Setup Node 20
uses: actions/setup-node@v4
with:
node-version: 20
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
env:
AWS_REGION: 'ap-southeast-1'
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Build and Deploy Frontend
working-directory: peer-prep
run: |
npm i
npm run build
- name: Upload to S3
working-directory: peer-prep/dist
run: |
aws s3 sync . s3://peerprep-frontend-bucket
images:
# build images here
needs:
- build-staging
- build-production
name: Build Staging Images
runs-on: ubuntu-latest
steps:
- name: Checkout Codebase
uses: actions/checkout@v4
# deploy:
# # deploy stuff here
# needs: images
# name: Deploy images and infrastructure here
# strategy:
# matrix:
# providers:
# [
# {
# init: './terraform/init/aws',
# deploy: './terraform/env/aws',
# csp: 'AWS',
# },
# {
# init: './terraform/init/aws',
# deploy: './terraform/env/aws',
# csp: 'GCP',
# },
# ]
# runs-on: ubuntu-latest
# steps:
# - name: Checkout Codebase
# uses: actions/checkout@v4
# - name: Setup Terraform for ${{ matrix.providers.csp }}
# uses: hashicorp/setup-terraform@v3
# - name: Ensure Provision of Remote State Backends on ${{ matrix.providers.csp }}
# working-directory: ${{ matrix.providers.init }}
# run: terraform init
# - name: Check and Deploy State Backends on ${{ matrix.providers.csp }}
# working-directory: ${{ matrix.providers.init }}
# run: terraform apply -auto-approve
# continue-on-error: true # assumes that the buckets are already provisioned
# # commands taken from https://github.com/gruntwork-io/terragrunt-action
# - name: Initialise Terraform Infrastructure with Terragrunt on ${{ matrix.providers.csp }}
# uses: gruntwork-io/terragrunt-action@v2
# with:
# tf_version: ''
# tg_version: ''
# tg_dir: ${{ matrix.providers.deploy }}
# tg_command: 'plan'
# - name: Setup Infrastructure with Terragrunt on ${{ matrix.providers.csp }}
# uses: gruntwork-io/terragrunt-action@v2
# with:
# tf_version: ''
# tg_version: ''
# tg_dir: ${{ matrix.providers.deploy }}
# tg_command: 'apply'