Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tsa96 committed Jun 29, 2023
1 parent c8cea9b commit 104890d
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 228 deletions.
17 changes: 17 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
NODE_ENV=test
NODE_PORT=3003
POSTGRES_USER=root
POSTGRES_DB=momentum
POSTGRES_PASSWORD=root
POSTGRES_PORT=5432
DATABASE_URL=postgresql://root:root@db/momentum?schema=public
MINIO_ROOT_USER=minio
MINIO_ROOT_PASSWORD=minio123
STORAGE_REGION=us-west-1
STORAGE_BUCKET_NAME=momtest
STORAGE_ACCESS_KEY_ID=minio
STORAGE_SECRET_ACCESS_KEY=minio123
STORAGE_ENDPOINT_URL=http://minio:9000
STEAM_WEB_API_KEY=thisisenoughtogenerateanopenidreferralforsomereason
SESSION_SECRET=thisisashitsecretdontuseitinprod
JWT_SECRET=thisisalsonotasecure
185 changes: 69 additions & 116 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,131 +1,84 @@
name: Tests and Linting

name: Code Quality
on:
pull_request:
branches:
- staging
- nestJS # TODO: Remove when done
paths-ignore:
- '**.md'

# TODO: Client stuff will need upgrading when NestJS rewrite is completed.
- main
jobs:
# client-lint:
# name: Client Lint
# runs-on: ubuntu-latest
#
# steps:
# - name: Checkout
# uses: actions/checkout@v2
#
# - name: Get specific changed files
# id: changed-files-specific
# uses: tj-actions/changed-files@v12
# with:
# files: client\/.*\.(js|ts|scss|html)$
#
# - name: Setup Node
# if: steps.changed-files-specific.outputs.any_changed == 'true'
# uses: actions/setup-node@v1
# with:
# node-version: "12.x"
#
# - name: Resolve Yarn Cache Directory
# if: steps.changed-files-specific.outputs.any_changed == 'true'
# id: yarn-cache-dir-path
# run: echo "::set-output name=dir::$(yarn cache dir)"
#
# - name: Cache Yarn Cache Directory
# if: steps.changed-files-specific.outputs.any_changed == 'true'
# uses: actions/cache@v2
# with:
# path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
# key: ${{ runner.os }}-${{ env.NODE_VERSION }}-${{ hashFiles('./client/yarn.lock') }}
# restore-keys: ${{ runner.os }}-${{ env.NODE_VERSION }}-
#
# - name: Run Lint
# if: steps.changed-files-specific.outputs.any_changed == 'true'
# run: |
# cd ./client/
# npm install -g @angular/cli && yarn install --prefer-offline
# npm run lint:ci
#
# client-tests:
# name: Client Tests
# runs-on: ubuntu-latest
#
# steps:
# - name: Checkout
# uses: actions/checkout@v2
#
# - name: Get specific changed files
# id: changed-files-specific
# uses: tj-actions/changed-files@v12
# with:
# files: .(ts)$
#
# - name: Setup Node
# if: steps.changed-files-specific.outputs.any_changed == 'true'
# uses: actions/setup-node@v1
# with:
# node-version: "12.x"
#
# - name: Resolve Yarn Cache Directory
# if: steps.changed-files-specific.outputs.any_changed == 'true'
# id: yarn-cache-dir-path
# run: echo "::set-output name=dir::$(yarn cache dir)"
#
# - name: Cache Yarn Cache Directory
# if: steps.changed-files-specific.outputs.any_changed == 'true'
# uses: actions/cache@v2
# with:
# path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
# key: ${{ runner.os }}-${{ env.NODE_VERSION }}-${{ hashFiles('./client/yarn.lock') }}
# restore-keys: ${{ runner.os }}-${{ env.NODE_VERSION }}-
#
# - name: Run Tests
# if: steps.changed-files-specific.outputs.any_changed == 'true'
# run: |
# cd ./client/
# npm install -g @angular/cli && yarn install --prefer-offline
# npm run test
#
backend-lint:
name: Backend Lint/Formatting
install-deps:
name: Install Dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
id: cache
with:
path: node_modules
key: modules-${{ hashFiles('package-lock.json') }}
- uses: actions/setup-node@v3
if: steps.cache.outputs.cache-hit != 'true'
with:
node-version: 18
node-version: 18.x
cache: 'npm'
cache-dependency-path: server/package-lock.json

- name: Install packages
working-directory: server
run: npm install

- name: npm install
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci --no-scripts
lint:
name: Linting and Formatting
runs-on: ubuntu-latest
needs: install-deps
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: node_modules
key: modules-${{ hashFiles('package-lock.json') }}
- run: git fetch --no-tags --prune --depth=1 origin main
- name: commitlint
if: github.event_name == 'pull_request'
run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose
- name: Prettier
working-directory: server
run: npm run format:check

run: npx nx format:check --base=origin/main
- name: ESLint
working-directory: server
run: npm run lint:check

backend-tests:
name: Backend Tests
run: npx nx affected --target=lint --base=origin/main --parallel=3
test:
name: Unit Tests
runs-on: ubuntu-latest
needs: install-deps
steps:
- uses: actions/checkout@v3
- name: Cache node_modules
uses: actions/cache@v3
with:
path: node_modules
key: modules-${{ hashFiles('package-lock.json') }}
- run: git fetch --no-tags --prune --depth=1 origin main
- run: npx nx affected --target=test --base=origin/main --parallel=3
e2e:
name: E2E Tests
runs-on: ubuntu-latest
needs: install-deps
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v35
- uses: actions/checkout@v3
- name: Cache node_modules
uses: actions/cache@v3
with:
path: node_modules
key: modules-${{ hashFiles('package-lock.json') }}
- name: Launch Docker containers
run:
docker compose
-f docker-compose.yml -f docker-compose.test.yml
run e2e-tests
build:
name: Build
runs-on: ubuntu-latest
needs: install-deps
steps:
- uses: actions/checkout@v3
- name: Cache node_modules
uses: actions/cache@v3
with:
files: server/**/*.{ts,js,prisma}

- name: Execute tests
if: steps.changed-files.outputs.any_changed == 'true'
run: docker compose -f docker-compose.yml -f docker-compose.test.yml up --build --exit-code-from api
path: node_modules
key: modules-${{ hashFiles('package-lock.json') }}
- run: git fetch --no-tags --prune --depth=1 origin main
- run: npx nx affected --target=build --base=origin/main --parallel=3
100 changes: 0 additions & 100 deletions .github/workflows/tests.yml

This file was deleted.

41 changes: 29 additions & 12 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ services:
- 5432
ports:
- '5432:5432'
env_file:
- .env.test
minio:
image: minio/minio
container_name: MinIO
Expand All @@ -21,21 +23,36 @@ services:
interval: 5s
timeout: 20s
retries: 3
env_file:
- .env.test
createbuckets:
image: minio/mc
container_name: MinIO_CreateBuckets
depends_on:
- minio
# To use Docker Compose's new --wait feature, we need every container to
# pass a healthcheck. Unfortunately this means keeping it this one alive for
# no reason. Probably a better way of doing this, though --wait is quite new
# and on_start may be coming soon, that'll replace this entire container.
healthcheck:
test: ['CMD', 'echo', 'im healthy!']
interval: 1s
timeout: 5s
retries: 3
entrypoint: >
/bin/bash -c " /usr/bin/mc alias set momentum_minio http://minio:9000
minio minio123; /usr/bin/mc mb momentum_minio/momtest --ignore-existing;
/usr/bin/mc anonymous set public momentum_minio/momtest; sleep infinity"
bash -c "
mc alias set momentum_minio http://minio:9000 minio minio123 &&
mc mb momentum_minio/momtest --ignore-existing &&
mc anonymous set public momentum_minio/momtest
"
e2e-tests:
platform: linux/x86_64
image: node:18-alpine
depends_on:
- minio
- db
- createbuckets
env_file:
- .env.test
working_dir: /app/
volumes:
- ./:/app/
ports:
- '3003'
command: >
sh -c "
apk add git &&
npx nx run db:push &&
npx nx affected --target=e2e --base=origin/main --parallel=1
"

0 comments on commit 104890d

Please sign in to comment.