name: CI on: push: branches: ['release/*'] pull_request: branches: [main] jobs: ci: runs-on: docker container: image: catthehacker/ubuntu:act-latest services: postgres: image: postgres:16-alpine env: POSTGRES_USER: app POSTGRES_PASSWORD: "!ChangeMe!" POSTGRES_DB: app options: >- --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10 steps: - uses: https://data.forgejo.org/actions/checkout@v4 - name: Set up PHP uses: https://github.com/shivammathur/setup-php@v2 with: php-version: '8.4' extensions: pdo_pgsql, mbstring, xml, dom, intl coverage: pcov - name: Cache Composer dependencies uses: https://data.forgejo.org/actions/cache@v4 with: path: ~/.composer/cache key: composer-${{ hashFiles('composer.lock') }} restore-keys: composer- - name: Install dependencies run: composer install --no-interaction --prefer-dist - name: Build Tailwind CSS run: php bin/console tailwind:build - name: Lint run: vendor/bin/php-cs-fixer fix --dry-run --diff - name: Static analysis run: composer stan - name: Create and migrate test database env: DATABASE_URL: postgresql://app:!ChangeMe!@postgres:5432/app?serverVersion=16&charset=utf8 run: | php bin/console --env=test doctrine:database:create --if-not-exists php bin/console --env=test doctrine:migrations:migrate --no-interaction - name: Tests env: DATABASE_URL: postgresql://app:!ChangeMe!@postgres:5432/app?serverVersion=16&charset=utf8 run: php bin/phpunit --coverage-clover coverage.xml --coverage-text - name: Parse coverage if: github.event_name == 'pull_request' id: coverage run: | COVERAGE=$(php -r ' $xml = simplexml_load_file("coverage.xml"); if ($xml === false || !isset($xml->project->metrics)) { echo "0"; exit; } $metrics = $xml->project->metrics; $statements = (int) $metrics["statements"]; $covered = (int) $metrics["coveredstatements"]; echo $statements > 0 ? round(($covered / $statements) * 100, 2) : 0; ') echo "percentage=$COVERAGE" >> "$GITHUB_OUTPUT" - name: Comment coverage on PR if: github.event_name == 'pull_request' env: FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }} PR_NUMBER: ${{ github.event.pull_request.number }} COVERAGE: ${{ steps.coverage.outputs.percentage }} REPO: ${{ github.repository }} SERVER_URL: ${{ github.server_url }} COMMIT_SHA: ${{ github.sha }} run: | API_URL="${SERVER_URL}/api/v1/repos/${REPO}/issues/${PR_NUMBER}/comments" MARKER="" BODY="${MARKER} ## Code Coverage Report | Metric | Value | |--------|-------| | **Line Coverage** | ${COVERAGE}% | _Updated by CI — commit ${COMMIT_SHA}_" # Find existing coverage comment EXISTING=$(curl -sf -H "Authorization: token ${FORGEJO_TOKEN}" \ "${API_URL}?limit=50" | \ php -r ' $comments = json_decode(file_get_contents("php://stdin"), true); if (!is_array($comments)) exit; foreach ($comments as $c) { if (str_contains($c["body"], "")) { echo $c["id"]; exit; } } ' || true) if [ -n "$EXISTING" ]; then curl -sf -X PATCH \ -H "Authorization: token ${FORGEJO_TOKEN}" \ -H "Content-Type: application/json" \ -d "$(php -r 'echo json_encode(["body" => $argv[1]]);' "$BODY")" \ "${SERVER_URL}/api/v1/repos/${REPO}/issues/comments/${EXISTING}" > /dev/null else curl -sf -X POST \ -H "Authorization: token ${FORGEJO_TOKEN}" \ -H "Content-Type: application/json" \ -d "$(php -r 'echo json_encode(["body" => $argv[1]]);' "$BODY")" \ "${API_URL}" > /dev/null fi