From 6b93611edb9412d03af82d96acf7e9873a0973bd Mon Sep 17 00:00:00 2001 From: Tan Yi Guan Date: Wed, 26 Oct 2022 00:50:48 +0800 Subject: [PATCH] [#11564] Linting should be skipped forgenerated files during local buildand test (#11910) * Fix lint:css issue * Update lint:spaces to ignore build files * Update linting to use git diff * update linting routine to be ran as pre-commit hook * improve linting on github actions * modify git diff command to work on github actions * add fetch-depth flag to actions/checkout * remove trailing space * remove pre-commit hook Co-authored-by: Nicolas Chang Weng Yew Co-authored-by: Zhao Jingjing <54243224+zhaojj2209@users.noreply.github.com> --- .github/workflows/component.yml | 54 ++++++++++++++++++++++----------- .gitignore | 2 ++ package-lock.json | 6 ++++ package.json | 12 +++++--- 4 files changed, 52 insertions(+), 22 deletions(-) diff --git a/.github/workflows/component.yml b/.github/workflows/component.yml index a0e13129567..cdade37b9fe 100644 --- a/.github/workflows/component.yml +++ b/.github/workflows/component.yml @@ -3,11 +3,11 @@ name: Component Tests on: push: branches: - - master + - master - release pull_request: branches: - - master + - master - release schedule: - cron: "0 0 * * *" #end of every day @@ -16,10 +16,12 @@ jobs: strategy: fail-fast: false #ensure both tests run even if one fails matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 + with: + fetch-depth: '0' - name: Set up JDK 11 uses: actions/setup-java@v1 with: @@ -33,17 +35,33 @@ jobs: key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} restore-keys: | ${{ runner.os }}-gradle- - - name: Run Backend Linting - run: ./gradlew lint --continue + - name: Cache eslint + uses: actions/cache@v2 + with: + path: | + ./.eslintcache + key: ${{ runner.os }}-eslint-${{ hashFiles('.eslintcache') }} + restore-keys: | + ${{ runner.os }}-eslint- + - name: Cache stylelint + uses: actions/cache@v2 + with: + path: | + ./.stylelintcache + key: ${{ runner.os }}-stylelint-${{ hashFiles('.stylelintcache') }} + restore-keys: | + ${{ runner.os }}-stylelint- + - name: Run Backend Linting + run: ./gradlew lint --continue - name: Install Frontend Dependencies - run: npm ci - - name: Run Lint Checks - run: npm run lint + run: npm ci + - name: Run Lint Checks + run: npm run lint component-testing: strategy: fail-fast: false #ensure both tests run even if one fails matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 @@ -60,21 +78,21 @@ jobs: key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} restore-keys: | ${{ runner.os }}-gradle- - - name: Update Property File + - name: Update Property File run: mv src/test/resources/test.ci-${{ matrix.os }}.properties src/test/resources/test.properties - name: Run Solr search service if: matrix.os == 'ubuntu-latest' # Docker does not work well on Windows env run: docker-compose run -d -p 8983:8983 solr - name: Run Backend Tests run: | - ./gradlew createConfigs componentTests + ./gradlew createConfigs componentTests ./gradlew jacocoReport - - name: Generate Types + - name: Generate Types run: ./gradlew generateTypes - - name: Install Frontend Dependencies - run: npm ci - - name: Run Frontend Tests - run: npm run coverage - - name: Upload to Codecov - if: matrix.os == 'ubuntu-latest' #only upload to codecov on ubuntu VM + - name: Install Frontend Dependencies + run: npm ci + - name: Run Frontend Tests + run: npm run coverage + - name: Upload to Codecov + if: matrix.os == 'ubuntu-latest' #only upload to codecov on ubuntu VM uses: codecov/codecov-action@v3 diff --git a/.gitignore b/.gitignore index 60e167619d7..31928101439 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,8 @@ node_modules/ npm-debug.log coverage/* +.eslintcache +.stylelintcache # Gradle .gradle diff --git a/package-lock.json b/package-lock.json index 776a1dfefcd..8b55674918c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15402,6 +15402,12 @@ "queue-microtask": "^1.2.2" } }, + "run-script-os": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/run-script-os/-/run-script-os-1.1.6.tgz", + "integrity": "sha512-ql6P2LzhBTTDfzKts+Qo4H94VUKpxKDFz6QxxwaUZN0mwvi7L3lpOI7BqPCq7lgDh3XLl0dpeXwfcVIitlrYrw==", + "dev": true + }, "rw": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/rw/-/rw-1.3.3.tgz", diff --git a/package.json b/package.json index 1bb6fcb8201..76f1486914a 100644 --- a/package.json +++ b/package.json @@ -6,10 +6,13 @@ "analyze": "webpack-bundle-analyzer src/web/dist/stats.json", "test": "ng test --watch", "coverage": "rimraf coverage && ng test --coverage", - "lint:ts": "ng lint --eslint-config static-analysis/teammates-eslint.yml", - "lint:css": "stylelint \"src/web/**/*.css\" \"src/web/**/*.scss\" \"src/web/**/*.html\" --config static-analysis/teammates-stylelint.yml", - "lint:spaces": "lintspaces -n -t -d spaces -l 1 -. \"src/main/**/*.html\" \"src/web/**/*.html\" \"src/**/*.xml\" \"src/**/*.json\" \"src/**/*.properties\" \"*.yml\" \"*.json\" \"*.gradle\" \"static-analysis/*.*ml\" \".gitattributes\"", - "lint": "npm-run-all lint:* -c" + "lint:ts": "ng lint --cache --eslint-config static-analysis/teammates-eslint.yml", + "lint:css": "stylelint \"src/web/**/*.css\" \"src/web/**/*.scss\" \"src/web/**/*.html\" --ignore-pattern \"src/web/dist/*.css\" --cache --config static-analysis/teammates-stylelint.yml", + "lint:windows:spaces": "lintspaces -n -t -d spaces -l 1 -. \"src/main/**/*.html\" \"src/web/**/*.html\" \"src/**/*.xml\" \"src/**/*.json\" \"src/**/*.properties\" \"*.yml\" \"*.json\" \"*.gradle\" \"static-analysis/*.*ml\" \".gitattributes\"", + "lint:nix:spaces": "lintspaces -n -t -d spaces -l 1 --matchdotfiles $(git diff --name-only --diff-filter=ACMRTUXB origin/master HEAD | grep -E \"src/(main|web)/.*.html|src/.*.(xml|json|properties)|*.(yml|json|gradle)|static-analysis/*.*ml|.gitattributes\")", + "lint": "run-script-os", + "lint:windows": "npm-run-all lint:ts lint:css lint:windows:spaces -c", + "lint:nix": "npm-run-all lint:ts lint:css lint:nix:spaces -c" }, "private": true, "dependencies": { @@ -71,6 +74,7 @@ "npm-run-all": "^4.1.5", "postcss": "^8.4.7", "rimraf": "^3.0.2", + "run-script-os": "^1.1.6", "stylelint": "^13.13.1", "stylelint-config-standard": "^22.0.0", "typescript": "~4.3.5",