Skip to content

Tests

Tests #232

Workflow file for this run

name: Tests
on:
workflow_call:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened]
branches: [main]
paths-ignore:
- "**.md"
- "**.rst"
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
lint:
name: Lint
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.10']
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
# pin tox to the current major version to avoid
# workflows breaking all at once when a new major version is released.
python -m pip install 'tox<5'
- name: Run linters
run: tox -e lint
unit:
name: Unit
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.10']
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install 'tox<5'
- name: Run unit tests
run: tox -e unit
- name: Determine system architecture
run: echo "SYSTEM_ARCH=$(uname -m)" >> $GITHUB_ENV
- name: Upload Unit Test Coverage File
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
if-no-files-found: ignore
name: coverage-unit-${{ matrix.python-version }}-${{ env.SYSTEM_ARCH }}
path: .coverage-unit
func:
name: Functional tests
needs:
- lint
- unit
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.10"]
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install 'tox<5'
- name: Run functional tests
run: tox -e func
- name: Generate Safe Test Command Identifier by removing spaces and special characters
run: |
TEST_CMD_ID=$(echo "${{ matrix.python-version }}" | sed 's/[^a-zA-Z0-9]/_/g')
echo "TEST_CMD_ID=$TEST_CMD_ID" >> $GITHUB_ENV
- name: Upload Functional Test Coverage Artifact
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
if-no-files-found: ignore
name: coverage-functional-${{ env.TEST_CMD_ID }}-${{ env.SYSTEM_ARCH }}
path: .coverage-func
tics-analysis:
runs-on: [self-hosted, linux, amd64, tiobe, jammy]
if: >
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main')
needs: func
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install coverage tools
run: |
pip install coverage[toml]
# Install everything from all requirements.txt files otherwise TICS errors.
- name: Install all charm dependencies
run: |
for f in $(find -name '*requirements.txt'); do
echo "${f}"
pip3 install --requirement "${f}"
done
# For reactive charms
for f in $(find -name 'wheelhouse.txt'); do
echo "${f}"
pip3 install --requirement "${f}"
done
- name: Determine system architecture
run: echo "SYSTEM_ARCH=$(uname -m)" >> $GITHUB_ENV
- name: Download Coverage Files
uses: actions/download-artifact@v4
with:
pattern: coverage-*-${{ env.SYSTEM_ARCH }}
merge-multiple: true
path: artifacts/
continue-on-error: true
- name: Merge coverage reports
run: |
# Create the path that is expected to have a coverage.xml for tics
mkdir -p tests/report/
coverage_files=(./artifacts/.coverage*)
if [ -e "${coverage_files[0]}" ]; then
echo "Merging coverage files: ${coverage_files[*]}"
coverage combine "${coverage_files[@]}"
# Check if there is actual data to report before generating XML with merged reports
if coverage report > /dev/null 2>&1; then
coverage report --show-missing
coverage xml -o tests/report/coverage.xml
fi
fi
- name: Run TICS analysis
uses: tiobe/tics-github-action@v3
with:
mode: qserver
project: prometheus-hardware-exporter
viewerUrl: https://canonical.tiobe.com/tiobeweb/TICS/api/cfg?name=default
branchdir: ${{ github.workspace }}
ticsAuthToken: ${{ secrets.TICSAUTHTOKEN }}
installTics: true