Skip to content

Commit

Permalink
chore: add integration test to pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
pkarolyi committed Apr 27, 2024
1 parent bd44cc0 commit 36f7c59
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 60 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ node_modules
.gitignore
.nvmrc
Dockerfile
Dockerfile.test
README.md
28 changes: 0 additions & 28 deletions .github/workflows/ci.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .github/workflows/docker.yml

This file was deleted.

95 changes: 95 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -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
122 changes: 122 additions & 0 deletions .github/workflows/push_main.yml
Original file line number Diff line number Diff line change
@@ -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 }}
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

# ---
Expand All @@ -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"]


8 changes: 8 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:20.12-alpine3.18

RUN apk --no-cache add git
RUN npm install -g --ignore-scripts [email protected]

COPY ./test/integration.sh .

ENTRYPOINT ["sh", "integration.sh"]
10 changes: 10 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
garden-snail:
build: .
ports:
- "3000:3000"
test:
build:
dockerfile: Dockerfile.test
depends_on:
- garden-snail
1 change: 1 addition & 0 deletions test/.turbo/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"token":"token_abcd","apiurl":"http://localhost:3000","teamid":"test"}
36 changes: 36 additions & 0 deletions test/integration.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 36f7c59

Please sign in to comment.