"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateBitbucketPipelinesYml = generateBitbucketPipelinesYml;
function generateBitbucketPipelinesYml({ schema: { slug }, devOps: { database, keycloak }, }) {
    return /*yml*/ `
image: node:20
options:
  docker: true

clone:
  depth: full

definitions:
  caches:
    pnpm: ~/.pnpm-store
    sonar: ~/.sonar/cache
  services:
    docker:
      memory: 3072
  steps:
    - step: &build-test
        name: Build and test
        caches:
          - pnpm
          - sonar
        services:
          - docker
        size: 4x
        script:
          - export ENABLE_BACKEND_SHUTDOWN=true
          - export PLAYWRIGHT_WORKERS=1
          ${database ? startPostgres : ''}
          - npm install -g pnpm
          - pnpm run setup
          - pnpm prisma migrate dev --skip-generate
          - pnpm run --dir backend/ e2e:coverage &
          # Wait for backend to be healthy
          - retries=0
          - until curl --silent --fail http://localhost:3001/health || [ $((retries++)) -ge 10 ]; do sleep $((10 * retries)); done

          - pnpm run --dir frontend/ e2e:ci &
          # Wait for frontend to be healthy
          - retries=0
          - until curl --silent --fail http://localhost:3000/health || [ $((retries++)) -ge 10 ]; do sleep $((10 * retries)); done

          - pnpm run --dir backend/ test:jest

          - (cd e2e && npx playwright install --with-deps && npx playwright test)
        artifacts:
          - 'e2e/test-results/**'
          - 'backend/coverage/**'
    - step: &run-sonar-scan-sonarcloud
        name: Run Sonar Scan on SonarCloud
        size: 4x
        script:
          - pipe: sonarsource/sonarcloud-scan:2.0.0
    - step: &check-quality-gate-sonarcloud
        name: Check the Quality Gate on SonarCloud
        size: 4x
        script:
          - pipe: sonarsource/sonarcloud-quality-gate:0.1.6
    - step: &lint-dockerfile
        name: Lint the Dockerfile
        image: hadolint/hadolint:latest-debian
        script:
          ${keycloak ? '- hadolint docker/keycloak/Dockerfile' : ''}
          - hadolint docker/backend/Dockerfile
          - hadolint docker/frontend/Dockerfile
    - step: &build-images
        name: Build the application
        caches:
          - pnpm
          - docker
        size: 2x
        script:
          # Build the Docker image (to do asset and template compilation, etc.)
          ${keycloak ? `- docker build -t ${slug}-keycloak:latest -f ./docker/Keycloak/Dockerfile .` : ''}
          - docker build -t ${slug}-backend:latest -f ./docker/backend/Dockerfile .
          - docker build -t ${slug}-frontend:latest -f ./docker/frontend/Dockerfile .

pipelines:
  pull-requests:
    '**':
      - parallel:
          - step: *lint-dockerfile
          - step: *build-test
      - step: *run-sonar-scan-sonarcloud
      - step: *check-quality-gate-sonarcloud
  branches:
    main:
      - parallel:
          - step: *lint-dockerfile
          - step: *build-test
      - step: *run-sonar-scan-sonarcloud
      - step: *check-quality-gate-sonarcloud
      - step: *build-images
`;
}
const startPostgres = `
          # Start Postgres
          - docker run --name postgres -e POSTGRES_USER=$POSTGRES_USER -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -e POSTGRES_DB=$POSTGRES_DB -p 5432:5432 -d postgres:13
          # Wait for Postgres to be ready
          - until docker exec postgres pg_isready -U $POSTGRES_USER || [ $((retries++)) -ge 10 ]; do sleep $((10 * retries)); done
`;
//# sourceMappingURL=bitbucket-pipelines-yml.generator.js.map