-
Notifications
You must be signed in to change notification settings - Fork 1
83 lines (77 loc) · 2.81 KB
/
python-app.yml
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
# This workflow installs Python dependencies, runs tests, and performs linting using flake8.
# It is triggered on push and pull request events for specific files.
name: Python application
env:
# Paths to source files for validation
SRC_PATH: validation/validate_all_configs.py validation/validate_config.py
# Paths to test files for validation
TESTS_PATH: tests/test_validate_all_configs.py tests/test_validate_config.py
on:
# Trigger workflow on push events for specific files
push:
branches: [ "*" ]
paths:
- "validation/validate_all_configs.py"
- "validation/validate_config.py"
- "tests/test_validate_all_configs.py"
- "tests/test_validate_config.py"
# Trigger workflow on pull request events for specific files
pull_request:
branches: [ "*" ]
paths:
- "validation/validate_all_configs.py"
- "validation/validate_config.py"
- "tests/test_validate_all_configs.py"
- "tests/test_validate_config.py"
# Allows manual triggering of the workflow
workflow_dispatch:
# Grants read access to repository contents
permissions:
contents: read
jobs:
# Job to determine if source tests should run
determine-tests:
runs-on: ubuntu-latest
outputs:
# Determines if source tests should run
run-src-tests: ${{ steps.set-output.outputs.run-src-tests }}
steps:
- # Checks out the repository
uses: actions/checkout@v4
- name: Determine tests to run
id: set-output
run: |
if git diff --name-only $(git merge-base HEAD origin/main) | grep -q '^${{ env.SRC_PATH }}/'; then
echo "::set-output name=run-src-tests::true"
else
echo "::set-output name=run-src-tests::false"
fi
# Job to build and test the application
build:
runs-on: ubuntu-latest
needs: determine-tests
steps:
- # Checks out the repository
uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
# Specifies Python version
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# Run flake8 linting, excluding the tutorials directory
flake8 --exclude=tutorials/ . --count --select=E9,F63,F7,F82 --show-source --statistics
# Treat all errors as warnings and set line length limit
flake8 --exclude=tutorials/ . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
if [ "${{ needs.determine-tests.outputs.run-src-tests }}" == "true" ]; then
# Runs pytest on specified test paths
pytest ${{ env.TESTS_PATH }}/
fi