Spaces:
No application file
No application file
name: Run Unit Tests | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
workflow_dispatch: | |
jobs: | |
run-tests: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.9' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Run tests | |
run: pytest tests/ | |
- name: Notify Discord | |
if: always() | |
env: | |
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} | |
run: | | |
if [ "${{ job.status }}" == "success" ]; then | |
COLOR="3066993" | |
TITLE="β Unit Tests Passed" | |
DESCRIPTION="All unit tests have passed successfully." | |
EMOJI="π" | |
else | |
COLOR="15158332" | |
TITLE="β Unit Tests Failed" | |
DESCRIPTION="Some unit tests have failed. Please check the logs for more details." | |
EMOJI="π¨" | |
fi | |
PAYLOAD=$(cat <<EOF | |
{ | |
"embeds": [{ | |
"title": "$TITLE", | |
"description": "$DESCRIPTION", | |
"color": $COLOR, | |
"fields": [ | |
{ | |
"name": "Repository", | |
"value": "${{ github.repository }}", | |
"inline": true | |
}, | |
{ | |
"name": "Branch", | |
"value": "${{ github.ref_name }}", | |
"inline": true | |
}, | |
{ | |
"name": "Triggered by", | |
"value": "${{ github.event_name }}", | |
"inline": true | |
}, | |
{ | |
"name": "Run by", | |
"value": "${{ github.actor }}", | |
"inline": true | |
} | |
], | |
"footer": { | |
"text": "$EMOJI Test run completed at $(date -u "+%Y-%m-%d %H:%M:%S UTC")" | |
} | |
}], | |
"username": "GitHub Actions", | |
"avatar_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" | |
} | |
EOF | |
) | |
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -H "Content-Type: application/json" -d "$PAYLOAD" $DISCORD_WEBHOOK) | |
if [ $RESPONSE -ne 204 ]; then | |
echo "Failed to send Discord notification. HTTP response code: $RESPONSE" | |
exit 1 | |
else | |
echo "Discord notification sent successfully!" | |
fi | |