Skip to content

Commit

Permalink
ci: setup backend actions
Browse files Browse the repository at this point in the history
  • Loading branch information
neuodev committed Nov 30, 2024
1 parent 23b9e70 commit 1eb3fd7
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 23 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Backend
on:
pull_request:
branches:
- "master"
paths:
- "packages/auth/**"
- "packages/models/**"
- "packages/atlas/**"
- "services/server/**"

workflow_dispatch:

# @ref https://docs.github.com/en/actions/use-cases-and-examples/using-containerized-services/creating-postgresql-service-containers
jobs:
main:
runs-on: ubuntu-latest
container: node:20-bookworm-slim
services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: litespace
POSTGRES_DB: test
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "20.11.1"
- name: Enable pnpm
run: corepack enable pnpm
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install
- name: Build packages
run: pnpm build:server:pkgs
- name: Run models tests
run: pnpm models test:ci
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
"license": "MIT",
"private": true,
"scripts": {
"build:pkg:assets": "pnpm --filter @litespace/assets build",
"build:pkg:atlas": "pnpm --filter @litespace/atlas build",
"build:pkg:auth": "pnpm --filter @litespace/auth build",
"build:pkg:emails": "pnpm --filter @litespace/emails build",
"build:pkg:luna": "pnpm --filter @litespace/luna build",
"build:pkg:models": "pnpm --filter @litespace/models build",
"build:pkg:sol": "pnpm --filter @litespace/sol build",
"build:pkg:types": "pnpm --filter @litespace/types build",
"build:pkg:headless": "pnpm --filter @litespace/headless build",
"build:pkg:assets": "pnpm assets build",
"build:pkg:atlas": "pnpm atlas build",
"build:pkg:auth": "pnpm auth build",
"build:pkg:emails": "pnpm emails build",
"build:pkg:luna": "pnpm luna build",
"build:pkg:models": "pnpm models build",
"build:pkg:sol": "pnpm sol build",
"build:pkg:types": "pnpm types build",
"build:pkg:headless": "pnpm headless build",
"build:pkgs": "pnpm build:pkg:assets && pnpm build:pkg:types && pnpm build:pkg:sol && pnpm build:pkg:emails && pnpm build:pkg:models && pnpm build:pkg:atlas && pnpm build:pkg:headless && pnpm build:pkg:auth && pnpm build:pkg:luna",
"build:server:pkgs": "pnpm build:pkg:types && pnpm build:pkg:sol && pnpm build:pkg:emails && pnpm build:pkg:models && pnpm build:pkg:atlas && pnpm build:pkg:auth",
"watch:atlas": "pnpm build:pkg:atlas -w",
"watch:auth": "pnpm auth watch",
"watch:emails": "pnpm emails watch",
Expand Down
6 changes: 6 additions & 0 deletions packages/models/.env.test.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DATABASE_URL=postgres://postgres:litespace@postgres:5432/test
PG_USER='postgres'
PG_PASSWORD='litespace'
PG_HOST='postgres'
PG_PORT='5432'
PG_DATABASE='test'
10 changes: 8 additions & 2 deletions packages/models/fixtures/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ async function execute(command: string): Promise<string> {
});
}

const ci = !!process.env.CI;

export async function down() {
await execute("pnpm migrate:test down");
const command = ci
? "pnpm migrate:test:ci down"
: "pnpm migrate:test:local down";
await execute(command);
}

export async function up() {
await execute("pnpm migrate:test up");
const command = ci ? "pnpm migrate:test:ci up" : "pnpm migrate:test:local up";
await execute(command);
}
9 changes: 6 additions & 3 deletions packages/models/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@
"build": "rollup -c --bundleConfigAsCjs",
"watch": "pnpm build -w",
"migrate": "env-cmd -f .env node-pg-migrate",
"migrate:test": "env-cmd -f .env.test node-pg-migrate",
"migrate:test:local": "env-cmd -f .env.test node-pg-migrate",
"migrate:test:ci": "env-cmd -f .env.test.ci node-pg-migrate",
"seed": "env-cmd -f .env vite-node scripts/seed.ts",
"reseed": "pnpm migrate down && pnpm migrate up && pnpm seed",
"test": "env-cmd -f .env.test jest -i --runInBand --detectOpenHandles"
"test": "jest --runInBand --detectOpenHandles --forceExit",
"test:local": "env-cmd -f .env.test pnpm run test",
"test:ci": "env-cmd -f .env.test.ci pnpm run test"
},
"devDependencies": {
"@litespace/models": "workspace:^",
"@litespace/sol": "workspace:^",
"@faker-js/faker": "^9.0.3",
"@jest/globals": "^29.7.0",
"@litespace/sol": "workspace:^",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-commonjs": "^25.0.8",
"@rollup/plugin-json": "^6.1.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/models/tests/calls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import dayjs from "@/lib/dayjs";

describe(nameof(Calls), () => {
beforeEach(async () => {
await flush();
return await flush();
});

describe(nameof(calls.create), () => {
it("should insert new call row", async () => {
const call = await calls.create();
expect(call.id).to.be.eq(1);
expect(dayjs.utc(call.createdAt).isValid()).to.be.true;
expect(dayjs.utc(call.updatedAt).isValid()).to.be.true;
expect(call.processingTime).to.be.eq(null);
Expand Down
2 changes: 1 addition & 1 deletion packages/models/tests/interviews.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { expect } from "chai";

describe("Interviews", () => {
beforeEach(async () => {
await fixtures.flush();
return await fixtures.flush();
});

describe(nameof(interviews.find), () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/models/tests/lessons.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import dayjs from "@/lib/dayjs";

describe("Lessons", () => {
beforeEach(async () => {
await fixtures.flush();
return await fixtures.flush();
});

describe(nameof(lessons.countCounterpartMembers), () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/models/tests/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { expect } from "chai";

describe("Messages", () => {
beforeEach(async () => {
await fixtures.flush();
return await fixtures.flush();
});

describe(nameof(messages.countUserMessages), () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/models/tests/ratings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { expect } from "chai";

describe("Ratings", () => {
beforeEach(async () => {
await fixtures.flush();
return await fixtures.flush();
});

describe(nameof(ratings.create), () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/models/tests/rooms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IUser } from "@litespace/types";

describe("Rooms", () => {
beforeEach(async () => {
await fixtures.flush();
return await fixtures.flush();
});

describe(nameof(rooms.create), () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/models/tests/topics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import dayjs from "@/lib/dayjs";

describe("Topics", () => {
beforeEach(async () => {
await fixtures.flush();
return await fixtures.flush();
});

describe(nameof(topics.create), () => {
Expand Down
1 change: 0 additions & 1 deletion packages/models/tests/users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ describe("Users", () => {
gender: IUser.Gender.Male,
});

expect(user.id).to.be.eq(1);
expect(user.name).to.be.eq(name);
expect(user.role).to.be.eq(IUser.Role.Student);
expect(user.gender).to.be.eq(IUser.Gender.Male);
Expand Down

0 comments on commit 1eb3fd7

Please sign in to comment.