Просмотр исходного кода

Add GitHub Workflow action for code validation

The source code is validated by running the action on pull requests to
master.

The validations steps are:
- Typescript, Eslint and Prettiers checks;
- Unit tests;
- Production build;
Sergiu Miclea 3 лет назад
Родитель
Сommit
265079fa84
3 измененных файлов с 44 добавлено и 19 удалено
  1. 0 17
      .githooks/pre-commit
  2. 42 0
      .github/workflows/build.yml
  3. 2 2
      package.json

+ 0 - 17
.githooks/pre-commit

@@ -1,17 +0,0 @@
-#!/bin/sh
-
-# Run this command after repo checkout to enable git hooks
-# git config core.hooksPath .githooks
-
-printf "\nRunning TSC:\n"
-
-PATH=$PATH:/usr/local/bin:/usr/local/sbin
-
-yarn tsc
-
-if [[ "$?" == 0 ]]; then
-  printf "\t\033[32mTSC Passed \e[0m"
-else
-  printf "\t\033[41mTSC Failed \e[0m"
-  exit 1
-fi

+ 42 - 0
.github/workflows/build.yml

@@ -0,0 +1,42 @@
+name: Build and Test
+
+on:
+  pull_request:
+    branches: [ master ]
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/checkout@v3
+
+    - name: Setup Node.js
+      uses: actions/setup-node@v1
+      with:
+        node-version: 16.x
+
+    - name: Install yarn
+      run: npm install -g yarn
+
+    - name: Install dependencies
+      run: yarn install
+
+    - name: Check Typescript
+      run: yarn tsc
+
+    - name: Check ESLint
+      run: yarn eslint
+
+    - name: Check Prettier
+      run: yarn format
+
+    - name: Run unit tests
+      run: yarn test
+
+    - name: Install production dependencies
+      run: |
+        rm -rf node_modules
+        yarn install --production
+
+    - name: Build
+      run: yarn build

+ 2 - 2
package.json

@@ -12,8 +12,8 @@
     "server-dev": "nodemon -e ts,js -w server/**/ -w .env",
     "server-debug": "node --inspect server",
     "tsc": "npx tsc --skipLibCheck",
-    "eslint": "npx eslint \"src/**\" \"server/**\" --fix",
-    "format": "prettier --write src/**/*.{js,jsx,ts,tsx,css,md,json} --config ./.prettierrc",
+    "eslint": "npx eslint \"src/**\" \"server/**\"",
+    "format": "prettier --check src/**/*.{js,jsx,ts,tsx,css,md,json} --config ./.prettierrc",
     "test": "jest",
     "test-release": "node ./tests/testRelease",
     "test-coverage": "node ./tests/testCoverage",