name: "CI: Backend" defaults: run: shell: bash on: pull_request: paths: - 'backend/**' - 'common/**' types: - opened - synchronize - ready_for_review push: branches: - develop - staging paths: - 'backend/**' - 'common/**' concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true permissions: contents: read jobs: test-backend: if: ${{ !github.event.pull_request.draft }} permissions: contents: read pull-requests: write # coverage comment on the PR name: "Backend Tests" runs-on: penpot-extended-runner container: image: penpotapp/devenv:latest volumes: - /var/cache/github-runner/m2:/root/.m2 - /var/cache/github-runner/gitlib:/root/.gitlibs services: postgres: image: postgres:17 # Provide the password for postgres env: POSTGRES_USER: penpot_test POSTGRES_PASSWORD: penpot_test POSTGRES_DB: penpot_test # Set health checks to wait until postgres has started options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 redis: image: valkey/valkey:9 steps: - name: Checkout repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - name: Fmt working-directory: ./backend run: | cljfmt check --parallel=true src/ test/ - name: Lint working-directory: ./backend run: | clj-kondo --parallel --lint ../common/src/ src/ - name: Tests working-directory: ./backend env: # `clojure.core/assert` is elided at compile time, so without this # flag the precondition asserts do not exist in the compiled code # and the suite silently stops checking them. PENPOT_FLAGS: "enable-backend-asserts" PENPOT_TEST_DATABASE_URI: "postgresql://postgres/penpot_test" PENPOT_TEST_DATABASE_USERNAME: penpot_test PENPOT_TEST_DATABASE_PASSWORD: penpot_test PENPOT_TEST_REDIS_URI: "redis://redis/1" run: | mkdir -p /tmp/penpot; clojure -M:dev:test:coverage - name: Coverage summary if: ${{ !cancelled() && hashFiles('backend/target/coverage/lcov.info') != '' }} run: | node scripts/coverage-summary.mjs \ --title "Backend test coverage" \ --note "Namespaces under \`backend/src/app\`." \ --lcov backend/target/coverage/lcov.info \ > backend/target/coverage/summary.md cat backend/target/coverage/summary.md >> "$GITHUB_STEP_SUMMARY" - name: Coverage comment # Fork PRs get a read-only token, so only branches of this repo comment. if: ${{ !cancelled() && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && hashFiles('backend/target/coverage/lcov.info') != '' }} continue-on-error: true env: GITHUB_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.pull_request.number }} HEAD_SHA: ${{ github.event.pull_request.head.sha }} run: | node scripts/coverage-comment.mjs \ --project Backend \ --lcov backend/target/coverage/lcov.info \ --emma-xml backend/target/coverage/coverage.xml \ --prefix backend/ - name: Upload coverage report uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 if: ${{ !cancelled() }} with: name: backend-coverage path: backend/target/coverage/ overwrite: true if-no-files-found: ignore retention-days: 7