-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (92 loc) · 2.85 KB
/
pipeline.yaml
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Pipeline
on:
push:
branches:
- test
- main
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
env:
AWS_REGION: us-east-1
ENVIRONMENT: ${{ github.ref_name == 'main' && 'prod' || github.ref_name == 'test' && 'test' }}
jobs:
test-lambda:
runs-on: ubuntu-22.04
defaults:
run:
working-directory: lambda_code
steps:
- uses: actions/checkout@v3
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
# Install dependencies
- name: Set up Python
run: uv python install
- name: Install the project
run: uv sync --group test
# Run unit tests
# - name: Run tests
# run: uv run pytest -s .
build-lambda:
runs-on: ubuntu-22.04
needs: test-lambda
defaults:
run:
working-directory: lambda_code
steps:
- uses: actions/checkout@v3
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
# Install dependencies
- name: Set up Python
run: uv python install
- name: Build Lambda
run: |
mkdir -p build
cp -r src/* build/
uv pip compile pyproject.toml -o build/requirements.txt
uv pip install -r build/requirements.txt --target build --python-platform x86_64-manylinux_2_40 --only-binary=:all:
- name: Upload build as artifact
uses: actions/upload-artifact@v4
with:
name: lambda-code-build
path: lambda_code/build
if-no-files-found: error
deploy-stack:
runs-on: ubuntu-22.04
needs: build-lambda
defaults:
run:
working-directory: terraform
steps:
- uses: actions/checkout@v3
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: lambda-code-build
path: lambda_code/build
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
audience: sts.amazonaws.com
aws-region: ${{ env.AWS_REGION }}
role-to-assume: arn:aws:iam::639269844451:role/github-actions
role-session-name: testing-deployment
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- name: Terraform Init
run: terraform init
- name: Select or Create Terraform Workspace
run: |
terraform workspace list || echo "Workspace list unavailable"
terraform workspace select --or-create ${{ env.ENVIRONMENT }}
- name: Terraform Plan
run: terraform plan
- name: Terraform Apply
run: terraform apply -auto-approve