Skip to content

Commit

Permalink
fix workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
SkidGod4444 committed Nov 25, 2024
1 parent 8b29d14 commit 20c08e1
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-triggers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
env:
TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }}
run: |
npx trigger.dev@latest deploy
pnpm dlx trigger.dev@latest deploy
6 changes: 0 additions & 6 deletions .github/workflows/format-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
push:
branches:
- main
- 'feat/*'
- 'bugfix/*'
pull_request:
branches:
- main
Expand Down Expand Up @@ -52,10 +50,6 @@ jobs:
echo "formatting_required=true" >> $GITHUB_ENV
fi
- name: Format code with Prettier if needed
if: env.formatting_required == 'true'
run: pnpm format:write

- name: Check for changes and push if needed
run: |
if [ -n "$(git status --porcelain)" ]; then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
name: Lint and Test
name: Lint and Type Check

on:
push:
branches:
- main
- 'feat/*'
- 'bugfix/*'
pull_request:
branches:
- main
Expand All @@ -27,6 +25,9 @@ jobs:
- name: Install pnpm
run: npm install -g pnpm

- name: Install turbo
run: pnpm install -g turbo

- name: Cache pnpm modules
uses: actions/cache@v3
with:
Expand All @@ -36,7 +37,7 @@ jobs:
${{ runner.os }}-pnpm-
- name: Install dependencies
run: pnpm install --shamefully-hoist
run: pnpm install

lint:
runs-on: ubuntu-latest
Expand All @@ -45,39 +46,31 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js (again to ensure pnpm is available)
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '21.7.1'

- name: Install pnpm (again in case the previous job isolated the environment)
run: npm install -g pnpm

- name: Install Turbo CLI
run: npm install -g turbo
- name: Use pnpm & turbo from setup
run: pnpm --version && turbo --version

- name: Run Lint
run: pnpm lint

test:
type-check:
runs-on: ubuntu-latest
needs: [setup, lint]
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
RESEND_API: ${{ secrets.RESEND_API }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up .env file for tests
run: |
echo "DATABASE_URL=${{ secrets.DATABASE_URL }}" >> apps/api/.env
echo "RESEND_API=${{ secrets.RESEND_API }}" >> apps/api/.env
- name: Set up Node.js (again to ensure pnpm is available)
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '21.7.1'

- name: Run Tests
run: pnpm test
- name: Use turbo from setup
run: turbo --version

- name: Run Type Check
run: turbo typecheck
47 changes: 21 additions & 26 deletions .github/workflows/test-multiple-node-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
push:
branches:
- main
- 'feat/*'
- 'bugfix/*'
pull_request:
branches:
- main
Expand All @@ -15,35 +13,37 @@ on:
jobs:
test:
runs-on: ubuntu-latest
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
RESEND_API: ${{ secrets.RESEND_API }}
strategy:
matrix:
node-version: [20.18.0, 18.20.4, 22.11.0, 19.9.0, 23.1.0] # Ensure all versions are >= v18
node-version: [20.18.0, 18.20.4, 22.11.0, 19.9.0, 23.1.0] # Ensure all versions are >= v18

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up .env file for tests in apps/api
run: |
echo "DATABASE_URL=${{ secrets.DATABASE_URL }}" >> apps/api/.env
echo "RESEND_API=${{ secrets.RESEND_API }}" >> apps/api/.env
- name: Set environment variables for vitest in apps/api
run: |
echo "RESEND_API=${{ secrets.RESEND_API }}" >> apps/api/.env
echo "DATABASE_URL=${{ secrets.DATABASE_URL }}" >> apps/api/.env
cat apps/api/.env # Add this line to log and verify env variables
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Install pnpm
run: npm install -g pnpm
- name: Set environment variables
run: |
echo "DATABASE_URL=${{ secrets.DATABASE_URL }}" >> $GITHUB_ENV
echo "RESEND_API=${{ secrets.RESEND_API }}" >> $GITHUB_ENV
- name: Log environment variables (debug)
run: |
echo "DATABASE_URL=$DATABASE_URL"
echo "RESEND_API=$RESEND_API"
- name: Set up .env file for tests in apps/api
run: |
echo "DATABASE_URL=${{ secrets.DATABASE_URL }}" >> apps/api/.env
echo "RESEND_API=${{ secrets.RESEND_API }}" >> apps/api/.env
cat apps/api/.env # Verify .env contents
- name: Install pnpm & turbo
run: npm install -g pnpm && pnpm install -g turbo

- name: Cache pnpm modules
uses: actions/cache@v3
Expand All @@ -56,10 +56,5 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Log environment variables for verification (debug)
run: |
echo "DATABASE_URL=$DATABASE_URL"
echo "RESEND_API=$RESEND_API"
- name: Run tests
run: pnpm test
- name: Run Turbo tests
run: turbo test
23 changes: 5 additions & 18 deletions apps/api/tests/hello.test.ts → apps/api/__tests__/db.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { GET, POST, PATCH, DELETE } from "../app/api/[[...route]]/route";
import { prisma } from "@repo/db";
import { DELETE, GET, PATCH, POST } from "@/app/api/[[...route]]/route";

vi.mock("@repo/db", () => ({
prisma: {
Expand All @@ -18,7 +18,7 @@ describe("API Routes", () => {
vi.clearAllMocks();
});

it("POST http:/localhost:3000/api/hello should create a new user", async () => {
it("POST /api/hello should create a new user", async () => {
// Mock the response of prisma.user.create
const newUser = { id: "123", name: "New User" };
prisma.user.create.mockResolvedValue(newUser);
Expand All @@ -34,7 +34,7 @@ describe("API Routes", () => {
expect(json.test).toEqual(newUser);
});

it("GET http:/localhost:3000/api/hello should return users", async () => {
it("GET /api/hello should return users", async () => {
// Mock the response of prisma.user.findMany
const mockUsers = [{ id: "123", name: "New User" }];
prisma.user.findMany.mockResolvedValue(mockUsers);
Expand All @@ -49,7 +49,7 @@ describe("API Routes", () => {
expect(json.test).toEqual(mockUsers);
});

it("PATCH http:/localhost:3000/api/hello should update the user name", async () => {
it("PATCH /api/hello should update the user name", async () => {
// Mock the response of prisma.user.update
const updatedUser = { id: "123", name: "Updated User" };
prisma.user.update.mockResolvedValue(updatedUser);
Expand All @@ -65,7 +65,7 @@ describe("API Routes", () => {
expect(json.test).toEqual(updatedUser);
});

it("DELETE http:/localhost:3000/api/hello should delete the user", async () => {
it("DELETE /api/hello should delete the user", async () => {
// Mock the response of prisma.user.delete
const deletedUser = { id: "2", name: "Deleted User" };
prisma.user.delete.mockResolvedValue(deletedUser);
Expand All @@ -80,17 +80,4 @@ describe("API Routes", () => {
expect(json.test).toEqual(deletedUser);
});

it("GET /api/health should return health status", async () => {
const req = new Request("http:/localhost:3000/api/health", {
method: "GET",
});
const res = await GET(req);

expect(res.status).toBe(200);
const json = await res.json();
expect(json).toEqual({
message: "i am alive",
status: 200,
});
});
});
18 changes: 18 additions & 0 deletions apps/api/__tests__/health.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { GET } from "@/app/api/[[...route]]/route";
import { describe, it, expect } from "vitest";

describe("Health API", () => {
it("GET /api/health should return health status", async () => {
const req = new Request("http://localhost:3000/api/health", {
method: "GET",
});
const res = await GET(req);

expect(res.status).toBe(200);
const json = await res.json();
expect(json).toEqual({
message: "i am alive",
status: 200,
});
});
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"lint": "turbo run lint --force",
"lint:fix": "turbo run lint:fix",
"test": "turbo run test --force",
"typecheck": "turbo run typecheck",
"format:write": "turbo run format:write",
"format:check": "turbo run format:check"
},
Expand Down

0 comments on commit 20c08e1

Please sign in to comment.