Skip to content

Integration Tests

Integration Tests #10

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