From b5e7dfee10bd56d545f184febb08d490de497150 Mon Sep 17 00:00:00 2001 From: Prisca Date: Sun, 3 Nov 2024 21:51:16 +0100 Subject: [PATCH] chore(ci): update CI to use new docker container workflow --- .env.ci | 29 ++++++++ .env.example | 3 + .github/workflows/checks.yml | 131 ++--------------------------------- .github/workflows/tools.yml | 91 ++++++++++++++++++++++++ biome.json | 2 +- docker-compose.tools.yaml | 9 +-- 6 files changed, 134 insertions(+), 131 deletions(-) create mode 100644 .env.ci create mode 100644 .github/workflows/tools.yml diff --git a/.env.ci b/.env.ci new file mode 100644 index 0000000..d93be5c --- /dev/null +++ b/.env.ci @@ -0,0 +1,29 @@ +TZ=UTC +PORT=3333 +HOST=localhost +LOG_LEVEL=info +APP_KEY=1234567890123456 +NODE_ENV=test + +BYPASS_LOGIN=true + +SESSION_DRIVER=memory + +DB_CONNECTION=postgres +DB_HOST=localhost +DB_PORT=5432 +DB_USER=postgres +DB_PASSWORD=postgres +DB_DATABASE=postgres + +REDIS_PASSWORD=1234 +REDIS_HOST=localhost +REDIS_PORT=6379 +REDIS_DB=1 + +TWITCH_CLIENT_ID=client_id +TWITCH_CLIENT_SECRET=client_secret +TWITCH_CALLBACK_URL=http://localhost:3333/auth/twitch/callback + +# Game length in seconds +GAME_LENGTH=90 diff --git a/.env.example b/.env.example index c83ba95..c7bb4b1 100644 --- a/.env.example +++ b/.env.example @@ -27,3 +27,6 @@ TWITCH_CALLBACK_URL= # Game length in seconds GAME_LENGTH=90 + + + diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 3ab92f9..f44634d 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -14,130 +14,9 @@ concurrency: group: ci-${{ github.workflow }}-${{ github.ref }} jobs: - lint: - runs-on: ubuntu-latest + tools: + uses: ./.github/workflows/tools.yml + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} - steps: - - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: 21 - - - name: Install pnpm - run: | - corepack enable - corepack prepare pnpm@latest --activate - - - name: Install dependencies - run: pnpm install - - - name: Lint - run: pnpm lint - - typecheck: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: 21 - - - name: Install pnpm - run: | - corepack enable - corepack prepare pnpm@latest --activate - - - name: Install dependencies - run: | - pnpm install - pnpm -r build - - - name: Typecheck - run: pnpm typecheck - - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: 21 - - - name: Install pnpm - run: | - corepack enable - corepack prepare pnpm@latest --activate - - - name: Install dependencies - run: pnpm install - - - name: Build - run: pnpm build - - tests: - runs-on: ubuntu-latest - timeout-minutes: 10 - - services: - redis: - image: redis:6.2-alpine - ports: - - 6379:6379 - postgres: - image: postgres:15-alpine - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: postgres - ports: - - 5432:5432 - - steps: - - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: 21 - - - name: Install pnpm - run: | - corepack enable - corepack prepare pnpm@latest --activate - - - name: Install dependencies - run: | - pnpm install - pnpm exec playwright install - - - name: Run tests - env: - APP_KEY: 1234567890123456 - NODE_ENV: test - PORT: 3030 - HOST: localhost - LOG_LEVEL: info - SESSION_DRIVER: memory - BYPASS_LOGIN: true - REDIS_HOST: localhost - REDIS_PORT: 6379 - REDIS_DB: 1 - DB_CONNECTION: postgres - DB_HOST: localhost - DB_PORT: 5432 - DB_USER: postgres - DB_PASSWORD: postgres - DB_DATABASE: postgres - TWITCH_CLIENT_ID: client_id - TWITCH_CLIENT_SECRET: client_secret - TWITCH_CALLBACK_URL: http://localhost:3333/auth/twitch/callback - GAME_LENGTH: 90 - run: FORCE_COLOR=1 pnpm test -r diff --git a/.github/workflows/tools.yml b/.github/workflows/tools.yml new file mode 100644 index 0000000..d6b0e9c --- /dev/null +++ b/.github/workflows/tools.yml @@ -0,0 +1,91 @@ +name: Tools CI + +on: + workflow_call: + secrets: + DOCKERHUB_USERNAME: + required: true + DOCKERHUB_PASSWORD: + required: true + +env: + COMPOSE_FILE_TOOLS: ./docker-compose.tools.yaml + COMPOSE_FILE: ./docker-compose.yaml + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Login to DockerHub + uses: docker/login-action@v3.3.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Run lint + run: | + docker compose -f ${{ env.COMPOSE_FILE_TOOLS }} run --rm install-node-deps + docker compose -f ${{ env.COMPOSE_FILE_TOOLS }} run --rm biome-check + + typecheck: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Login to DockerHub + uses: docker/login-action@v3.3.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Run typecheck + run: | + docker compose -f ${{ env.COMPOSE_FILE_TOOLS }} run --rm install-node-deps + docker compose -f ${{ env.COMPOSE_FILE_TOOLS }} run --rm tsc + + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Login to DockerHub + uses: docker/login-action@v3.3.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Ensure /app/build is not in use + run: | + fuser -k build || true + + - name: Run build + run: | + docker compose -f ${{ env.COMPOSE_FILE_TOOLS }} run --rm install-node-deps + docker compose -f ${{ env.COMPOSE_FILE_TOOLS }} run --rm build + + tests: + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - uses: actions/checkout@v4 + + - name: Login to DockerHub + uses: docker/login-action@v3.3.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Run tests + run: | + cp .env.ci .env + docker compose -f ${{ env.COMPOSE_FILE }} up -d redis + docker compose -f ${{ env.COMPOSE_FILE_TOOLS }} run --rm install-node-deps + docker compose -f ${{ env.COMPOSE_FILE_TOOLS }} up -d postgres-test + docker compose -f ${{ env.COMPOSE_FILE_TOOLS }} run --rm biome-check + docker compose -f ${{ env.COMPOSE_FILE_TOOLS }} run --rm test diff --git a/biome.json b/biome.json index c1d1b42..f98ad44 100644 --- a/biome.json +++ b/biome.json @@ -3,7 +3,7 @@ "vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false }, "files": { "ignoreUnknown": false, - "ignore": ["node_modules", "dist", "build", "public", "resources"] + "ignore": ["node_modules", "dist", "build", "public", "resources", ".pnpm-store"] }, "formatter": { "enabled": true, diff --git a/docker-compose.tools.yaml b/docker-compose.tools.yaml index 21b1205..eead75a 100644 --- a/docker-compose.tools.yaml +++ b/docker-compose.tools.yaml @@ -15,7 +15,7 @@ services: - node_modules:/app/node_modules working_dir: /app entrypoint: [ "sh", "-c" ] - command: ["corepack enable && pnpm typecheck"] + command: ["corepack enable && FORCE_COLOR=1 pnpm typecheck"] biome-check: image: node:23.0 @@ -24,7 +24,7 @@ services: - node_modules:/app/node_modules working_dir: /app entrypoint: [ "sh", "-c" ] - command: ["corepack enable && pnpm lint"] + command: ["corepack enable && FORCE_COLOR=1 pnpm lint"] biome-check-fix: image: node:23.0 @@ -33,7 +33,7 @@ services: - node_modules:/app/node_modules working_dir: /app entrypoint: [ "sh", "-c" ] - command: ["corepack enable && pnpm lint --write"] + command: ["corepack enable && FORCE_COLOR=1 pnpm lint --write"] build: image: node:23.0 @@ -42,7 +42,8 @@ services: - node_modules:/app/node_modules - build:/app/build working_dir: /app - command: ["node", "ace", "build"] + entrypoint: [ "sh", "-c" ] + command: ["corepack enable && FORCE_COLOR=1 pnpm build"] test: image: node:23.0