From e5dfd6e8fa3d657393e6f00a500dfbd980f69a38 Mon Sep 17 00:00:00 2001 From: Severiano Badajoz Date: Wed, 15 Apr 2020 09:41:45 -0700 Subject: [PATCH] Add eslint steps to lint job (#1335) * add lint-client and lint-diff-client targets * add lint-diff and lint targets * prettier * add lint-diff call to lint task * temp * tweak lint-diff * add lint for PRs and lint for master * remove temp * remove incorrect branches syntax, use github_ref * pull all branches * format * proper target and comment * create separate steps with conditionals * fix indentation * refactor lint->lint-server, introduce lint to lint all * trade diff-index for diff, do check against base instead of master * remove fetching all branches * Revert "remove fetching all branches" This reverts commit 26ce7a0f05b1c787523fac2340f2f441d724e242. * tweak comparison * use local eslint * add eslint dep install * temp * grab only base * simplify fetch * add pull_request type trigger * specify pushes only to master * change conditionals to be based on event name * Revert "temp" This reverts commit 3d59134cc0f999f28f93add418db12e4d5e1a008. * "branch" => "branches" * create separate installation step * change command based on os --- .github/workflows/push_tests.yml | 198 +++++++++++++++++-------------- Makefile | 13 +- client/Makefile | 15 +++ 3 files changed, 139 insertions(+), 87 deletions(-) diff --git a/.github/workflows/push_tests.yml b/.github/workflows/push_tests.yml index 8bf8a943..1bb6a7ea 100644 --- a/.github/workflows/push_tests.yml +++ b/.github/workflows/push_tests.yml @@ -1,6 +1,9 @@ name: Push Tests -on: [push] +on: + push: + branches: master + pull_request: env: JEST_ENV: prod @@ -10,100 +13,123 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.7 - uses: actions/setup-python@v1 - with: - python-version: 3.7 - - name: Lint with flake8 - run: | - pip install flake8 - make lint + - uses: actions/checkout@v2 + - run: | + git fetch --depth=1 origin +${{github.base_ref}} + - name: Set up Python 3.7 + uses: actions/setup-python@v1 + with: + python-version: 3.7 + - name: Node cache + uses: actions/cache@v1 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - name: Install dependencies + run: | + pip install flake8 + cd client + npm i "eslint" "eslint-config-airbnb" "eslint-config-prettier" "eslint-loader" "eslint-plugin-filenames" "eslint-plugin-import" "eslint-plugin-jest" "eslint-plugin-jsx-a11y" "eslint-plugin-react" "eslint-plugin-react-hooks" + - name: Lint with flake8 + run: | + make lint-server + - name: Lint all with eslint + working-directory: ./client + if: github.event_name != 'pull_request' + run: | + make lint + - name: Lint diff with eslint + working-directory: ./client + if: github.event_name == 'pull_request' + run: | + make lint-diff unit-test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.7 - uses: actions/setup-python@v1 - with: - python-version: 3.7 - - name: Python cache - uses: actions/cache@v1 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - name: Node cache - uses: actions/cache@v1 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - name: Install dependencies - run: make pydist install-dist dev-env-server - - name: Unit tests - run: | - make unit-test - bash <(curl -s https://codecov.io/bash) -y .codecov.yml -k server -cF backend,python,unitTest - cd client && ./node_modules/codecov/bin/codecov --yml=../.codecov.yml --root=../ --gcov-root=../ -C -F frontend,javascript,unitTest + - uses: actions/checkout@v2 + - name: Set up Python 3.7 + uses: actions/setup-python@v1 + with: + python-version: 3.7 + - name: Python cache + uses: actions/cache@v1 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + - name: Node cache + uses: actions/cache@v1 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - name: Install dependencies + run: make pydist install-dist dev-env-server + - name: Unit tests + run: | + make unit-test + bash <(curl -s https://codecov.io/bash) -y .codecov.yml -k server -cF backend,python,unitTest + cd client && ./node_modules/codecov/bin/codecov --yml=../.codecov.yml --root=../ --gcov-root=../ -C -F frontend,javascript,unitTest smoke-tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.7 - uses: actions/setup-python@v1 - with: - python-version: 3.7 - - name: Python cache - uses: actions/cache@v1 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - name: Node cache - uses: actions/cache@v1 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - name: Install dependencies - run: make pydist install-dist - - name: Smoke tests (without annotations feature) - run: | - cd client && make smoke-test - ./node_modules/codecov/bin/codecov --yml=../.codecov.yml --root=../ --gcov-root=../ -C -F frontend,javascript,smokeTest + - uses: actions/checkout@v2 + - name: Set up Python 3.7 + uses: actions/setup-python@v1 + with: + python-version: 3.7 + - name: Python cache + uses: actions/cache@v1 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + - name: Node cache + uses: actions/cache@v1 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - name: Install dependencies + run: make pydist install-dist + - name: Smoke tests (without annotations feature) + run: | + cd client && make smoke-test + ./node_modules/codecov/bin/codecov --yml=../.codecov.yml --root=../ --gcov-root=../ -C -F frontend,javascript,smokeTest smoke-tests-annotations: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.7 - uses: actions/setup-python@v1 - with: - python-version: 3.7 - - name: Python cache - uses: actions/cache@v1 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - name: Node cache - uses: actions/cache@v1 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - name: Install dependencies - run: make pydist install-dist - - name: Smoke tests (with annotations feature) - run: | - cd client && make smoke-test-annotations - ./node_modules/codecov/bin/codecov --yml=../.codecov.yml --root=../ --gcov-root=../ -C -F frontend,javascript,smokeTestAnnotations + - uses: actions/checkout@v2 + - name: Set up Python 3.7 + uses: actions/setup-python@v1 + with: + python-version: 3.7 + - name: Python cache + uses: actions/cache@v1 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + - name: Node cache + uses: actions/cache@v1 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - name: Install dependencies + run: make pydist install-dist + - name: Smoke tests (with annotations feature) + run: | + cd client && make smoke-test-annotations + ./node_modules/codecov/bin/codecov --yml=../.codecov.yml --root=../ --gcov-root=../ -C -F frontend,javascript,smokeTestAnnotations diff --git a/Makefile b/Makefile index df2d8621..18ef2865 100644 --- a/Makefile +++ b/Makefile @@ -74,9 +74,20 @@ fmt-py: black . .PHONY: lint -lint: +lint: lint-server lint-client + +.PHONY: lint-server +lint-server: flake8 server +.PHONY: lint-client +lint-client: + cd client && $(MAKE) lint + +.PHONY: lint-diff-client +lint-diff-client: + cd client && $(MAKE) lint-diff + # CREATING DISTRIBUTION RELEASE diff --git a/client/Makefile b/client/Makefile index e3aa9d07..2093b60a 100644 --- a/client/Makefile +++ b/client/Makefile @@ -1,4 +1,8 @@ include ../common.mk +# https://stackoverflow.com/a/14777895/9587410 +ifeq ($(shell uname),Darwin) # is Windows_NT on XP, 2000, 7, Vista, 10... + IS_DARWIN := "true" +endif DATASET := $(if $(DATASET),$(DATASET),../example-dataset/pbmc3k.h5ad) ANNOTATIONS := $(if $(ANNOTATIONS),$(ANNOTATIONS),../server/test/test_datasets/pbmc3k-annotations.csv) @@ -21,6 +25,17 @@ install: build: npm run build +# Formatting code + +.PHONY: lint +lint: + npx eslint . + +.PHONY: lint-diff +lint-diff: +# Get client diff against master, find all js/jsx files, remove the client prefex, run eslinst against result + git diff --name-only --diff-filter=d origin/master...HEAD -- ../client/ | grep -E "(.*)\.(jsx|js)" | sed "s/client\///" | $(if $(IS_DARWIN),xargs ./node_modules/.bin/eslint,xargs -r ./node_modules/.bin/eslint) + # Development convenience methods