-
Notifications
You must be signed in to change notification settings - Fork 3
157 lines (143 loc) · 3.96 KB
/
test_integration.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
name: Integration Tests
on:
workflow_dispatch:
inputs:
environment:
required: true
description: 'The environment to run the tests in'
type: environment
enabled:
required: false
description: 'Whether to run the tests'
type: boolean
default: true
infra:
required: false
description: An infra to use. Empty creates one.
type: string
logs:
required: false
description: 'Whether to log the tests'
type: boolean
default: false
workflow_call:
inputs:
environment:
required: true
description: 'The environment to run the tests in'
type: string
enabled:
required: false
description: 'Whether to run the tests'
type: boolean
default: true
infra:
required: false
description: An infra to use. Empty creates one.
type: string
logs:
required: false
description: 'Whether to log the tests'
type: boolean
default: false
jobs:
integration_tests:
name: Integration
runs-on: ubuntu-latest
environment:
name: ${{ inputs.environment }}
env:
DUPLO_HOST: ${{ vars.DUPLO_HOST }}
DUPLO_TOKEN: ${{ secrets.DUPLO_TOKEN }}
steps:
# checkout code
- name: Checkout Code
uses: actions/checkout@v4
if: inputs.enabled
# install python
- name: Set up Python
uses: actions/setup-python@v5
if: inputs.enabled
with:
python-version: 3.12
cache: 'pip'
# install the project
- name: Install dependencies
if: inputs.enabled
run: |
pip install .[build,test]
- name: Setup Args
id: pytest_args
env:
INFRA: ${{ inputs.infra }}
LOGS: ${{ inputs.logs }}
run: |
ARGS=(
"src"
"--junit-xml=test-results.xml"
"-m integration"
)
# if infra is set, add it to the args
if [ -n "$INFRA" ]; then
ARGS+=("--infra" "$INFRA")
fi
# if the logs are set, add it to the args
if [ "$LOGS" = "true" ]; then
ARGS+=("-s")
fi
echo "PYTEST_ARGS=${ARGS[*]}" >> $GITHUB_OUTPUT
# run the tests
- name: Test with pytest
if: inputs.enabled
run: pytest ${{ steps.pytest_args.outputs.PYTEST_ARGS }}
- name: Surface failing tests
if: always() && inputs.enabled
uses: pmeier/pytest-results-action@main
with:
path: test-results.xml
summary: true
display-options: fEX
fail-on-empty: true
cleanup:
name: Cleanup
runs-on: ubuntu-latest
if: always()
needs: integration_tests
steps:
# checkout code
- name: Checkout Code
uses: actions/checkout@v4
# install python
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
cache: 'pip'
# install the project
- name: Install dependencies
run: |
pip install .
pip install awscli
- name: Duplo JIT for AWS
id: duplo-jit-aws
shell: bash
env:
AWS_REGION: us-east-2
run: >-
duploctl jit aws -q '{
AWS_ACCESS_KEY_ID: AccessKeyId,
AWS_SECRET_ACCESS_KEY: SecretAccessKey,
AWS_SESSION_TOKEN: SessionToken,
AWS_REGION: Region
}' -o env --admin >> $GITHUB_OUTPUT
- name: Configure AWS IAM Credentials
id: aws-iam
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ steps.duplo-jit-aws.outputs.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ steps.duplo-jit-aws.outputs.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ steps.duplo-jit-aws.outputs.AWS_SESSION_TOKEN }}
aws-region: ${{ steps.duplo-jit-aws.outputs.AWS_REGION }}
mask-aws-account-id: true
- name: Run Cleanup
run: ./scripts/aws_cleanup.sh