|
| 1 | +############################################################################### |
| 2 | +# Workflow: Python Unit Tests |
| 3 | +# |
| 4 | +# Purpose: |
| 5 | +# Runs Python unit tests automatically on pull requests and pushes to main/next. |
| 6 | +# |
| 7 | +# Triggers: |
| 8 | +# - On push to main or next branches (Python files only) |
| 9 | +# - On pull requests affecting Python files |
| 10 | +# - Manual dispatch |
| 11 | +# |
| 12 | +# Key Steps: |
| 13 | +# 1. Checkout repository code |
| 14 | +# 2. Set up Python environment using a custom action |
| 15 | +# 3. Run unit tests and report results |
| 16 | +# |
| 17 | +# Notes: |
| 18 | +# - secrets are set in https://github.com/smarter-sh/smarter/settings/secrets/actions |
| 19 | +# - Integrates with Codecov for coverage reporting |
| 20 | +############################################################################### |
1 | 21 | name: Python Unit Tests |
2 | 22 |
|
3 | 23 | on: |
4 | | - workflow_dispatch: |
5 | | - pull_request: |
6 | | - paths: |
7 | | - - "**.py" |
| 24 | + workflow_dispatch: # Allows the workflow to be manually triggered from the GitHub Actions tab |
| 25 | + pull_request: # |
| 26 | + paths: # Trigger workflow on pull requests, but |
| 27 | + - "**.py" # only if Python files are changed |
8 | 28 | push: |
9 | | - branches: |
10 | | - - main |
11 | | - - next |
12 | | - paths: |
13 | | - - "**.py" |
| 29 | + branches: # |
| 30 | + - main # |
| 31 | + - next # Trigger workflow on pushes to main and next |
| 32 | + paths: # branches, but only if Python files are changed |
| 33 | + - "**.py" # |
14 | 34 |
|
15 | 35 | env: |
16 | 36 | python-version: "3.13" |
17 | 37 |
|
18 | 38 | jobs: |
| 39 | + # Job #1: Run Python unit tests |
| 40 | + # |
| 41 | + # This job will run on an Ubuntu runner and execute the Python |
| 42 | + # tests by using a custom action located in ./.github/actions/tests/python. |
19 | 43 | python-unit-tests: |
20 | | - runs-on: ubuntu-latest |
| 44 | + runs-on: ubuntu-latest # the runner (remote machine) will use Ubuntu OS |
21 | 45 | steps: |
22 | 46 | - name: Checkout code |
23 | 47 | id: checkout |
|
37 | 61 | mysql-database: "${{ secrets.MYSQL_DATABASE }}" |
38 | 62 | mysql-charset: "${{ secrets.MYSQL_CHARSET }}" |
39 | 63 | codecov-token: "${{ secrets.CODECOV_TOKEN }}" |
| 64 | + |
| 65 | + # Job #2: Notifications (Mini-capstone assignment) |
| 66 | + # This job will run after the Python unit tests and |
| 67 | + # is scaffolded to facilitate sending notifications based |
| 68 | + # on the test results. |
| 69 | + notifications: |
| 70 | + needs: python-unit-tests |
| 71 | + runs-on: ubuntu-latest |
| 72 | + steps: |
| 73 | + - name: Notify on test results |
| 74 | + run: | |
| 75 | + if [ "${{ needs.python-unit-tests.result }}" == "success" ]; then |
| 76 | + echo "success notifications go here" |
| 77 | + else |
| 78 | + echo "failure notifications go here" |
| 79 | + fi |
0 commit comments