Skip to content

ci: make "lint" and "test" reusable local actions #1342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/actions/lint/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: lint

runs:
using: composite
steps:
- name: Install poetry
shell: bash
run: pipx install poetry

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'poetry'

- name: Install dependencies
shell: bash
run: poetry install --no-root --only=lint

- name: Lint with black
shell: bash
run: poetry run black --check .

- name: Lint with isort
shell: bash
run: poetry run isort --check .

- name: Lint with ruff
shell: bash
run: poetry run ruff check .

- name: Lint with flake8
shell: bash
run: poetry run flake8 . --count --show-source --statistics
71 changes: 71 additions & 0 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: test
inputs:
python-version:
description: python version to use
required: true
runs:
using: composite
steps:
- name: Install poetry
shell: bash
run: pipx install poetry

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
cache: 'poetry'

- name: Install package
shell: bash
run: poetry install -E all --only main,test

- name: Check migrations are up to date
shell: bash
run: poetry run /usr/bin/env aap-eda-manage makemigrations --dry-run --check

- name: Run default tests
shell: bash
run: |
poetry run python -m pytest -vv \
--cov=./ \
--cov-report=xml \
--junit-xml=eda-server-default.xml
echo "GIT_SHA=$(git rev-parse "$GITHUB_SHA")" >> "$GITHUB_ENV"

- name: Run multithreaded tests
shell: bash
run: |
poetry run python -m pytest -vv \
--cov=./ \
--cov-append \
--junit-xml=eda-server-multithreaded.xml \
-m "multithreaded"

- name: Merge test results
shell: bash
run: |
pip install junitparser
junitparser merge eda-server-default.xml eda-server-multithreaded.xml eda-server-test-results.xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
env_vars: OS,PYTHON
fail_ci_if_error: false
files: ./coverage.xml
flags: "unit-int-tests-${{ inputs.python-version }}"
name: codecov-umbrella
verbose: true

- name: Upload jUnit test results (APDE CI)
if: github.repository == 'ansible/eda-server' && github.ref == 'refs/heads/main'
shell: bash
run: >-
poetry run http --check-status --ignore-stdin
--auth "${{ env.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_USER }}:${{ env.PDE_ORG_RESULTS_UPLOAD_PASSWORD }}"
-f POST "${{ env.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_URL }}/api/results/upload/"
xunit_xml@eda-server-test-results.xml
component_name=eda
git_commit_sha=${{ env.GIT_SHA }}
git_repository_url="https://github.com/${{ github.repository }}"
91 changes: 10 additions & 81 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'poetry'

- name: Install dependencies
run: poetry install --no-root --only=lint

- name: Lint with black
run: poetry run black --check .

- name: Lint with isort
run: poetry run isort --check .

- name: Lint with ruff
run: poetry run ruff check .

- name: Lint with flake8
run: poetry run flake8 . --count --show-source --statistics

- name: lint
uses: ./.github/actions/lint

test:
runs-on: ubuntu-latest
Expand All @@ -56,13 +34,16 @@ jobs:
env:
EDA_SECRET_KEY: 'test'
EDA_DB_PASSWORD: 'secret'
PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_USER: ${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_USER }}
PDE_ORG_RESULTS_UPLOAD_PASSWORD: ${{ secrets.PDE_ORG_RESULTS_UPLOAD_PASSWORD }}
PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_URL: ${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_URL }}
services:
postgres:
image: 'quay.io/sclorg/postgresql-15-c9s:latest'
env:
POSTGRESQL_USER: eda
POSTGRESQL_PASSWORD: secret
POSTGRESQL_ADMIN_PASSWORD: secret
POSTGRESQL_PASSWORD: ${{ env.EDA_DB_PASSWORD }}
POSTGRESQL_ADMIN_PASSWORD: ${{ env.EDA_DB_PASSWORD }}
POSTGRESQL_DATABASE: eda
options: >-
--health-cmd pg_isready
Expand All @@ -84,59 +65,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry

- name: Set up Python
uses: actions/setup-python@v5
- name: test
uses: ./.github/actions/test
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'

- name: Install package
run: poetry install -E all --only main,test

- name: Check migrations are up to date
run: poetry run /usr/bin/env aap-eda-manage makemigrations --dry-run --check

- name: Run default tests
run: |
poetry run python -m pytest -vv \
--cov=./ \
--cov-report=xml \
--junit-xml=eda-server-default.xml
echo "GIT_SHA=$(git rev-parse "$GITHUB_SHA")" >> "$GITHUB_ENV"

- name: Run multithreaded tests
run: |
poetry run python -m pytest -vv \
--cov=./ \
--cov-append \
--junit-xml=eda-server-multithreaded.xml \
-m "multithreaded"

- name: Merge test results
run: |
pip install junitparser
junitparser merge eda-server-default.xml eda-server-multithreaded.xml eda-server-test-results.xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
env_vars: OS,PYTHON
fail_ci_if_error: false
files: ./coverage.xml
flags: "unit-int-tests-${{ matrix.python-version }}"
name: codecov-umbrella
verbose: true

- name: Upload jUnit test results (APDE CI)
if: github.repository == 'ansible/eda-server' && github.ref == 'refs/heads/main'
run: >-
poetry run http --check-status --ignore-stdin
--auth "${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_USER }}:${{ secrets.PDE_ORG_RESULTS_UPLOAD_PASSWORD }}"
-f POST "${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_URL }}/api/results/upload/"
xunit_xml@eda-server-test-results.xml
component_name=eda
git_commit_sha=${{ env.GIT_SHA }}
git_repository_url="https://github.com/${{ github.repository }}"
python-version: ${{ matrix.python-version }}