Skip to content

Commit

Permalink
👷 Merge CI scripts
Browse files Browse the repository at this point in the history
- trigger: PR(open,reopen,sync) to ["develop","main"]
- check list: lint > test > static analysis
  • Loading branch information
ninthsun91 committed Jul 7, 2023
1 parent e01e775 commit 1fa2060
Show file tree
Hide file tree
Showing 12 changed files with 812 additions and 1,640 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.export = {
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: "latest",
project: process.env.ESLINT_PROJECT_PATH,
project: __dirname + "/tsconfig.json",
tsconfigRootDir: "./",
sourceType: "module",
},
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/aws-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ on:
# branches:
# - 'feature/'
push:
branches:
- main
branches: ["develop"]
# pull_request:
# types: [opened, reopened, synchronize]
# branches: ["develop"]

# concurrency will check if any dulpicated task is running and cancel the task
concurrency:
Expand Down
Empty file added .github/workflows/cd-dev.yml
Empty file.
Empty file added .github/workflows/cd-prod.yml
Empty file.
119 changes: 119 additions & 0 deletions .github/workflows/ci-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: CI - dev

on:
pull_request:
types: [opened, reopened, synchronize]
branches: ["develop"]

jobs:
Lint:
name: check-lint

runs-on: ubuntu-latest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

steps:
- name: Checkout repository
uses: actions/checkout@v3

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

- name: Install dependencies
run: |
npm install -g pnpm
pnpm install --frozen-lockfile
- name: Run lint
run: pnpm lint

- name: Notify Slack if error exists
if: ${{ failure() }}
uses: act10ns/slack@v1
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
channel: '#ci'

- name: Block merge if error exists
if: ${{ failure() }}
run: |
echo "Lint error found!!"
echo "Please fix them before merging."
exit 1
Test:
name: check-test
# needs: Lint

permissions: write-all
runs-on: ubuntu-latest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
DATABASE_URL: ${{ secrets.DEV_DATABASE_URL }}
API_VERSION: ${{ secrets.API_VERSION }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
JWT_EXPIRES_IN: ${{ secrets.JWT_EXPIRES_IN }}
MIN_COOKING_TIME: ${{ secrets.MIN_COOKING_TIME }}
MAX_COOKING_TIME: ${{ secrets.MAX_COOKING_TIME }}
BUSINESS_NUMBER_CHECK_API_KEY: ${{ secrets.BUSINESS_NUMBER_CHECK_API_KEY }}

steps:
- name: Checkout repository
uses: actions/checkout@v3

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

- name: Setup datatabase with docker compose
run: |
docker-compose up -d
- name: Install dependencies
run: |
npm install -g pnpm
npm install -g dotenv-cli
pnpm install --frozen-lockfile
npx prisma migrate
npx prisma generate
- name: Run test
run: pnpm test:report

- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: JEST Tests
path: reports/jest-junit.xml
reporter: jest-junit

- name: Notify slack if fails
if: ${{ failure() }}
uses: act10ns/slack@v1
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
channel: '#ci'

Analysis:
name: Static Analysis
# needs: [Lint, Test]

runs-on: ubuntu-latest

steps:
- name: Analyze with SonarCloud
uses: SonarSource/sonarcloud-github-action@de2e56b42aa84d0b1c5b622644ac17e505c9a049
env:
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args:
-Dsonar.projectKey=tdd-delivery_tdd-delivery
-Dsonar.organization=tdd-delivery
2 changes: 1 addition & 1 deletion .github/workflows/ci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Server CI - run e2e test
on:
pull_request:
types: [opened, reopened, synchronize]
branches: ["develop"]
branches: ["none"]

jobs:
lint:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name : FoodDeliverySystem develop 배포
on :
pull_request :
branches :
- develop
- none
types: [opened, reopened, synchronize]

jobs :
Expand All @@ -12,7 +12,7 @@ jobs :
steps :
- uses : actions/checkout@v2
- run : npm install -g pnpm
- run : pnpm i
- run : pnpm install --frozen-lockfile
- run : pnpm test:report

- name : Test Report
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: SonarCloud analysis
on:
pull_request:
types : [opened, reopened, synchronize]
branches: [ "main", "dev" ]
branches: [ "none" ]
workflow_dispatch:

permissions:
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ FROM base AS deploy
WORKDIR /home/app
COPY --from=build /home/app/dist ./dist
COPY --from=build /home/app/node_modules ./node_modules
COPY --from=build /home/app/.env ./.env
COPY --from=build /home/app/.env.test ./.env.test
# COPY --from=build /home/app/.env ./.env
# COPY --from=build /home/app/.env.test ./.env.test

CMD ["node", "dist/main.js"]
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"test:migrate": "dotenv -e \".env.test\" -- npx prisma migrate deploy",
"test:report": "pnpm test:migrate && jest --ci --reporters=default --reporters=jest-Junit",
"test:report": "pnpm test:migrate && jest --ci --reporters=default --reporters=jest-junit",
"prepare": "ts-patch install"
},
"dependencies": {
Expand Down Expand Up @@ -93,6 +93,10 @@
"moduleNameMapper": {
"src/(.*)$": "<rootDir>/../src/$1"
},
"reporters": [
"default",
"jest-junit"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
Expand Down
Loading

0 comments on commit 1fa2060

Please sign in to comment.