-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (97 loc) · 3.11 KB
/
sam-pipeline.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
on:
push:
branches:
- main
- dev
paths:
- 'src/**'
- 'tests/**'
- '.github/workflows/**'
- 'template.yml'
- 'samconfig.toml'
- 'requirements.txt'
- 'docker/**'
jobs:
test:
# Containers must run in Linux based operating systems
runs-on: ubuntu-latest
# Docker Hub image that `container-job` executes in
# Service containers to run with `container-job`
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: 'pip'
- name: Execute unit tests and coverage report
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r tests/requirements.txt; fi
- name: Run unit tests
run: python -m coverage run -m unittest -v tests/*.py
env:
# The hostname used to communicate with the PostgreSQL service container
POSTGRES_HOST: localhost
# The default PostgreSQL port
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
STAGE: local
- name: Run coverage report
run: python -m coverage report -m
build-and-deploy:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- uses: aws-actions/setup-sam@v2
with:
use-installer: true
- uses: aws-actions/configure-aws-credentials@v1
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: Set environment for branch
run: |
if [[ $GITHUB_REF_NAME == 'main' ]]; then
echo "ENV_STAGE=prod" >> "$GITHUB_ENV"
else
echo "ENV_STAGE=dev" >> "$GITHUB_ENV"
fi
# sam build
- name: Run SAM Build
run: sam build --use-container
# sam deploy
- name: Run SAM Deploy
run: |
sam deploy --s3-bucket ${{ secrets.AWS_ARTIFACTS_BUCKET_NAME }} \
--stack-name stori-transactions-email-sender-${{ env.ENV_STAGE }} \
--parameter-overrides \
BucketName=${{ secrets.AWS_BUCKET_NAME_FILES_PREFIX }}-${{ env.ENV_STAGE }} \
SecretName=${{ secrets.AWS_SECRET_NAME }} \
Stage=${{ env.ENV_STAGE }} \
--no-confirm-changeset --no-fail-on-empty-changeset