Skip to content

Commit 05598a1

Browse files
ci: make "lint" and "test" reusable local actions (#1342)
Follow up #1341 This PR extract "lint" and "test" jobs into reusable local actions, so other workflows can reuse the same logic. So far, only current "test" and "lint" jobs are extrated as standanlone jobs, more granular reusability might be needed in the future. Jira: https://issues.redhat.com/browse/AAP-46938 Signed-off-by: Alex <[email protected]>
1 parent 9346d36 commit 05598a1

File tree

3 files changed

+115
-81
lines changed

3 files changed

+115
-81
lines changed

.github/actions/lint/action.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: lint
2+
3+
runs:
4+
using: composite
5+
steps:
6+
- name: Install poetry
7+
shell: bash
8+
run: pipx install poetry
9+
10+
- name: Set up Python
11+
uses: actions/setup-python@v5
12+
with:
13+
python-version: '3.11'
14+
cache: 'poetry'
15+
16+
- name: Install dependencies
17+
shell: bash
18+
run: poetry install --no-root --only=lint
19+
20+
- name: Lint with black
21+
shell: bash
22+
run: poetry run black --check .
23+
24+
- name: Lint with isort
25+
shell: bash
26+
run: poetry run isort --check .
27+
28+
- name: Lint with ruff
29+
shell: bash
30+
run: poetry run ruff check .
31+
32+
- name: Lint with flake8
33+
shell: bash
34+
run: poetry run flake8 . --count --show-source --statistics

.github/actions/test/action.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: test
2+
inputs:
3+
python-version:
4+
description: python version to use
5+
required: true
6+
runs:
7+
using: composite
8+
steps:
9+
- name: Install poetry
10+
shell: bash
11+
run: pipx install poetry
12+
13+
- name: Set up Python
14+
uses: actions/setup-python@v5
15+
with:
16+
python-version: ${{ inputs.python-version }}
17+
cache: 'poetry'
18+
19+
- name: Install package
20+
shell: bash
21+
run: poetry install -E all --only main,test
22+
23+
- name: Check migrations are up to date
24+
shell: bash
25+
run: poetry run /usr/bin/env aap-eda-manage makemigrations --dry-run --check
26+
27+
- name: Run default tests
28+
shell: bash
29+
run: |
30+
poetry run python -m pytest -vv \
31+
--cov=./ \
32+
--cov-report=xml \
33+
--junit-xml=eda-server-default.xml
34+
echo "GIT_SHA=$(git rev-parse "$GITHUB_SHA")" >> "$GITHUB_ENV"
35+
36+
- name: Run multithreaded tests
37+
shell: bash
38+
run: |
39+
poetry run python -m pytest -vv \
40+
--cov=./ \
41+
--cov-append \
42+
--junit-xml=eda-server-multithreaded.xml \
43+
-m "multithreaded"
44+
45+
- name: Merge test results
46+
shell: bash
47+
run: |
48+
pip install junitparser
49+
junitparser merge eda-server-default.xml eda-server-multithreaded.xml eda-server-test-results.xml
50+
51+
- name: Upload coverage to Codecov
52+
uses: codecov/codecov-action@v5
53+
with:
54+
env_vars: OS,PYTHON
55+
fail_ci_if_error: false
56+
files: ./coverage.xml
57+
flags: "unit-int-tests-${{ inputs.python-version }}"
58+
name: codecov-umbrella
59+
verbose: true
60+
61+
- name: Upload jUnit test results (APDE CI)
62+
if: github.repository == 'ansible/eda-server' && github.ref == 'refs/heads/main'
63+
shell: bash
64+
run: >-
65+
poetry run http --check-status --ignore-stdin
66+
--auth "${{ env.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_USER }}:${{ env.PDE_ORG_RESULTS_UPLOAD_PASSWORD }}"
67+
-f POST "${{ env.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_URL }}/api/results/upload/"
68+
69+
component_name=eda
70+
git_commit_sha=${{ env.GIT_SHA }}
71+
git_repository_url="https://github.com/${{ github.repository }}"

.github/workflows/ci.yaml

Lines changed: 10 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,8 @@ jobs:
2121
- name: Checkout
2222
uses: actions/checkout@v3
2323

24-
- name: Install poetry
25-
run: pipx install poetry
26-
27-
- name: Set up Python
28-
uses: actions/setup-python@v5
29-
with:
30-
python-version: '3.11'
31-
cache: 'poetry'
32-
33-
- name: Install dependencies
34-
run: poetry install --no-root --only=lint
35-
36-
- name: Lint with black
37-
run: poetry run black --check .
38-
39-
- name: Lint with isort
40-
run: poetry run isort --check .
41-
42-
- name: Lint with ruff
43-
run: poetry run ruff check .
44-
45-
- name: Lint with flake8
46-
run: poetry run flake8 . --count --show-source --statistics
47-
24+
- name: lint
25+
uses: ./.github/actions/lint
4826

4927
test:
5028
runs-on: ubuntu-latest
@@ -56,13 +34,16 @@ jobs:
5634
env:
5735
EDA_SECRET_KEY: 'test'
5836
EDA_DB_PASSWORD: 'secret'
37+
PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_USER: ${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_USER }}
38+
PDE_ORG_RESULTS_UPLOAD_PASSWORD: ${{ secrets.PDE_ORG_RESULTS_UPLOAD_PASSWORD }}
39+
PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_URL: ${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_URL }}
5940
services:
6041
postgres:
6142
image: 'quay.io/sclorg/postgresql-15-c9s:latest'
6243
env:
6344
POSTGRESQL_USER: eda
64-
POSTGRESQL_PASSWORD: secret
65-
POSTGRESQL_ADMIN_PASSWORD: secret
45+
POSTGRESQL_PASSWORD: ${{ env.EDA_DB_PASSWORD }}
46+
POSTGRESQL_ADMIN_PASSWORD: ${{ env.EDA_DB_PASSWORD }}
6647
POSTGRESQL_DATABASE: eda
6748
options: >-
6849
--health-cmd pg_isready
@@ -84,59 +65,7 @@ jobs:
8465
- name: Checkout
8566
uses: actions/checkout@v3
8667

87-
- name: Install poetry
88-
run: pipx install poetry
89-
90-
- name: Set up Python
91-
uses: actions/setup-python@v5
68+
- name: test
69+
uses: ./.github/actions/test
9270
with:
93-
python-version: ${{ matrix.python-version }}
94-
cache: 'poetry'
95-
96-
- name: Install package
97-
run: poetry install -E all --only main,test
98-
99-
- name: Check migrations are up to date
100-
run: poetry run /usr/bin/env aap-eda-manage makemigrations --dry-run --check
101-
102-
- name: Run default tests
103-
run: |
104-
poetry run python -m pytest -vv \
105-
--cov=./ \
106-
--cov-report=xml \
107-
--junit-xml=eda-server-default.xml
108-
echo "GIT_SHA=$(git rev-parse "$GITHUB_SHA")" >> "$GITHUB_ENV"
109-
110-
- name: Run multithreaded tests
111-
run: |
112-
poetry run python -m pytest -vv \
113-
--cov=./ \
114-
--cov-append \
115-
--junit-xml=eda-server-multithreaded.xml \
116-
-m "multithreaded"
117-
118-
- name: Merge test results
119-
run: |
120-
pip install junitparser
121-
junitparser merge eda-server-default.xml eda-server-multithreaded.xml eda-server-test-results.xml
122-
123-
- name: Upload coverage to Codecov
124-
uses: codecov/codecov-action@v5
125-
with:
126-
env_vars: OS,PYTHON
127-
fail_ci_if_error: false
128-
files: ./coverage.xml
129-
flags: "unit-int-tests-${{ matrix.python-version }}"
130-
name: codecov-umbrella
131-
verbose: true
132-
133-
- name: Upload jUnit test results (APDE CI)
134-
if: github.repository == 'ansible/eda-server' && github.ref == 'refs/heads/main'
135-
run: >-
136-
poetry run http --check-status --ignore-stdin
137-
--auth "${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_USER }}:${{ secrets.PDE_ORG_RESULTS_UPLOAD_PASSWORD }}"
138-
-f POST "${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_URL }}/api/results/upload/"
139-
140-
component_name=eda
141-
git_commit_sha=${{ env.GIT_SHA }}
142-
git_repository_url="https://github.com/${{ github.repository }}"
71+
python-version: ${{ matrix.python-version }}

0 commit comments

Comments
 (0)