Add lambda tests and ci cd #38
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: Upload website to S3 | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
backend-testing: | |
runs-on: ubuntu-latest | |
name: Backend Testing | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
- name: Set up python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.11.9" | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r infra/lambda/requirements.txt | |
- name: Run tests | |
run: | | |
pytest --cov=infra/lambda | |
terraform: | |
name: Terraform Infrastructure | |
runs-on: ubuntu-latest | |
env: | |
AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}} | |
AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY}} | |
AWS_REGION: "ap-southeast-1" | |
TF_API_TOKEN: ${{secrets.TF_API_TOKEN}} | |
steps: | |
- name: checkout | |
uses: actions/checkout@v2 | |
- name: Add AWS profile credentials | |
run: | | |
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- name: Set up Terraform | |
uses: hashicorp/setup-terraform@v2 | |
with: | |
cli_config_credentials_token: ${{secrets.TF_API_TOKEN}} | |
- name: Init | |
id: init | |
working-directory: infra | |
run: terraform init | |
- name: plan | |
id: plan | |
working-directory: infra | |
run: terraform plan | |
- name: terraform apply | |
id: apply | |
working-directory: infra | |
run: terraform apply -auto-approve | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@master | |
- uses: jakejarvis/s3-sync-action@master | |
with: | |
args: --acl public-read --follow-symlinks --delete | |
env: | |
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: "ap-southeast-1" # optional: defaults to us-east-1 | |
SOURCE_DIR: "website" # optional: defaults to entire repository | |
# Invalidate Cloudfront | |
- name: Cloudfront Invalidation | |
uses: chetan/invalidate-cloudfront-action@master | |
env: | |
DISTRIBUTION: ${{ secrets.AWS_DISTRIBUTION_PRODUCTION }} | |
PATHS: "/*" | |
AWS_REGION: "ap-southeast-1" | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |