From 36f7c59d0ea2f3b6085d95b12d80a86f945383d2 Mon Sep 17 00:00:00 2001 From: Peter Karolyi Date: Sat, 27 Apr 2024 16:31:57 +0200 Subject: [PATCH] chore: add integration test to pipelines --- .dockerignore | 1 + .github/workflows/ci.yml | 28 ------- .github/workflows/docker.yml | 29 ------- .github/workflows/pull_request.yml | 95 ++++++++++++++++++++++ .github/workflows/push_main.yml | 122 +++++++++++++++++++++++++++++ Dockerfile | 5 +- Dockerfile.test | 8 ++ compose.yml | 10 +++ test/.turbo/config.json | 1 + test/integration.sh | 36 +++++++++ 10 files changed, 275 insertions(+), 60 deletions(-) delete mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/docker.yml create mode 100644 .github/workflows/pull_request.yml create mode 100644 .github/workflows/push_main.yml create mode 100644 Dockerfile.test create mode 100644 compose.yml create mode 100644 test/.turbo/config.json create mode 100644 test/integration.sh diff --git a/.dockerignore b/.dockerignore index ef37f19..c826ef5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,4 +7,5 @@ node_modules .gitignore .nvmrc Dockerfile +Dockerfile.test README.md \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index fd016dc..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Lint, Build, Test - -on: - push: - branches: ["main"] - pull_request: - branches: ["main"] - -jobs: - build: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v3 - - uses: actions/setup-node@v4 - with: - node-version: "20.12" - cache: "pnpm" - - name: Install dependencies - run: pnpm install - - name: Lint - run: pnpm lint - - name: Build - run: pnpm build - - name: Test - run: pnpm test:cov - - name: Test e2e - run: pnpm test:e2e diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index 10ee284..0000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Publish Docker image - -on: - push: - branches: ["main"] - -jobs: - push_to_registry: - name: Push Docker image to Docker Hub - runs-on: ubuntu-latest - steps: - - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - uses: actions/checkout@v4 - - uses: docker/setup-qemu-action@v3 - - uses: docker/setup-buildx-action@v3 - - uses: docker/metadata-action@v5 - id: meta - with: - images: pkarolyi/garden-snail - - uses: docker/build-push-action@v5 - with: - context: . - file: ./Dockerfile - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 0000000..19434df --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,95 @@ +name: Build and Test + +on: + pull_request: + types: ["opened", "reopened", "synchronize"] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + name: Build + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up pnpm + uses: pnpm/action-setup@v3 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.12" + cache: "pnpm" + - name: Install dependencies + run: pnpm install + - name: Build + run: pnpm build + lint: + name: Lint + runs-on: ubuntu-22.04 + needs: build + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up pnpm + uses: pnpm/action-setup@v3 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.12" + cache: "pnpm" + - name: Install dependencies + run: pnpm install + - name: Lint + run: pnpm lint + test: + name: Test (unit) + runs-on: ubuntu-22.04 + needs: build + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up pnpm + uses: pnpm/action-setup@v3 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.12" + cache: "pnpm" + - name: Install dependencies + run: pnpm install + - name: Test + run: pnpm test:cov + test-e2e: + name: Test (e2e) + runs-on: ubuntu-22.04 + needs: build + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up pnpm + uses: pnpm/action-setup@v3 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.12" + cache: "pnpm" + - name: Install dependencies + run: pnpm install + - name: Test e2e + run: pnpm test:e2e + test-integration: + name: Test (integration) + runs-on: ubuntu-22.04 + needs: [build, lint, test, test-e2e] + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up buildx + uses: docker/setup-buildx-action@v3 + - name: Build docker images + run: docker compose build + - name: Test API with turborepo + run: docker compose run test diff --git a/.github/workflows/push_main.yml b/.github/workflows/push_main.yml new file mode 100644 index 0000000..d72195c --- /dev/null +++ b/.github/workflows/push_main.yml @@ -0,0 +1,122 @@ +name: Build, Test and Publish + +on: + push: + branches: ["main"] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + name: Build + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up pnpm + uses: pnpm/action-setup@v3 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.12" + cache: "pnpm" + - name: Install dependencies + run: pnpm install + - name: Build + run: pnpm build + lint: + name: Lint + runs-on: ubuntu-22.04 + needs: build + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up pnpm + uses: pnpm/action-setup@v3 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.12" + cache: "pnpm" + - name: Install dependencies + run: pnpm install + - name: Lint + run: pnpm lint + test: + name: Test (unit) + runs-on: ubuntu-22.04 + needs: build + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up pnpm + uses: pnpm/action-setup@v3 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.12" + cache: "pnpm" + - name: Install dependencies + run: pnpm install + - name: Test + run: pnpm test:cov + test-e2e: + name: Test (e2e) + runs-on: ubuntu-22.04 + needs: build + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up pnpm + uses: pnpm/action-setup@v3 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.12" + cache: "pnpm" + - name: Install dependencies + run: pnpm install + - name: Test e2e + run: pnpm test:e2e + test-integration: + name: Test (integration) + runs-on: ubuntu-22.04 + needs: [build, lint, test, test-e2e] + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up buildx + uses: docker/setup-buildx-action@v3 + - name: Build docker images + run: docker compose build + - name: Test API with turborepo + run: docker compose run test + build-push-docker: + name: Build and Push Docker + runs-on: ubuntu-22.04 + needs: [build, lint, test, test-e2e, test-integration] + steps: + - name: Login to Dockerhub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up buildx + uses: docker/setup-buildx-action@v3 + - name: Collect image metadata + uses: docker/metadata-action@v5 + id: meta + with: + images: pkarolyi/garden-snail + - name: Build and push image to Dockerhub + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index 6ba2a75..60378ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,10 +11,9 @@ RUN apk --no-cache add g++ make py3-pip WORKDIR /garden-snail COPY package.json pnpm-lock.yaml ./ -COPY . . - RUN pnpm install --frozen-lockfile +COPY . . RUN pnpm build # --- @@ -32,6 +31,6 @@ RUN pnpm install --frozen-lockfile COPY --from=builder --chown=node:node /garden-snail/dist ./dist EXPOSE 3000 -CMD ["node", "dist/main"] +ENTRYPOINT ["node", "dist/main"] diff --git a/Dockerfile.test b/Dockerfile.test new file mode 100644 index 0000000..3befc62 --- /dev/null +++ b/Dockerfile.test @@ -0,0 +1,8 @@ +FROM node:20.12-alpine3.18 + +RUN apk --no-cache add git +RUN npm install -g --ignore-scripts pnpm@8.9.0 + +COPY ./test/integration.sh . + +ENTRYPOINT ["sh", "integration.sh"] diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..4c708a7 --- /dev/null +++ b/compose.yml @@ -0,0 +1,10 @@ +services: + garden-snail: + build: . + ports: + - "3000:3000" + test: + build: + dockerfile: Dockerfile.test + depends_on: + - garden-snail diff --git a/test/.turbo/config.json b/test/.turbo/config.json new file mode 100644 index 0000000..818db2c --- /dev/null +++ b/test/.turbo/config.json @@ -0,0 +1 @@ +{"token":"token_abcd","apiurl":"http://localhost:3000","teamid":"test"} diff --git a/test/integration.sh b/test/integration.sh new file mode 100644 index 0000000..597102d --- /dev/null +++ b/test/integration.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +echo "Checking out https://github.com/vercel/turbo (sparse checkout for \"examples/basic\")..." +git clone -n --depth=1 --filter=tree:0 https://github.com/vercel/turbo.git +cd /turbo +git sparse-checkout set --no-cone "examples/basic" +git checkout + +echo "pnpm install..." +cd /turbo/examples/basic +pnpm install --frozen-lockfile + +echo "enablig turbo remote cache..." +mkdir .turbo +echo "{\"token\":\"token_abcd\",\"apiurl\":\"http://garden-snail:3000\",\"teamid\":\"team_testing\"}" > .turbo/config.json + +echo "first build..." +pnpm build + +echo "removing local cache files..." +rm -r ./apps/docs/.next ./apps/web/.next ./apps/docs/.turbo ./apps/web/.turbo ./node_modules/.cache + +echo "second build..." +build_output=$(pnpm build) + +echo "$build_output" + +if (echo "$build_output" | grep -q "cache hit, replaying logs") && (echo "$build_output" | grep -q "FULL TURBO") +then + echo "SUCCESS" + exit 0 +else + echo "FAILURE" + exit 1 +fi +