Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nx CI #771

Merged
merged 6 commits into from
Jun 29, 2023
Merged

Nx CI #771

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
226 changes: 110 additions & 116 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,131 +1,125 @@
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
with:
fetch-depth: 0
- 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.base.sha }}
--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
build:
name: Build
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') }}
- run: git fetch --no-tags --prune --depth=1 origin main
- run: npx nx affected --target=build --base=origin/main --parallel=3
backend-e2e:
name: Backend E2E 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
- name: Check affected
run:
|
if npx nx show projects --affected | grep -q backend-e2e; then
echo "affected=true" >> $GITHUB_ENV
else
echo "affected=false" >> $GITHUB_ENV
fi
- name: Run tests in Docker
if: env.affected == 'true'
run:
docker compose
-f docker-compose.yml -f docker-compose.test.yml
run backend-e2e
frontend-e2e:
name: Frontend E2E Tests
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
- name: Check affected
run:
|
if npx nx show projects --affected | grep -q frontend-e2e; then
echo "affected=true" >> $GITHUB_ENV
else
echo "affected=false" >> $GITHUB_ENV
fi
- name: Run tests in Docker
if: env.affected == 'true'
run:
docker compose
-f docker-compose.yml -f docker-compose.test.yml
run frontend-e2e
5 changes: 4 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Add files here to ignore them from prettier formatting
/dist
/coverage
/data
.angular

# Prettier's YAML formatting is atrocious
**/*.yml
2 changes: 1 addition & 1 deletion apps/backend-e2e/src/user.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ describe('User', () => {
await req.patch({
url: 'user',
status: 204,
body: { countryCode: newCountryCode },
body: { country: newCountryCode },
token: token
});

Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
"maximumError": "5mb"
tsa96 marked this conversation as resolved.
Show resolved Hide resolved
},
{
"type": "anyComponentStyle",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ <h5>Alias</h5>

<div class="form-group">
<h5>Country</h5>
<nb-select
formControlName="country"
>
<nb-select formControlName="country">
<nb-option
*ngFor="let item of ISOCountryCode | keyvalue"
*ngFor="let item of AlphabeticalCountryCode | keyvalue"
[value]="item.key"
>{{ item.value }}</nb-option
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import { Bitflags } from '@momentum/bitflags';
styleUrls: ['./profile-edit.component.scss']
})
export class ProfileEditComponent implements OnInit, OnDestroy {
protected readonly ISOCountryCode = ISOCountryCode;
protected readonly AlphabeticalCountryCode = Object.fromEntries(
Object.entries(ISOCountryCode).sort(([_, a], [__, b]) => a.localeCompare(b))
);
private ngUnSub = new Subject<void>();

profileEditFormGroup: FormGroup = this.fb.group({
Expand Down
38 changes: 4 additions & 34 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ services:
# /usr/bin/mc rm -r --force momentum_minio/momtest;
entrypoint: >
/bin/sh -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;"
mc alias set momentum_minio http://minio:9000 minio minio123 &&
mc mb momentum_minio/momtest --ignore-existing &&
mc anonymous set public momentum_minio/momtest
"
db:
platform: linux/x86_64
env_file:
Expand All @@ -46,34 +47,3 @@ services:
- ${POSTGRES_PORT}:${POSTGRES_PORT}
volumes:
- ./data/postgres:/var/lib/postgresql/data
# Here we use the profiles feature to only load the API with Docker if
# launching with `--profile full`. This allows developers choose between
# running the Nest API in Docker (great for frontend-only dev) and running
# it natively, using a single command line option. Note we must construct
# the DATABASE_URL from other env variables in this mode, overriding whatever
# is in .env - we want to name it `db` in full mode so it's only exposed to
# the internal network.
api:
platform: linux/x86_64
image: node:18
depends_on:
- minio
profiles:
- full
env_file:
- .env
environment:
IS_DOCKERIZED_API: 'true'
DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db/${POSTGRES_DB}?schema=public
working_dir: /app/server
volumes:
- ./server:/app/server
- /app/server/node_modules/
ports:
- '9229:9229' # For Node debugging
- ${NODE_PORT}:${NODE_PORT}
expose:
- ${NODE_PORT}
command: >
sh -c "npm install &&
npm run ${CMD:-start:push}"
Loading