Skip to content

Commit

Permalink
Fix ci on merge (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
danishjoseph authored Apr 22, 2024
1 parent 5025b98 commit 96179bf
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 35 deletions.
55 changes: 29 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
name: CI

env:
NODE_VERSION: 18

on:
push:
branches: [main]
Expand All @@ -10,48 +14,46 @@ permissions:
pull-requests: write

jobs:
build:
test:
name: Unit tests & Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- 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'
Expand All @@ -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
Expand All @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion src/asset-management/services/asset-exchange.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/asset-management/services/asset.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/asset-management/services/trading-data.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/asset-management/utils/validate-dto-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`,
);
}
};
2 changes: 1 addition & 1 deletion src/data-sync/data-sync.module.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
10 changes: 7 additions & 3 deletions src/data-sync/data-sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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, {
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/data-sync/utils/validate-dto-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`,
);
}
};

0 comments on commit 96179bf

Please sign in to comment.