Skip to content

Commit

Permalink
Add ci (#120)
Browse files Browse the repository at this point in the history
* Initialise CI workflow

* Amend CI workflow

* Fix linting and add backend CI workflow
  • Loading branch information
Jajared authored Nov 10, 2024
1 parent c474b3f commit 95cbc6f
Show file tree
Hide file tree
Showing 38 changed files with 178 additions and 220 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/backend-ci-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Backend CI Workflow

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'

- name: Install Dependencies for Each Service
run: |
cd backend
for service in auth-service question-service user-service matching-service gateway-service collaboration-service; do
echo "Installing dependencies for $service"
cd $service
npm install
cd ..
done
# Build Check for Each Service
- name: Build Each Service
run: |
cd backend
for service in auth-service question-service user-service matching-service gateway-service collaboration-service; do
echo "Building $service"
cd $service
npm run build
cd ..
done
# Lint Check for Each Service
- name: Lint Each Service
run: |
cd backend
for service in auth-service question-service user-service matching-service gateway-service collaboration-service; do
echo "Linting $service"
cd $service
npm run lint
cd ..
done
38 changes: 38 additions & 0 deletions .github/workflows/frontend-ci-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Frontend CI Workflow

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'

- name: Install Dependencies
run: |
cd frontend
npm install
# Build Check
- name: Build Project
run: |
cd frontend
npm run build
# Lint Check
- name: Lint Code
run: |
cd frontend
npm run lint
31 changes: 0 additions & 31 deletions backend/.github/workflows/backend-docker-compose.yml

This file was deleted.

17 changes: 0 additions & 17 deletions backend/auth-service/src/app.controller.spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion backend/auth-service/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AppController } from './app.controller';
import { AppService } from './app.service';
import { PassportModule } from '@nestjs/passport';
import { JwtModule } from '@nestjs/jwt';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { ClientsModule } from '@nestjs/microservices';
import { HttpModule } from '@nestjs/axios';
import {
AccessTokenStrategy,
Expand Down
7 changes: 5 additions & 2 deletions backend/auth-service/src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export class AppService {
}

public async resetPassword(dto: ResetPasswordDto): Promise<boolean> {
const { userId, email } = await this.validatePasswordResetToken(dto.token);
const { userId } = await this.validatePasswordResetToken(dto.token);

const hashedPassword = await bcrypt.hash(dto.password, SALT_ROUNDS);

Expand Down Expand Up @@ -218,6 +218,7 @@ export class AppService {
}
return { userId, email };
} catch (err) {
console.error(err);
throw new RpcException({
statusCode: HttpStatus.UNAUTHORIZED,
message: 'Unauthorized: Invalid or expired password reset token',
Expand Down Expand Up @@ -246,7 +247,7 @@ export class AppService {
text: `Click here to reset your password: ${resetUrl}`,
};

transporter.sendMail(mailOptions, (error, info) => {
transporter.sendMail(mailOptions, (error) => {
if (error) {
throw new RpcException(`Error sending reset email: ${error.message}`);
}
Expand All @@ -260,6 +261,7 @@ export class AppService {
});
return decoded;
} catch (error) {
console.error(error);
throw new RpcException('Invalid access token');
}
}
Expand All @@ -271,6 +273,7 @@ export class AppService {
});
return decoded;
} catch (error) {
console.error(error);
throw new RpcException('Invalid Refresh Token');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export enum AccountProvider {
LOCAL = 'local',
GOOGLE = 'google',
GITHUB = 'github',
}
}
2 changes: 1 addition & 1 deletion backend/auth-service/src/dto/reset-password-request.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';
import { IsEmail, IsNotEmpty } from 'class-validator';

export class ResetPasswordRequestDto {
@IsEmail()
Expand Down
2 changes: 1 addition & 1 deletion backend/auth-service/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { MicroserviceOptions } from '@nestjs/microservices';
import { ValidationPipe } from '@nestjs/common';
import { config } from 'src/configs';
import * as dotenv from 'dotenv';
Expand Down
2 changes: 1 addition & 1 deletion backend/collaboration-service/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Get } from '@nestjs/common';
import { Controller } from '@nestjs/common';
import { AppService } from './app.service';
import { MessagePattern, Payload } from '@nestjs/microservices';
import { CreateSessionDto } from './dto';
Expand Down
2 changes: 1 addition & 1 deletion backend/gateway-service/src/common/configs/env.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RpcException, Transport } from '@nestjs/microservices';
import { Transport } from '@nestjs/microservices';
import * as dotenv from 'dotenv';

dotenv.config();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export enum AccountProvider {
LOCAL = 'local',
GOOGLE = 'google',
GITHUB = 'github',
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export enum Languages {
PYTHON = 'Python',
JAVA = 'Java',
CPLUSPLUS = 'C++',
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export enum Proficiency {
BEGINNER = 'Beginner',
INTERMEDIATE = 'Intermediate',
ADVANCED = 'Advanced',
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ export const GetCurrentUserId = createParamDecorator(
}
},
); */

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';
import { IsEmail, IsNotEmpty } from 'class-validator';

export class ResetPasswordRequestDto {
@ApiProperty({
Expand All @@ -8,5 +8,4 @@ export class ResetPasswordRequestDto {
@IsEmail()
@IsNotEmpty()
email: string;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { Type } from 'class-transformer';
import { IsArray, IsIn, IsNotEmpty, IsString } from 'class-validator';

export class UserMatchOptionsDto {

@IsString()
userId: string;

@ApiProperty({
description: 'Either Easy, Medium, or Hard',
example: 'Easy',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { ClientProxy } from '@nestjs/microservices';
import { Inject } from '@nestjs/common';
import { firstValueFrom } from 'rxjs';
import { RedisMatchService } from './redis.service';
import { v4 as uuidv4 } from 'uuid';
import { MatchAcceptDto, MatchDeclineDto, MatchRequestDto } from './dto';
import {
MATCH_FOUND,
Expand Down
8 changes: 5 additions & 3 deletions backend/gateway-service/src/modules/match/redis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class RedisMatchService {

// Subscribe to the Redis Pub/Sub channel for match events
subscribeToMatchEvents(callback: (matchedUsers: any) => void): void {
this.redisSubscriber.subscribe('matchChannel', (err, count) => {
this.redisSubscriber.subscribe('matchChannel', (err) => {
if (err) {
console.error('Error subscribing to Redis channel:', err);
return;
Expand All @@ -35,11 +35,13 @@ export class RedisMatchService {
matchId: parsedMessage.matchId,
matchedUserIds: parsedMessage.matchedUserIds,
});
}}});
}
}
});
}

subscribeToTimeoutEvents(callback: (matchedUsers: any) => void): void {
this.redisSubscriber.subscribe('timeoutChannel', (err, count) => {
this.redisSubscriber.subscribe('timeoutChannel', (err) => {
if (err) {
console.error('Error subscribing to Redis channel:', err);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
import {
CreateQuestionDto,
FindQuestionByIdDto,
FindQuestionBySlugDto,
GetQuestionsDto,
UpdateQuestionDto,
} from './dto';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Exclude, Expose, Transform } from 'class-transformer';
import { Exclude } from 'class-transformer';

export class UsersResponseDto {
@Exclude()
Expand Down
16 changes: 0 additions & 16 deletions backend/matching-service/src/app.controller.spec.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export interface MatchDetails {
score: number;
generatedTopics: string[];
generatedDifficulty: string;
selectedQuestionId: string
selectedQuestionId: string;
}
23 changes: 16 additions & 7 deletions backend/matching-service/src/services/redis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ export class RedisService {
}
}

async publishMatchedUsers(matchId: string, matchedUserIds: string[]): Promise<void> {
async publishMatchedUsers(
matchId: string,
matchedUserIds: string[],
): Promise<void> {
const message = {
matchId: matchId,
matchedUserIds: matchedUserIds,
};
await this.redisPublisher.publish(
'matchChannel',
JSON.stringify(message),
);
await this.redisPublisher.publish('matchChannel', JSON.stringify(message));
}

async publishTimedOutUsers(timedOutUserIds: string[]): Promise<void> {
Expand All @@ -126,8 +126,17 @@ export class RedisService {
return users.map((user) => JSON.parse(user));
}

async storeMatch(matchId: string, matchData: MatchDetails, ttl: number = 1000): Promise<void> {
await this.redisPublisher.set(matchId, JSON.stringify(matchData), 'EX', ttl);
async storeMatch(
matchId: string,
matchData: MatchDetails,
ttl: number = 1000,
): Promise<void> {
await this.redisPublisher.set(
matchId,
JSON.stringify(matchData),
'EX',
ttl,
);
}

async getMatch(matchId: string): Promise<MatchDetails | null> {
Expand Down
Loading

0 comments on commit 95cbc6f

Please sign in to comment.