diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d15be5..f730f31 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,8 @@ name: CI + +env: + NODE_VERSION: 18 + on: push: branches: [main] @@ -10,7 +14,8 @@ permissions: pull-requests: write jobs: - build: + test: + name: Unit tests & Lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -18,40 +23,37 @@ jobs: - name: Set up NodeJS uses: actions/setup-node@v4 with: - node-version: 18 + node-version: ${{ env.NODE_VERSION }} + + - name: Install test dependencies + run: yarn install --production=false --only=dev - - name: Install dependencies - run: yarn install + - name: Lint code + run: yarn lint - - name: Run tests + - name: Run Unit tests run: yarn test --colors + build: + name: Build Docker image & save to artifact + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build Docker image run: | docker build -t stockdog:pr-${{ github.event.number }} . - docker save stockdog:pr-${{ github.event.number }} > stockdog-pr-${{ github.event.number }}.image.tar - - name: Save Docker image as artifact + - name: Save Docker image to artifact + if: success() && github.event_name == 'pull_request' + run: docker save stockdog:pr-${{ github.event.number }} > stockdog-pr-${{ github.event.number }}.image.tar + + - name: Upload Docker image to artifact uses: actions/upload-artifact@v4 with: name: docker-image path: stockdog-pr-${{ github.event.number }}.image.tar - - name: Comment PR - if: success() && github.event_name == 'pull_request' - uses: actions/github-script@v7 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - const artifactUrl = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`; - const message = `:sparkles: **Docker Image Artifact** :sparkles:\n\nYour Docker image artifact can be found at the following location:\n\n:point_right: [Click Here](${artifactUrl}) :point_left:\n\nHappy coding! :rocket:`; - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: message, - }); - push: needs: build if: github.event_name == 'push' && github.ref == 'refs/heads/main' @@ -63,10 +65,11 @@ jobs: uses: actions/download-artifact@v4 with: name: docker-image - path: stockdog-pr-${{ github.event.number }}.image.tar - name: Load Docker image - run: docker load < stockdog-pr-${{ github.event.number }}.image.tar + run: | + docker load < stockdog-pr-${{ github.event.number }}.image.tar + docker tag stockdog:pr-${{ github.event.number }} stockdog:alpha-${{ github.event.number }} - name: Login to DockerHub uses: docker/login-action@v3 @@ -75,12 +78,12 @@ jobs: password: ${{ secrets.DOCKER_HUB_TOKEN }} - name: Push Docker image - run: docker push ${{ secrets.DOCKER_HUB_USERNAME }}/stockdog:pr-${{ github.event.number }} + run: docker push ${{ secrets.DOCKER_HUB_USERNAME }}/stockdog:alpha-${{ github.event.number }} - name: Update image metadata uses: docker/metadata-action@v5 with: - images: ${{ secrets.DOCKER_HUB_USERNAME }}/stockdog:pr-${{ github.event.number }} + images: ${{ secrets.DOCKER_HUB_USERNAME }}/stockdog:alpha-${{ github.event.number }} tags: | type=sha labels: | diff --git a/src/asset-management/services/asset-exchange.service.ts b/src/asset-management/services/asset-exchange.service.ts index 66fa539..d76197e 100644 --- a/src/asset-management/services/asset-exchange.service.ts +++ b/src/asset-management/services/asset-exchange.service.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger } from '@nestjs/common'; +import { Injectable } from '@nestjs/common'; import { AssetExchangeRepository } from '../repositories'; import { Exchange } from '../types/interface'; import { Exchange as Ex } from '../types/enums'; diff --git a/src/asset-management/services/asset.service.ts b/src/asset-management/services/asset.service.ts index 3de69fa..f8606b5 100644 --- a/src/asset-management/services/asset.service.ts +++ b/src/asset-management/services/asset.service.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger } from '@nestjs/common'; +import { Injectable } from '@nestjs/common'; import { AssetExchangeRepository, AssetRepository } from '../repositories'; import { validateAndThrowError } from '../utils/validate-dto-error'; import { Asset, AssetExchange, Exchange } from '../entities'; diff --git a/src/asset-management/services/trading-data.service.ts b/src/asset-management/services/trading-data.service.ts index 46665d9..f3a9476 100644 --- a/src/asset-management/services/trading-data.service.ts +++ b/src/asset-management/services/trading-data.service.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger } from '@nestjs/common'; +import { Injectable } from '@nestjs/common'; import { TradingDataDTO } from '../dto'; import { TradingData } from '../entities'; import { TradingDataRepository } from '../repositories'; diff --git a/src/asset-management/utils/validate-dto-error.ts b/src/asset-management/utils/validate-dto-error.ts index 9f9a7a5..f8e3524 100644 --- a/src/asset-management/utils/validate-dto-error.ts +++ b/src/asset-management/utils/validate-dto-error.ts @@ -4,7 +4,7 @@ export const validateAndThrowError = async (dto, dtoName) => { const errors = await validate(dto); if (errors.length > 0) { throw new Error( - `Validation failed for ${dtoName} : ${JSON.stringify(errors)}` + `Validation failed for ${dtoName} : ${JSON.stringify(errors)}`, ); } }; diff --git a/src/data-sync/data-sync.module.ts b/src/data-sync/data-sync.module.ts index fb936d3..e1ab972 100644 --- a/src/data-sync/data-sync.module.ts +++ b/src/data-sync/data-sync.module.ts @@ -1,4 +1,4 @@ -import { Logger, Module } from '@nestjs/common'; +import { Module } from '@nestjs/common'; import { AssetManagementModule } from 'src/asset-management/asset-management.module'; import { DataSyncService } from './data-sync.service'; import { BseService } from './bse.service'; diff --git a/src/data-sync/data-sync.service.ts b/src/data-sync/data-sync.service.ts index f3d63d9..4782040 100644 --- a/src/data-sync/data-sync.service.ts +++ b/src/data-sync/data-sync.service.ts @@ -26,7 +26,7 @@ export class DataSyncService { }); await this.bseService.handleAssetData(response.data); } - + @Cron(CronExpression.EVERY_DAY_AT_MIDNIGHT) async handleDeliveryDataBSE(url: string, userAgent: string, referer: string) { this.logger.log('BSE Data Sync Started'); @@ -90,7 +90,9 @@ export class DataSyncService { }, }); - let assetResponseStream = Readable.from(JSON.stringify(assetResponse.data)); + const assetResponseStream = Readable.from( + JSON.stringify(assetResponse.data), + ); await this.nseService.handleAssetData(assetResponseStream); const tradeResponse = await axios.get(tradingURL, { @@ -101,7 +103,9 @@ export class DataSyncService { Referer: referer, }, }); - let tradeResponseStream = Readable.from(JSON.stringify(tradeResponse.data)); + const tradeResponseStream = Readable.from( + JSON.stringify(tradeResponse.data), + ); await this.nseService.handleTradingData(tradeResponseStream); } diff --git a/src/data-sync/utils/validate-dto-error.ts b/src/data-sync/utils/validate-dto-error.ts index 9f9a7a5..f8e3524 100644 --- a/src/data-sync/utils/validate-dto-error.ts +++ b/src/data-sync/utils/validate-dto-error.ts @@ -4,7 +4,7 @@ export const validateAndThrowError = async (dto, dtoName) => { const errors = await validate(dto); if (errors.length > 0) { throw new Error( - `Validation failed for ${dtoName} : ${JSON.stringify(errors)}` + `Validation failed for ${dtoName} : ${JSON.stringify(errors)}`, ); } };