-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (97 loc) · 3.7 KB
/
tests.yml
File metadata and controls
113 lines (97 loc) · 3.7 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
name: Tests
on:
push:
branches: [ main ]
pull_request:
permissions:
contents: write
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
steps:
# -------------------- Checkout --------------------
- name: Checkout code
uses: actions/checkout@v4
# -------------------- Micromamba setup --------------------
- name: Set up micromamba
uses: mamba-org/setup-micromamba@v1
with:
environment-file: env_github_tests.yml
environment-name: test-env
cache-environment: true
init-shell: bash
# -------------------- Test dependencies --------------------
- name: Install test dependencies
run: |
micromamba install pytest pytest-cov -y
# -------------------- Install flagx --------------------
- name: Install FLAG-X package
run: |
pip install -e .
# -------------------- Space cleanup --------------------
- name: Clean caches
run: |
micromamba clean --all --yes
pip cache purge || true
# -------------------- Ensure badges folder exists --------------------
- name: Ensure badges directory exists
run: mkdir -p badges
# -------------------- Run Tests --------------------
- name: Run tests with coverage
id: tests
run: pytest --cov=. --cov-report=xml --cov-report=term
continue-on-error: true
# -------------------- Determine test result --------------------
- name: Determine test result
id: test_result
run: |
if [ "${{ steps.tests.outcome }}" = "success" ]; then
echo "status=passing" >> $GITHUB_OUTPUT
echo "color=green" >> $GITHUB_OUTPUT
else
echo "status=failing" >> $GITHUB_OUTPUT
echo "color=red" >> $GITHUB_OUTPUT
fi
# -------------------- Extract coverage --------------------
- name: Extract coverage percentage
id: coverage
run: |
value=$(xmllint --xpath "string(/coverage/@line-rate)" coverage.xml)
percent=$(printf "%.0f" "$(echo "$value * 100" | bc)")
echo "percent=$percent" >> $GITHUB_OUTPUT
# -------------------- Coverage color --------------------
- name: Determine coverage color
id: coverage_color
run: |
p=${{ steps.coverage.outputs.percent }}
if [ "$p" -ge 80 ]; then c=green
elif [ "$p" -ge 50 ]; then c=yellow
else c=red
fi
echo "color=$c" >> $GITHUB_OUTPUT
# -------------------- Generate test badge --------------------
- name: Generate test badge
uses: emibcn/badge-action@v1.2.1
with:
label: "tests"
status: "${{ steps.test_result.outputs.status }}"
color: "${{ steps.test_result.outputs.color }}"
path: "badges/test-status.svg"
# -------------------- Generate coverage badge --------------------
- name: Generate coverage badge
uses: emibcn/badge-action@v1.2.1
with:
label: "coverage"
status: "${{ steps.coverage.outputs.percent }}%"
color: "${{ steps.coverage_color.outputs.color }}"
path: "badges/coverage.svg"
# -------------------- Commit badges (always runs) --------------------
- name: Commit badges
if: always() && github.actor != 'github-actions[bot]'
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update test and coverage badges"
file_pattern: "badges/*.svg"