diff --git a/.gitea/workflows/build-and-deploy.yml b/.gitea/workflows/build-and-deploy.yml index 2dea98f..2343ee0 100644 --- a/.gitea/workflows/build-and-deploy.yml +++ b/.gitea/workflows/build-and-deploy.yml @@ -21,9 +21,121 @@ env: DEPLOY_ROOT: /opt/rentaldrivego jobs: + pipeline-tests: + name: Pipeline Tests + runs-on: ubuntu-latest + services: + postgres: + image: postgres:16-alpine + env: + POSTGRES_DB: rentaldrivego_test + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + redis: + image: redis:7-alpine + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + env: + DATABASE_URL: postgresql://postgres:password@postgres:5432/rentaldrivego_test + REDIS_URL: redis://redis:6379 + NODE_ENV: test + JWT_SECRET: test-secret + JWT_EXPIRY: 8h + FILE_STORAGE_ROOT: /tmp/rentaldrivego-test-storage + steps: + - name: Checkout repository + shell: bash + env: + GITEA_SERVER_URL: ${{ gitea.server_url }} + GITEA_REPOSITORY: ${{ gitea.repository }} + GITEA_SHA: ${{ gitea.sha }} + CHECKOUT_TOKEN: ${{ gitea.token }} + run: | + set -euo pipefail + if ! command -v git >/dev/null 2>&1; then + echo "::error::git must be available in the runner image" + exit 1 + fi + + WORKSPACE="${GITHUB_WORKSPACE:-$PWD}" + mkdir -p "$WORKSPACE" + cd "$WORKSPACE" + + SERVER_URL="${GITEA_SERVER_URL:-${GITHUB_SERVER_URL:-}}" + REPOSITORY="${GITEA_REPOSITORY:-${GITHUB_REPOSITORY:-}}" + SHA="${GITEA_SHA:-${GITHUB_SHA:-}}" + if [ -z "$SERVER_URL" ] || [ -z "$REPOSITORY" ] || [ -z "$SHA" ]; then + echo "::error::Missing repository checkout context" + exit 1 + fi + + REPOSITORY_URL="${SERVER_URL}/${REPOSITORY}.git" + if [ ! -d .git ]; then + git init + git remote add origin "$REPOSITORY_URL" + fi + + git config --global --add safe.directory "$WORKSPACE" + if [ -n "${CHECKOUT_TOKEN:-}" ]; then + git -c "http.extraHeader=Authorization: token ${CHECKOUT_TOKEN}" fetch --no-tags --depth=1 origin "$SHA" + else + git fetch --no-tags --depth=1 origin "$SHA" + fi + git checkout --force FETCH_HEAD + + - uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + + - run: corepack enable && corepack prepare npm@10.5.0 --activate + + - name: Install dependencies + run: | + for attempt in 1 2 3; do + npm ci --include=optional && break + if [ "$attempt" = "3" ]; then + exit 1 + fi + npm cache verify || true + sleep "$((attempt * 10))" + done + + - name: Repair Rollup optional dependency on Linux ARM64 + run: | + ARCH="$(uname -m)" + if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then + ROLLUP_VERSION="$(node -p "require('./node_modules/rollup/package.json').version")" + for attempt in 1 2 3; do + npm install --no-save --include=optional "@rollup/rollup-linux-arm64-gnu@$ROLLUP_VERSION" && break + if [ "$attempt" = "3" ]; then + exit 1 + fi + npm cache verify || true + sleep "$((attempt * 10))" + done + node -e "require('@rollup/rollup-linux-arm64-gnu')" + fi + + - run: npm run db:generate + - run: npm run type-check + - run: npm run test:api + - run: npm run test:frontends + - run: npm run db:deploy + - run: npx prisma db push --schema packages/database/prisma/schema.prisma + - run: npm run test:api:integration + build-image: name: Build & Push Docker Image runs-on: ubuntu-latest + needs: pipeline-tests outputs: image_repository: ${{ steps.image-meta.outputs.repository }} docker_image: ${{ steps.image-meta.outputs.full }} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8c7e981..ed8397a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -120,6 +120,13 @@ integration_tests: build_image: stage: build image: docker:24 + needs: + - api_tests + - carplace_tests + - admin_tests + - dashboard_tests + - homepage_tests + - integration_tests services: - name: docker:24-dind alias: docker