Repository navigation
90 lines (84 loc) · 3.25 KB
/
Copy pathtestsPython.yml
File metadata and controls
90 lines (84 loc) · 3.25 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
###############################################################################
# Workflow: Python Unit Tests
#
# Purpose:
# Runs Python unit tests automatically on pull requests and pushes to main/next.
#
# Triggers:
# - On push to main or next branches (Python files only)
# - On pull requests affecting Python files
# - Manual dispatch
#
# Key Steps:
# 1. Checkout repository code
# 2. Set up Python environment using a custom action
# 3. Run unit tests and report results
#
# Notes:
# - secrets are set in https://github.com/smarter-sh/smarter/settings/secrets/actions
# - Integrates with Codecov for coverage reporting
###############################################################################
name: Python Unit Tests
on:
workflow_dispatch: # Allows the workflow to be manually triggered from the GitHub Actions tab
pull_request: #
paths: # Trigger workflow on pull requests, but
- "**.py" # only if Python files are changed
push:
branches: #
- main #
- next # Trigger workflow on pushes to main and next
paths: # branches, but only if Python files are changed
- "**.py" #
env:
python-version: "3.13"
jobs:
# Job #1: Run Python unit tests
#
# This job will run on an Ubuntu runner and execute the Python
# tests by using a custom action located in ./.github/actions/tests/python.
python-unit-tests:
runs-on: ubuntu-latest # the runner (remote machine) will use Ubuntu OS
steps:
- name: Checkout code
id: checkout
uses: actions/checkout@v6
- name: Run Python tests
uses: ./.github/actions/tests/python
with:
environment: "local"
python-version: "${{ env.python-version}}"
openai-api-organization: "${{ secrets.OPENAI_API_ORGANIZATION }}"
openai-api-key: "${{ secrets.OPENAI_API_KEY }}"
mysql-host: "${{ secrets.MYSQL_HOST }}"
mysql-port: "${{ secrets.MYSQL_PORT }}"
mysql-user: "${{ secrets.MYSQL_USER }}"
mysql-password: "${{ secrets.MYSQL_PASSWORD }}"
mysql-database: "${{ secrets.MYSQL_DATABASE }}"
mysql-charset: "${{ secrets.MYSQL_CHARSET }}"
codecov-token: "${{ secrets.CODECOV_TOKEN }}"
# Job #2: Notifications (Mini-capstone assignment)
# This job will run after the Python unit tests and
# is scaffolded to facilitate sending notifications based
# on the test results.
notifications:
needs: python-unit-tests
runs-on: ubuntu-latest
# This line ensures the notification job runs even if the tests fail
if: always()
steps:
- name: Send mail
if: needs.python-unit-tests.result == 'failure'
uses: dawidd6/action-send-mail@v3
with:
# SMTP server details (Example for Gmail)
server_address: smtp.gmail.com
server_port: 465
username: ${{ secrets.MAIL_USERNAME }}
password: ${{ secrets.MAIL_PASSWORD }}
subject: "CI Build Failed: ${{ github.repository }}"
to: #your email here
from: GitHub Actions Workflow
body: |
The Python Unit Tests failed for the repository ${{ github.repository }}.
Check the logs here: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}