-
Notifications
You must be signed in to change notification settings - Fork 1
185 lines (156 loc) · 6.71 KB
/
Copy pathlinting_and_testing.yml
File metadata and controls
185 lines (156 loc) · 6.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name: tests
on:
# workflow_dispatch
push:
branches: [ master ]
paths-ignore:
- '.gitignore'
- '.readthedocs.yaml'
- 'LICENSE'
- 'setup.py'
- 'README.md'
- 'CITATION.cff'
- 'references.jsonld'
- '**/docs/**'
- '**/json_schemas/**'
- '.github/workflows/pr-tests.yml'
- '**/test/data/**'
- '**/test/references/**'
- '.github/workflows/test_containers.yml'
jobs:
# Name of the Job
lint_and_test:
strategy:
matrix:
os: [mmbswarm]
python-version: ["3.10", "3.11", "3.12"]
runs-on: ${{ matrix.os }}
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 0
- run: echo "Repository -> ${{ github.repository }}"
- run: echo "Branch -> ${{ github.ref }}"
- run: echo "Trigger event -> ${{ github.event_name }}"
- run: echo "Runner OS -> ${{ runner.os }}"
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- name: Detect changed files and set test paths
id: changes
shell: bash
run: |
BEFORE="${{ github.event.before }}"
AFTER="${{ github.sha }}"
if [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then
echo "New branch detected – running full test suite"
echo "test_paths=" >> "$GITHUB_OUTPUT"
exit 0
fi
CHANGED_FILES=$(git diff --name-only "$BEFORE" "$AFTER" 2>/dev/null || echo "")
echo "Changed files:"
echo "${CHANGED_FILES:-(none)}"
TESTS=""
while IFS= read -r FILE; do
[ -z "$FILE" ] && continue
if [[ "$FILE" =~ ^${{ github.event.repository.name }}/test/unitests/test_[^/]+/test_[^/]+\.py$ ]]; then
# Direct test file change – run only this file (skip container tests)
if [[ "$FILE" != *_container.py ]]; then
[ -f "$FILE" ] && TESTS+=$'\n'"$FILE"
fi
elif [[ "$FILE" =~ ^${{ github.event.repository.name }}/([a-z][^/]+)/([^/]+)\.py$ ]]; then
TOOL="${BASH_REMATCH[1]}"
BASE="${BASH_REMATCH[2]}"
if [[ "$BASE" == "__init__" || "$BASE" == "common" ]]; then
# Run all tests for this tool
TEST_DIR="${{ github.event.repository.name }}/test/unitests/test_${TOOL}"
[ -d "$TEST_DIR" ] && TESTS+=$'\n'"$TEST_DIR"
else
# Run the matching test file for this source file
TEST_FILE="${{ github.event.repository.name }}/test/unitests/test_${TOOL}/test_${BASE}.py"
if [ -f "$TEST_FILE" ]; then
TESTS+=$'\n'"$TEST_FILE"
else
TEST_DIR="${{ github.event.repository.name }}/test/unitests/test_${TOOL}"
[ -d "$TEST_DIR" ] && TESTS+=$'\n'"$TEST_DIR"
fi
fi
fi
done <<< "$CHANGED_FILES"
TESTS=$(echo "$TESTS" | grep -v '^$' | sort -u | tr '\n' ' ' | xargs || echo "")
echo "Test paths: ${TESTS:-(none detected – will run full suite)}"
echo "test_paths=$TESTS" >> "$GITHUB_OUTPUT"
- name: Remove all micromamba installations
run: |
rm -rf $HOME/.bash_profile $HOME/.conda $HOME/micromamba $HOME/micromamba-bin 2>/dev/null
touch $HOME/.bash_profile
- name: setup-micromamba
uses: mamba-org/setup-micromamba@v2.0.0
with:
generate-run-shell: true
micromamba-version: '2.0.2-2'
post-cleanup: 'all'
init-shell: bash
environment-file: .github/env.yaml
create-args: >-
python=${{ matrix.python-version }}
pytest
pytest-cov
pytest-html
flake8
pip
- name: Install genbadge from pip
shell: bash -l {0}
run: pip install genbadge[all]
- name: List installed package versions
shell: bash -l {0}
run: micromamba list
- name: Lint with flake8
shell: bash -l {0}
run: |
# F Codes: https://flake8.pycqa.org/en/latest/user/error-codes.html
# E Code: https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
# Workflow fails: Stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# Create directory for flake8 reports
mkdir -p ./reports/flake8
# Exit-zero treats all errors as warnings, workflow will not fail:
flake8 . --exclude=docs --ignore=C901,E226 --count --exit-zero --max-complexity=10 --max-line-length=9999 --statistics --format=html --htmldir=./reports/flake8/ --tee --output-file=./reports/flake8/flake8stats.txt
- name: Generate Flake8 badge
shell: bash -l {0}
run: |
genbadge flake8 --name "Flake8" --input-file ./reports/flake8/flake8stats.txt --output-file ./reports/flake8/flake8badge.svg
- name: Run tests
shell: bash -l {0}
run: |
# Ignoring docker and singularity tests
export PYTHONPATH=.:$PYTHONPATH
# copying cp2k_aux data
mkdir -p $CONDA_PREFIX/cp2k_aux
cp -r biobb_cp2k/cp2k/cp2k_in $CONDA_PREFIX/cp2k_aux
cp -r biobb_cp2k/cp2k/cp2k_data $CONDA_PREFIX/cp2k_aux
# Create directory for tests reports
mkdir -p ./reports/junit
# Run only tests for modified tools, fall back to full suite when nothing specific detected
TEST_PATHS="${{ steps.changes.outputs.test_paths }}"
if [ -z "$TEST_PATHS" ]; then
TEST_PATHS="${{ github.event.repository.name }}/test/unitests/"
fi
pytest $TEST_PATHS --cov=${{ github.event.repository.name }}/ --cov-report=xml --ignore-glob=*container.py --junit-xml=./reports/junit/junit.xml --html=./reports/junit/report.html
- name: Generate Tests badge
shell: bash -l {0}
run: |
genbadge tests --name "Tests" --input-file ./reports/junit/junit.xml --output-file ./reports/junit/testsbadge.svg
- name: Generate Coverage badge
shell: bash -l {0}
run: |
# Create directory for flake8 reports
mkdir -p ./reports/coverage
coverage xml -o ./reports/coverage/coverage.xml
coverage html -d ./reports/coverage/
genbadge coverage --name "Coverage" --input-file ./reports/coverage/coverage.xml --output-file ./reports/coverage/coveragebadge.svg
- name: Publish coverage report to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: ./reports