-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (108 loc) · 4.16 KB
/
lambda_pytest.yml
File metadata and controls
112 lines (108 loc) · 4.16 KB
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
name: lambda_pytest
on:
workflow_dispatch:
workflow_call:
inputs:
python_version:
type: string
required: true
default: "3.11"
app_path:
description: "The app to test"
type: string
required: true
default: "app_path"
app_path_prefix:
description: "The path to the app"
type: string
required: true
compose_path:
description: "The path to the docker-compose file"
type: string
need_compose:
description: "List of apps that need docker-compose"
type: string
aws_role_arn:
description: "The role to assume"
type: string
required: true
codeartifact_domain:
description: "The codeartifact domain"
type: string
required: true
default: "domain_name"
codeartifact_domain_owner:
description: "The codeartifact domain owner"
type: string
required: true
default: "123456789012"
codeartifact_repository:
description: "The codeartifact repository"
type: string
required: true
default: "repository_name"
tox_path:
description: "The path to the tox file"
type: string
required: true
default: "/tox/path"
aws_region:
description: "The region to deploy to"
type: string
required: true
default: "us-west-2"
# Permission can be added at job level or workflow level
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
pytest:
runs-on: ubuntu-latest
concurrency:
group: "pytest ${{inputs.app_path}} - ${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
cancel-in-progress: true
timeout-minutes: 5
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 1
sparse-checkout: |
${{inputs.app_path_prefix}}/${{inputs.app_path}}/
${{inputs.compose_path}}
- name: Set up Python ${{ inputs.python_version }}
id: py_setup
uses: actions/setup-python@v6
with:
python-version: ${{ inputs.python_version }}
- name: pip cache
id: cache-pip
uses: actions/cache@v5
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: "${{ inputs.aws_role_arn }}"
role-session-name: GitHub_to_AWS_via_FederatedOIDC
aws-region: ${{ inputs.aws_region }}
- name: Install dependencies
run: |
CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token --domain ${{inputs.codeartifact_domain}} --domain-owner ${{inputs.codeartifact_domain_owner}} --query authorizationToken --output text --duration-seconds 900`
echo "AWS_INDEX_URL=https://aws:$CODEARTIFACT_AUTH_TOKEN@${{inputs.codeartifact_domain}}-${{inputs.codeartifact_domain_owner}}.d.codeartifact.us-west-2.amazonaws.com/pypi/${{inputs.codeartifact_repository}}/simple/" >> $GITHUB_ENV
pip install tox
- name: Test ${{inputs.app_path}} with pytest
env:
EXEC_ENV: "docker"
# Have tried caching docker images but restoring the cache and loading the image is actually slower than just pulling from docker hub
# Add these environment variables to pass AWS credentials to tox/pytest
AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ env.AWS_SECRET_ACCESS_KEY }}
AWS_SESSION_TOKEN: ${{ env.AWS_SESSION_TOKEN }}
run: |
if [[ "${{ inputs.need_compose }}" == *"${{inputs.app_path}}"* ]]; then
docker compose -f ${{inputs.compose_path}}/docker-compose.yml up --detach --quiet-pull
fi
tox run -c ./${{inputs.tox_path}}/tox.ini --root ${{inputs.app_path_prefix}}/${{inputs.app_path}} --workdir ${{inputs.app_path_prefix}}/${{inputs.app_path}}