From d4ead41af27ae7fb0d98e901c6e40d1405e605c0 Mon Sep 17 00:00:00 2001 From: Marcel Eichner Date: Sun, 10 Apr 2022 15:42:27 +0200 Subject: [PATCH] build(ci): adds depcheck --- .depcheckrc | 9 +++++++++ .github/actions/setup/action.yml | 24 ++++++++++++++++++++++++ .github/workflows/depcheck.yml | 30 ++++++++++++++++++++++++++++++ .github/workflows/test.yml | 6 +----- .husky/pre-commit | 4 ++-- 5 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 .depcheckrc create mode 100644 .github/actions/setup/action.yml create mode 100644 .github/workflows/depcheck.yml diff --git a/.depcheckrc b/.depcheckrc new file mode 100644 index 0000000..d9a3aea --- /dev/null +++ b/.depcheckrc @@ -0,0 +1,9 @@ +# depcheck configuration +# SEE https://www.npmjs.com/package/depcheck#api + +# if you add ignores also annotate why the package is ignored +# keep list ordered at all times +ignores: + - "@commitlint/cli" + - "@commitlint/config-angular" + - "@istanbuljs/nyc-config-typescript" diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 0000000..83efdd4 --- /dev/null +++ b/.github/actions/setup/action.yml @@ -0,0 +1,24 @@ +name: setup +description: 'basic setup project with npm ci' + +runs: + using: "composite" + steps: + - name: setup nodejs + uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + check-latest: true + cache: npm + - name: cache dependencies + id: cache + uses: actions/cache@v3 + with: + path: ./node_modules + key: node-modules-${{ runner.name }}-${{ runner.arch}}-${{ hashFiles('package-lock.json') }} + - name: install dependencies + run: npm ci --no-audit + # only run npm ci when restoring the cache didn’t work to save some time + # as npm ci would remove the node_modules again + if: steps.cache.outputs.cache-hit != 'true' + shell: bash diff --git a/.github/workflows/depcheck.yml b/.github/workflows/depcheck.yml new file mode 100644 index 0000000..36b3ec3 --- /dev/null +++ b/.github/workflows/depcheck.yml @@ -0,0 +1,30 @@ +# SEE https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions + +# Runs `npx depcheck` +# +# Depcheck is a tool for analyzing the dependencies in a project to see: how +# each dependency is used, which dependencies are useless, and which +# dependencies are missing from package.json. +# +# https://www.npmjs.com/package/depcheck + +name: depcheck + +on: + # allow manual trigger workflow + pull_request: + branches: + - main + paths: + # run only when one of the files matching the glob patterns changed + - 'package.json' + - 'package-lock.json' + +jobs: + + depcheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/setup + - run: npx depcheck diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fa420cf..d3a857a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,9 +7,5 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version-file: '.nvmrc' - cache: 'npm' - - run: npm ci --no-optional + - uses: ./.github/actions/setup - run: npm test diff --git a/.husky/pre-commit b/.husky/pre-commit index 8c904ff..01ea140 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -16,7 +16,7 @@ fi . "$(dirname "$0")/_/husky.sh" printf "%b>>>%b lint...\n" "$GREEN" "$NO_COLOR" -npm run lint:fix -s +npm run -s lint:fix printf "%b>>>%b prettier...\n" "$GREEN" "$NO_COLOR" -npm run format +npm run -s format