-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (74 loc) · 3.13 KB
/
tests.yml
File metadata and controls
92 lines (74 loc) · 3.13 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
name: Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: write
jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: dom, mbstring
coverage: pcov
- name: Install dependencies
run: composer install --prefer-dist --no-progress
- name: Run PHPStan
run: vendor/bin/phpstan analyse
- name: Run tests with coverage
run: |
# Run tests and capture output to parse coverage percentage
vendor/bin/pest --coverage --coverage-clover=coverage.xml --coverage-html=coverage-html --min=80 | tee coverage-output.txt
# Extract "Total: XX.X %" from the output
COVERAGE=$(grep -oP 'Total:\s+\K[0-9]+(\.[0-9]+)?' coverage-output.txt)
echo "Coverage: $COVERAGE%"
echo "COVERAGE=$COVERAGE" >> $GITHUB_ENV
- name: Count lines of code
run: |
LOC_PHP_SRC=$(find src -name "*.php" | xargs wc -l | tail -1 | awk '{print $1}')
LOC_PHP_TEST=$(find tests -name "*.php" | xargs wc -l | tail -1 | awk '{print $1}')
echo "LOC_PHP_SRC=$LOC_PHP_SRC" >> $GITHUB_ENV
echo "LOC_PHP_TEST=$LOC_PHP_TEST" >> $GITHUB_ENV
- name: Generate badges and deploy to GitHub Pages
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
# Save coverage report before switching branches
cp -r coverage-html /tmp/coverage-html
# Create a fresh gh-pages branch
git checkout --orphan gh-pages
git reset --hard
# Create directories
mkdir -p badges
mkdir -p coverage
# Copy coverage report
cp -r /tmp/coverage-html/* coverage/
# Add .nojekyll to allow underscore-prefixed files (like _css, _icons)
touch .nojekyll
# Generate coverage badge color based on percentage
if (( $(echo "$COVERAGE >= 80" | bc -l) )); then
COLOR="brightgreen"
elif (( $(echo "$COVERAGE >= 60" | bc -l) )); then
COLOR="yellow"
else
COLOR="red"
fi
# Download badges
curl -o badges/coverage.svg "https://img.shields.io/badge/coverage-${COVERAGE}%25-${COLOR}.svg"
curl -o badges/loc-src.svg "https://img.shields.io/badge/lib-${LOC_PHP_SRC}%20lines-blue.svg"
curl -o badges/loc-test.svg "https://img.shields.io/badge/tests-${LOC_PHP_TEST}%20lines-blue.svg"
curl -o badges/tests.svg "https://img.shields.io/badge/tests-passing-brightgreen.svg"
# Commit and push
git add .nojekyll badges/ coverage/
git commit -m "Update badges and coverage report"
git push --force https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git gh-pages