From 229e57d3fba99a1a6871c15ddc437700487921c2 Mon Sep 17 00:00:00 2001 From: Martin Rohrmeier Date: Mon, 17 Jun 2024 15:47:12 +0200 Subject: [PATCH] chore(husky): improve pre commit checks (#338) --- .github/dependabot.yml | 40 +++++++++---------- .github/workflows/build.yml | 12 +++--- .github/workflows/checks.yml | 5 ++- .github/workflows/codeql.yml | 8 ++-- .github/workflows/dependencies.yaml | 4 +- .github/workflows/kics.yml | 10 ++--- .github/workflows/pullRequest-lint.yaml | 6 +-- .../workflows/release-release_candidate.yml | 19 ++++----- .github/workflows/release.yml | 19 ++++----- .github/workflows/release_candidate.yml | 12 +++--- .github/workflows/trivy-main.yml | 30 +++++++------- .github/workflows/trivy.yml | 28 ++++++------- .husky/.gitignore | 1 - .husky/pre-commit | 6 +-- package.json | 22 +++++++--- public/documentation/index.html | 10 +++-- public/documentation/js/Main.js | 1 - 17 files changed, 122 insertions(+), 111 deletions(-) delete mode 100644 .husky/.gitignore diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 9a90c292..506b1e29 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -21,46 +21,44 @@ version: 2 updates: # NPM - - - package-ecosystem: "npm" + - package-ecosystem: 'npm' directory: / labels: - - "dependabot" - - "dependencies" + - 'dependabot' + - 'dependencies' schedule: - interval: "weekly" + interval: 'weekly' # restrict to patch updates (due to the big amount of dependencies) ignore: - - dependency-name: "*" - update-types: ["version-update:semver-major", "version-update:semver-minor"] + - dependency-name: '*' + update-types: + ['version-update:semver-major', 'version-update:semver-minor'] groups: production-dependencies: - dependency-type: "production" + dependency-type: 'production' development-dependencies: - dependency-type: "development" + dependency-type: 'development' # Github Actions - - - package-ecosystem: "github-actions" + - package-ecosystem: 'github-actions' directory: / labels: - - "dependabot" - - "github-actions" + - 'dependabot' + - 'github-actions' schedule: - interval: "weekly" + interval: 'weekly' groups: dependencies: - dependency-type: "production" + dependency-type: 'production' # Docker - - - package-ecosystem: "docker" + - package-ecosystem: 'docker' directory: ./.conf/ labels: - - "dependabot" - - "docker" + - 'dependabot' + - 'docker' schedule: - interval: "weekly" + interval: 'weekly' groups: dependencies: - dependency-type: "production" \ No newline at end of file + dependency-type: 'production' diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a7d8b340..62d99a8c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,12 +26,12 @@ on: workflow_dispatch: env: - IMAGE_NAMESPACE: "tractusx" - IMAGE_NAME: "portal-assets" + IMAGE_NAMESPACE: 'tractusx' + IMAGE_NAME: 'portal-assets' # variables needed for scripts/legal-notice.sh - SERVER_URL: "${{ github.server_url }}" - REPOSITORY: "${{ github.repository }}" - REF_NAME: "${{ github.ref_name }}" + SERVER_URL: '${{ github.server_url }}' + REPOSITORY: '${{ github.repository }}' + REF_NAME: '${{ github.ref_name }}' jobs: build-and-push-image: @@ -92,7 +92,7 @@ jobs: username: ${{ secrets.DOCKER_HUB_USER }} password: ${{ secrets.DOCKER_HUB_TOKEN }} repository: ${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }} - readme-filepath: ".conf/notice-assets.md" + readme-filepath: '.conf/notice-assets.md' auth-and-dispatch: needs: build-and-push-image diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index cdeb56b2..72926225 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -35,7 +35,10 @@ jobs: - name: Install Dependencies run: yarn - - name: Execute linter checks + - name: Prettier checks + run: yarn pretty:check + + - name: Linter checks run: yarn lint - name: Build Application diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index e963c198..31046b43 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -29,7 +29,7 @@ # supported CodeQL languages. # -name: "CodeQL" +name: 'CodeQL' on: push: @@ -42,7 +42,7 @@ on: - 'src/**' - 'public/**' schedule: - - cron: "0 0 * * *" + - cron: '0 0 * * *' workflow_dispatch: jobs: @@ -63,7 +63,7 @@ jobs: strategy: fail-fast: false matrix: - language: ["javascript"] + language: ['javascript'] # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ] # Use only 'java' to analyze code written in Java, Kotlin or both # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both @@ -104,4 +104,4 @@ jobs: - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@9fdb3e49720b44c48891d036bb502feb25684276 # v2.227 with: - category: "/language:${{matrix.language}}" + category: '/language:${{matrix.language}}' diff --git a/.github/workflows/dependencies.yaml b/.github/workflows/dependencies.yaml index 7498d78a..9da9a59a 100644 --- a/.github/workflows/dependencies.yaml +++ b/.github/workflows/dependencies.yaml @@ -21,18 +21,16 @@ name: Check Dependencies on: push: - branches: [ main ] + branches: [main] pull_request: types: [opened, synchronize, reopened] workflow_dispatch: jobs: check-dependencies: - runs-on: ubuntu-latest steps: - - name: Set up JDK 17 uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: diff --git a/.github/workflows/kics.yml b/.github/workflows/kics.yml index 9b56d6e8..5d959db8 100644 --- a/.github/workflows/kics.yml +++ b/.github/workflows/kics.yml @@ -17,11 +17,11 @@ # SPDX-License-Identifier: Apache-2.0 ############################################################### -name: "KICS" +name: 'KICS' on: push: - branches: [ main ] + branches: [main] # pull_request: # The branches below must be a subset of the branches above # branches: [main, master] @@ -29,7 +29,7 @@ on: # - "**/*.md" # - "**/*.txt" schedule: - - cron: "0 0 * * *" + - cron: '0 0 * * *' workflow_dispatch: jobs: @@ -48,7 +48,7 @@ jobs: uses: checkmarx/kics-github-action@d1b692d84c536f4e8696954ce7aab6818f95f5bc # v2.0.0 with: # Scanning directory . - path: "." + path: '.' # Fail on HIGH severity results fail_on: high # when provided with a directory on output_path @@ -57,7 +57,7 @@ jobs: # - results-dir/results.json # - results-dir/results.sarif output_path: kicsResults/ - output_formats: "json,sarif" + output_formats: 'json,sarif' # If you want KICS to ignore the results and return exit status code 0 unless a KICS engine error happens # ignore_on_exit: results # GITHUB_TOKEN enables this github action to access github API and post comments in a pull request diff --git a/.github/workflows/pullRequest-lint.yaml b/.github/workflows/pullRequest-lint.yaml index f52da4e1..ad251299 100644 --- a/.github/workflows/pullRequest-lint.yaml +++ b/.github/workflows/pullRequest-lint.yaml @@ -17,7 +17,7 @@ # SPDX-License-Identifier: Apache-2.0 # ############################################################################# -name: "Lint PullRequest" +name: 'Lint PullRequest' on: pull_request_target: @@ -44,11 +44,11 @@ jobs: header: pr-title-lint-error message: | Hey there and thank you for opening this pull request! 👋🏼 - + We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted. Details: - + ``` ${{ steps.lint_pr_title.outputs.error_message }} ``` diff --git a/.github/workflows/release-release_candidate.yml b/.github/workflows/release-release_candidate.yml index bd00f186..3ef730fb 100644 --- a/.github/workflows/release-release_candidate.yml +++ b/.github/workflows/release-release_candidate.yml @@ -26,12 +26,12 @@ on: workflow_dispatch: env: - IMAGE_NAMESPACE: "tractusx" - IMAGE_NAME: "portal-assets" - REF_NAME: "${{ github.ref_name }}" + IMAGE_NAMESPACE: 'tractusx' + IMAGE_NAME: 'portal-assets' + REF_NAME: '${{ github.ref_name }}' # variables needed for scripts/legal-notice.sh - SERVER_URL: "${{ github.server_url }}" - REPOSITORY: "${{ github.repository }}" + SERVER_URL: '${{ github.server_url }}' + REPOSITORY: '${{ github.repository }}' jobs: build-and-push-release: @@ -88,9 +88,10 @@ jobs: id: meta uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1 with: - images: ${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }} - # Automatically prepare image tags; - # semver patter will generate tags like these for example :v1 :v1.2 v1.2.3 + images: + ${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }} + # Automatically prepare image tags; + # semver patter will generate tags like these for example :v1 :v1.2 v1.2.3 tags: | type=raw,value=latest type=raw,value=${{ env.REF_NAME }} @@ -116,7 +117,7 @@ jobs: username: ${{ secrets.DOCKER_HUB_USER }} password: ${{ secrets.DOCKER_HUB_TOKEN }} repository: ${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }} - readme-filepath: ".conf/notice-assets.md" + readme-filepath: '.conf/notice-assets.md' auth-and-dispatch: needs: build-and-push-release diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 02384501..3f74842e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,12 +27,12 @@ on: workflow_dispatch: env: - IMAGE_NAMESPACE: "tractusx" - IMAGE_NAME: "portal-assets" - REF_NAME: "${{ github.ref_name }}" + IMAGE_NAMESPACE: 'tractusx' + IMAGE_NAME: 'portal-assets' + REF_NAME: '${{ github.ref_name }}' # variables needed for scripts/legal-notice.sh - SERVER_URL: "${{ github.server_url }}" - REPOSITORY: "${{ github.repository }}" + SERVER_URL: '${{ github.server_url }}' + REPOSITORY: '${{ github.repository }}' jobs: build-and-push-release: @@ -89,9 +89,10 @@ jobs: id: meta uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1 with: - images: ${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }} - # Automatically prepare image tags; - # semver patter will generate tags like these for example :v1 :v1.2 v1.2.3 + images: + ${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }} + # Automatically prepare image tags; + # semver patter will generate tags like these for example :v1 :v1.2 v1.2.3 tags: | type=raw,value=latest type=raw,value=${{ env.REF_NAME }} @@ -117,7 +118,7 @@ jobs: username: ${{ secrets.DOCKER_HUB_USER }} password: ${{ secrets.DOCKER_HUB_TOKEN }} repository: ${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }} - readme-filepath: ".conf/notice-assets.md" + readme-filepath: '.conf/notice-assets.md' auth-and-dispatch: needs: build-and-push-release diff --git a/.github/workflows/release_candidate.yml b/.github/workflows/release_candidate.yml index 1db0243e..d8dff0d8 100644 --- a/.github/workflows/release_candidate.yml +++ b/.github/workflows/release_candidate.yml @@ -26,12 +26,12 @@ on: workflow_dispatch: env: - IMAGE_NAMESPACE: "tractusx" - IMAGE_NAME: "portal-assets" + IMAGE_NAMESPACE: 'tractusx' + IMAGE_NAME: 'portal-assets' # variables needed for scripts/legal-notice.sh - SERVER_URL: "${{ github.server_url }}" - REPOSITORY: "${{ github.repository }}" - REF_NAME: "${{ github.ref_name }}" + SERVER_URL: '${{ github.server_url }}' + REPOSITORY: '${{ github.repository }}' + REF_NAME: '${{ github.ref_name }}' jobs: build-and-push-image: @@ -92,7 +92,7 @@ jobs: username: ${{ secrets.DOCKER_HUB_USER }} password: ${{ secrets.DOCKER_HUB_TOKEN }} repository: ${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }} - readme-filepath: ".conf/notice-assets.md" + readme-filepath: '.conf/notice-assets.md' auth-and-dispatch: needs: build-and-push-image diff --git a/.github/workflows/trivy-main.yml b/.github/workflows/trivy-main.yml index 1675d3b0..986b3a0c 100644 --- a/.github/workflows/trivy-main.yml +++ b/.github/workflows/trivy-main.yml @@ -20,11 +20,11 @@ # Depending on the location of your Docker container # you need to change the path to the specific Docker registry. # -name: "Trivy Main" +name: 'Trivy Main' on: push: - branches: [ main ] + branches: [main] # pull_request: # The branches below must be a subset of the branches above # paths-ignore: @@ -32,13 +32,13 @@ on: # - "**/*.txt" schedule: # Once a day - - cron: "0 0 * * *" + - cron: '0 0 * * *' workflow_dispatch: # Trigger manually env: - IMAGE_NAMESPACE: "tractusx" - IMAGE_NAME: "portal-assets" + IMAGE_NAMESPACE: 'tractusx' + IMAGE_NAME: 'portal-assets' jobs: analyze-config: @@ -55,17 +55,17 @@ jobs: - name: Run Trivy vulnerability scanner in repo mode uses: aquasecurity/trivy-action@fd25fed6972e341ff0007ddb61f77e88103953c2 # v0.21.0 with: - scan-type: "config" + scan-type: 'config' hide-progress: false - format: "sarif" - output: "trivy-results1.sarif" - vuln-type: "os,library" + format: 'sarif' + output: 'trivy-results1.sarif' + vuln-type: 'os,library' - name: Upload Trivy scan results to GitHub Security tab uses: github/codeql-action/upload-sarif@9fdb3e49720b44c48891d036bb502feb25684276 # v3.25.6 if: always() with: - sarif_file: "trivy-results1.sarif" + sarif_file: 'trivy-results1.sarif' analyze-portal-assets: runs-on: ubuntu-latest @@ -88,13 +88,13 @@ jobs: uses: aquasecurity/trivy-action@fd25fed6972e341ff0007ddb61f77e88103953c2 # v0.21.0 with: # Path to Docker image - image-ref: "${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}:main" - format: "sarif" - output: "trivy-results2.sarif" - vuln-type: "os,library" + image-ref: '${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}:main' + format: 'sarif' + output: 'trivy-results2.sarif' + vuln-type: 'os,library' - name: Upload Trivy scan results to GitHub Security tab if: always() uses: github/codeql-action/upload-sarif@9fdb3e49720b44c48891d036bb502feb25684276 # v3.25.6 with: - sarif_file: "trivy-results2.sarif" + sarif_file: 'trivy-results2.sarif' diff --git a/.github/workflows/trivy.yml b/.github/workflows/trivy.yml index 882f11f7..394f36d6 100644 --- a/.github/workflows/trivy.yml +++ b/.github/workflows/trivy.yml @@ -20,7 +20,7 @@ # Depending on the location of your Docker container # you need to change the path to the specific Docker registry. # -name: "Trivy Stable" +name: 'Trivy Stable' on: # push: @@ -32,13 +32,13 @@ on: # - "**/*.txt" schedule: # Once a day - - cron: "0 0 * * *" + - cron: '0 0 * * *' workflow_dispatch: # Trigger manually env: - IMAGE_NAMESPACE: "tractusx" - IMAGE_NAME: "portal-assets" + IMAGE_NAMESPACE: 'tractusx' + IMAGE_NAME: 'portal-assets' jobs: analyze-config: @@ -55,17 +55,17 @@ jobs: - name: Run Trivy vulnerability scanner in repo mode uses: aquasecurity/trivy-action@fd25fed6972e341ff0007ddb61f77e88103953c2 # v0.21.0 with: - scan-type: "config" + scan-type: 'config' hide-progress: false - format: "sarif" - output: "trivy-results1.sarif" - vuln-type: "os,library" + format: 'sarif' + output: 'trivy-results1.sarif' + vuln-type: 'os,library' - name: Upload Trivy scan results to GitHub Security tab uses: github/codeql-action/upload-sarif@9fdb3e49720b44c48891d036bb502feb25684276 # v3.25.6 if: always() with: - sarif_file: "trivy-results1.sarif" + sarif_file: 'trivy-results1.sarif' analyze-portal-assets: runs-on: ubuntu-latest @@ -88,13 +88,13 @@ jobs: uses: aquasecurity/trivy-action@fd25fed6972e341ff0007ddb61f77e88103953c2 # v0.21.0 with: # Path to Docker image - image-ref: "${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}:latest" - format: "sarif" - output: "trivy-results2.sarif" - vuln-type: "os,library" + image-ref: '${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}:latest' + format: 'sarif' + output: 'trivy-results2.sarif' + vuln-type: 'os,library' - name: Upload Trivy scan results to GitHub Security tab if: always() uses: github/codeql-action/upload-sarif@9fdb3e49720b44c48891d036bb502feb25684276 # v3.25.6 with: - sarif_file: "trivy-results2.sarif" + sarif_file: 'trivy-results2.sarif' diff --git a/.husky/.gitignore b/.husky/.gitignore deleted file mode 100644 index 31354ec1..00000000 --- a/.husky/.gitignore +++ /dev/null @@ -1 +0,0 @@ -_ diff --git a/.husky/pre-commit b/.husky/pre-commit index af9c59b6..2312dc58 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,5 +1 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - -npm run pretty -npm run lint --fix \ No newline at end of file +npx lint-staged diff --git a/package.json b/package.json index 350eb52c..9cfeb318 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,23 @@ "dependencies": { "zero-md": "^2.4.0" }, + "lint-staged": { + "*.{js,jsx,ts,tsx}": [ + "prettier --write --ignore-unknown", + "eslint --quiet --fix" + ], + "*.{json,css,sass,scss,xml,yml,yaml,md}": [ + "prettier --write --ignore-unknown" + ], + "*.test.{js,jsx,ts,tsx}": [ + "jest" + ] + }, "scripts": { + "prepare": "husky", + "pretty": "prettier --write \"**/*.{ts,tsx,js,jsx,json,css,sass,scss,xml,yml,yaml,html,md}\"", + "pretty:check": "prettier --check \"**/*.{ts,tsx,js,jsx,json,css,sass,scss,xml,yml,yaml,html,md}\"", + "lint": "eslint \"./{src,public/documentation}/**/*.{ts,tsx,js,jsx}\" --report-unused-disable-directives --max-warnings 0", "build:release": "node src/documentation/Release.js ${1}", "build": "yarn build:copy-legal-info && ./scripts/build.sh", "build:legal-notice": "bash scripts/legal-notice.sh", @@ -29,10 +45,6 @@ "build:sources": "zip -r portal-assets.zip src package.json yarn.lock -x '*.stories.*' -x '*.test.*' -x '*.ttf' -x '*.svg' -x '*.png' -x '*.jpg'", "start": "concurrently \"yarn start:assets\" \"yarn start:proxy\" \"open http://localhost:3000/\"", "start:proxy": "node src/proxy/index.cjs", - "start:assets": "http-server -a 127.0.0.1 -p 3003", - "prepare": "husky", - "lint": "eslint .", - "lint:fix": "eslint --fix", - "pretty": "prettier --write './**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc" + "start:assets": "http-server -a 127.0.0.1 -p 3003" } } diff --git a/public/documentation/index.html b/public/documentation/index.html index a8508180..1ae2e54b 100644 --- a/public/documentation/index.html +++ b/public/documentation/index.html @@ -17,12 +17,16 @@ - SPDX-License-Identifier: Apache-2.0 --> - + CX Docs - + + @@ -32,4 +36,4 @@ - \ No newline at end of file + diff --git a/public/documentation/js/Main.js b/public/documentation/js/Main.js index 300d1afb..d3d90ad8 100644 --- a/public/documentation/js/Main.js +++ b/public/documentation/js/Main.js @@ -359,7 +359,6 @@ class Navigation extends Viewable { ;[...this.menu.getElementsByClassName('selected')].forEach((item) => item.classList.remove('selected') ) - // eslint-disable-next-line no-extra-semi ;[...this.menu.getElementsByClassName(normalize(content.path))].forEach( (item) => item.classList.add('selected') )