-
Notifications
You must be signed in to change notification settings - Fork 0
executable file
·139 lines (128 loc) · 4.99 KB
/
ci.yml
File metadata and controls
executable file
·139 lines (128 loc) · 4.99 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: CI
on:
push:
branches:
- main
pull_request: ~
workflow_dispatch: ~
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
tests:
name: Tests
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Create empty .env.local file
run: touch .env.local
-
name: Build Docker images
uses: docker/bake-action@v6
with:
pull: true
load: true
files: |
compose.yaml
compose.override.yaml
set: |
*.cache-from=type=gha,scope=${{github.ref}}
*.cache-from=type=gha,scope=refs/heads/main
*.cache-to=type=gha,scope=${{github.ref}},mode=max
-
name: Start services
run: docker compose up --wait --no-build
-
name: Check HTTP reachability
run: curl -v --fail-with-body http://localhost
-
name: Check HTTPS reachability
if: false # Remove this line when the homepage will be configured, or change the path to check
run: curl -vk --fail-with-body https://localhost
# -
# name: Check Mercure reachability
# run: curl -vkI --fail-with-body https://localhost/.well-known/mercure?topic=test
-
name: Create test database
#if: false # Remove this line if Doctrine ORM is installed
run: docker compose exec -T php bin/console -e test doctrine:database:create
-
name: Run migrations
#if: false # Remove this line if Doctrine Migrations is installed
run: docker compose exec -T php bin/console -e test doctrine:migrations:migrate --no-interaction
-
name: Run PHPUnit
#if: false # Remove this line if PHPUnit is installed
run: docker compose exec -e XDEBUG_MODE=coverage -e SYMFONY_DEPRECATIONS_HELPER=disabled php php bin/phpunit -vvv --testdox --verbose --debug --coverage-clover clover.xml
-
name: Process and Upload Coverage to Gist
if: github.ref == 'refs/heads/main'
run: |
# Install necessary tools
sudo apt-get update && sudo apt-get install -y bc jq libxml2-utils
# Check if clover.xml exists
if [ ! -f clover.xml ]; then
echo "clover.xml not found, setting default values"
COVERAGE=0
else
# Extract metrics using xmllint
echo "Extracting coverage metrics using xmllint..."
STATEMENTS=$(xmllint --xpath "string(//project/metrics/@statements)" clover.xml)
COVERED_STATEMENTS=$(xmllint --xpath "string(//project/metrics/@coveredstatements)" clover.xml)
echo "Total statements: $STATEMENTS"
echo "Covered statements: $COVERED_STATEMENTS"
if [ -n "$STATEMENTS" ] && [ -n "$COVERED_STATEMENTS" ] && [ "$STATEMENTS" -gt 0 ]; then
COVERAGE=$(echo "scale=4; ($COVERED_STATEMENTS / $STATEMENTS) * 100" | bc)
else
COVERAGE=0
fi
fi
COVERAGE_ROUNDED=$(printf "%.1f" $COVERAGE)
echo "Coverage: $COVERAGE_ROUNDED%"
# Determine color based on coverage percentage
if (( $(echo "$COVERAGE >= 80" | bc -l) )); then
COLOR="brightgreen"
elif (( $(echo "$COVERAGE >= 70" | bc -l) )); then
COLOR="green"
elif (( $(echo "$COVERAGE >= 60" | bc -l) )); then
COLOR="yellowgreen"
elif (( $(echo "$COVERAGE >= 50" | bc -l) )); then
COLOR="yellow"
else
COLOR="red"
fi
# Create JSON payload for shields.io endpoint
BADGE_JSON="{\"schemaVersion\": 1, \"label\": \"coverage\", \"message\": \"${COVERAGE_ROUNDED}%\", \"color\": \"$COLOR\"}"
echo "$BADGE_JSON" > coverage.json
# Send as a string to the GitHub API
curl -X PATCH \
-H "Authorization: token ${{ secrets.GIST_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"files\": {\"coverage.json\": {\"content\": $(echo "$BADGE_JSON" | jq -Rs .)}}}" \
https://api.github.com/gists/${{ secrets.GIST_ID }}
env:
GIST_TOKEN: ${{ secrets.GIST_TOKEN }}
GIST_ID: ${{ secrets.GIST_ID }}
-
name: Doctrine Schema Validator
#if: false # Remove this line if Doctrine ORM is installed
run: docker compose exec -T php bin/console -e test doctrine:schema:validate
-
name: PHPStan analysis
run: docker compose exec -T php vendor/bin/phpstan analyse src --memory-limit=-1
lint:
name: Docker Lint
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Lint Dockerfile
uses: hadolint/hadolint-action@v3.1.0