|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: ~ |
| 8 | + workflow_dispatch: ~ |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +jobs: |
| 15 | + tests: |
| 16 | + name: Tests |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - |
| 20 | + name: Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + - |
| 23 | + name: Set up Docker Buildx |
| 24 | + uses: docker/setup-buildx-action@v3 |
| 25 | + - |
| 26 | + name: Create empty .env.local file |
| 27 | + run: touch .env.local |
| 28 | + - |
| 29 | + name: Build Docker images |
| 30 | + uses: docker/bake-action@v6 |
| 31 | + with: |
| 32 | + pull: true |
| 33 | + load: true |
| 34 | + files: | |
| 35 | + compose.yaml |
| 36 | + compose.override.yaml |
| 37 | + set: | |
| 38 | + *.cache-from=type=gha,scope=${{github.ref}} |
| 39 | + *.cache-from=type=gha,scope=refs/heads/main |
| 40 | + *.cache-to=type=gha,scope=${{github.ref}},mode=max |
| 41 | + - |
| 42 | + name: Start services |
| 43 | + run: docker compose up --wait --no-build |
| 44 | + - |
| 45 | + name: Check HTTP reachability |
| 46 | + run: curl -v --fail-with-body http://localhost |
| 47 | + - |
| 48 | + name: Check HTTPS reachability |
| 49 | + if: false # Remove this line when the homepage will be configured, or change the path to check |
| 50 | + run: curl -vk --fail-with-body https://localhost |
| 51 | +# - |
| 52 | +# name: Check Mercure reachability |
| 53 | +# run: curl -vkI --fail-with-body https://localhost/.well-known/mercure?topic=test |
| 54 | + - |
| 55 | + name: Create test database |
| 56 | + #if: false # Remove this line if Doctrine ORM is installed |
| 57 | + run: docker compose exec -T php bin/console -e test doctrine:database:create |
| 58 | + - |
| 59 | + name: Run migrations |
| 60 | + #if: false # Remove this line if Doctrine Migrations is installed |
| 61 | + run: docker compose exec -T php bin/console -e test doctrine:migrations:migrate --no-interaction |
| 62 | + - |
| 63 | + name: Run PHPUnit |
| 64 | + #if: false # Remove this line if PHPUnit is installed |
| 65 | + 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 |
| 66 | + - |
| 67 | + name: Process and Upload Coverage to Gist |
| 68 | + if: github.ref == 'refs/heads/main' |
| 69 | + run: | |
| 70 | + # Install necessary tools |
| 71 | + sudo apt-get update && sudo apt-get install -y bc jq libxml2-utils |
| 72 | + |
| 73 | + # Check if clover.xml exists |
| 74 | + if [ ! -f clover.xml ]; then |
| 75 | + echo "clover.xml not found, setting default values" |
| 76 | + COVERAGE=0 |
| 77 | + else |
| 78 | + # Extract metrics using xmllint |
| 79 | + echo "Extracting coverage metrics using xmllint..." |
| 80 | + STATEMENTS=$(xmllint --xpath "string(//project/metrics/@statements)" clover.xml) |
| 81 | + COVERED_STATEMENTS=$(xmllint --xpath "string(//project/metrics/@coveredstatements)" clover.xml) |
| 82 | + |
| 83 | + echo "Total statements: $STATEMENTS" |
| 84 | + echo "Covered statements: $COVERED_STATEMENTS" |
| 85 | + |
| 86 | + if [ -n "$STATEMENTS" ] && [ -n "$COVERED_STATEMENTS" ] && [ "$STATEMENTS" -gt 0 ]; then |
| 87 | + COVERAGE=$(echo "scale=4; ($COVERED_STATEMENTS / $STATEMENTS) * 100" | bc) |
| 88 | + else |
| 89 | + COVERAGE=0 |
| 90 | + fi |
| 91 | + fi |
| 92 | + |
| 93 | + COVERAGE_ROUNDED=$(printf "%.1f" $COVERAGE) |
| 94 | + echo "Coverage: $COVERAGE_ROUNDED%" |
| 95 | + |
| 96 | + # Determine color based on coverage percentage |
| 97 | + if (( $(echo "$COVERAGE >= 80" | bc -l) )); then |
| 98 | + COLOR="brightgreen" |
| 99 | + elif (( $(echo "$COVERAGE >= 70" | bc -l) )); then |
| 100 | + COLOR="green" |
| 101 | + elif (( $(echo "$COVERAGE >= 60" | bc -l) )); then |
| 102 | + COLOR="yellowgreen" |
| 103 | + elif (( $(echo "$COVERAGE >= 50" | bc -l) )); then |
| 104 | + COLOR="yellow" |
| 105 | + else |
| 106 | + COLOR="red" |
| 107 | + fi |
| 108 | + |
| 109 | + # Create JSON payload for shields.io endpoint |
| 110 | + BADGE_JSON="{\"schemaVersion\": 1, \"label\": \"coverage\", \"message\": \"${COVERAGE_ROUNDED}%\", \"color\": \"$COLOR\"}" |
| 111 | + echo "$BADGE_JSON" > coverage.json |
| 112 | + |
| 113 | + # Send as a string to the GitHub API |
| 114 | + curl -X PATCH \ |
| 115 | + -H "Authorization: token ${{ secrets.GIST_TOKEN }}" \ |
| 116 | + -H "Content-Type: application/json" \ |
| 117 | + -d "{\"files\": {\"coverage.json\": {\"content\": $(echo "$BADGE_JSON" | jq -Rs .)}}}" \ |
| 118 | + https://api.github.com/gists/${{ secrets.GIST_ID }} |
| 119 | + env: |
| 120 | + GIST_TOKEN: ${{ secrets.GIST_TOKEN }} |
| 121 | + GIST_ID: ${{ secrets.GIST_ID }} |
| 122 | + - |
| 123 | + name: Doctrine Schema Validator |
| 124 | + #if: false # Remove this line if Doctrine ORM is installed |
| 125 | + run: docker compose exec -T php bin/console -e test doctrine:schema:validate |
| 126 | + - |
| 127 | + name: PHPStan analysis |
| 128 | + run: docker compose exec -T php vendor/bin/phpstan analyse src --memory-limit=-1 |
| 129 | + |
| 130 | + lint: |
| 131 | + name: Docker Lint |
| 132 | + runs-on: ubuntu-latest |
| 133 | + steps: |
| 134 | + - |
| 135 | + name: Checkout |
| 136 | + uses: actions/checkout@v4 |
| 137 | + - |
| 138 | + name: Lint Dockerfile |
| 139 | + uses: hadolint/hadolint-action@v3.1.0 |
0 commit comments