Skip to content

Refactor unit test workflow; add smoke test workflow #22

Refactor unit test workflow; add smoke test workflow

Refactor unit test workflow; add smoke test workflow #22

Workflow file for this run

# SPDX-License-Identifier: Apache-2.0
name: "Run unit tests via Tox::pytest"
# This tests should run only those tests that are marked as 'fast.'
# The opposite are those that would require the mark 'slow,' which would
# include longer-running integration and smoke tests.
#
# Essentially, this workflow should be used frequently for cheap tests,
# and a 'slow' marked workflow will be used later in review, manually triggered,
# to verify integration correctness.
on:
# run against every merge commit to 'main' and release branches
push:
branches:
- main
- release-*
# only run on PRs that touch certain regex paths
pull_request_target:
branches:
- main
- release-*
paths:
# note this should match the merging criteria in 'mergify.yml'
- "**.py"
- "pyproject.toml"
- "requirements**.txt"
- ".github/workflows/unit-tests.yaml" # This workflow
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
defaults:
run:
shell: bash
jobs:
start-ec2-runner:
uses: ./.github/workflows/reusable-start-ec2-runner.yaml
with:
aws_region: ${{vars.AWS_REGION}}
aws_ami: ${{vars.AWS_EC2_AMI}}
aws_ec2_runner_variant: ${{vars.UNITTEST_EC2_INSTANCE_TYPE}}
secrets: inherit
run-unit-tests:
needs:
- start-ec2-runner
runs-on: ${{needs.start-ec2-runner.outputs.runner_label}}
# It is important that this job has no write permissions and has
# no access to any secrets. This part is where we are running
# untrusted code from PRs.
permissions: {}
steps:
- name: "Harden runner"
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.1
with:
egress-policy: audit
- name: "Install packages"
run: |
cat /etc/os-release
sudo dnf install -y gcc gcc-c++ make git python3.11 python3.11-devel
- name: "Checkout code"
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
# installs in $GITHUB_WORKSPACE/venv.
# only has to install Tox because Tox will do the other virtual environment management.
- name: "Setup Python virtual environment"
run: |
python3.11 -m venv --upgrade-deps venv
. venv/bin/activate
pip install tox
- name: "Show disk utilization BEFORE tests"
run: |
df -h
- name: "Run unit tests with Tox and Pytest"
run: |
source venv/bin/activate
tox -e py3-unit
- name: "Show disk utilization AFTER tests"
run: |
df -h
stop-ec2-runner:
needs:
- start-ec2-runner
- run-unit-tests
if: ${{ always() }}
uses: ./.github/workflows/reusable-stop-ec2-runner.yaml
with:
aws_region: ${{vars.AWS_REGION}}
aws_ec2_runner_label: ${{needs.start-ec2-runner.outputs.runner_label}}
aws_ec2_runner_instance_id: ${{needs.start-ec2-runner.outputs.runner_instance_id}}
secrets: inherit