forked from compdemocracy/polis
-
-
Notifications
You must be signed in to change notification settings - Fork 2
82 lines (72 loc) · 3.48 KB
/
depcheck.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: DepCheck
on:
pull_request:
types: ["opened", "reopened", "synchronize"]
paths:
- .github/workflows/depcheck.yml
- client-admin/**
jobs:
run:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CI_COMMIT_ID: ${{ github.event.pull_request.head.sha || github.sha }}
CI_REPO_NAME: ${{ github.repository }}
steps:
# See: https://github.community/t/if-expression-with-context-variable/16558/6
- name: Check if secrets available
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
unset HAS_SECRET
if [ -n "$GITHUB_TOKEN" ]; then HAS_SECRET=true; fi
echo "name=HAS_SECRET" >> $GITHUB_ENV
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 18
# See: https://github.com/taskworld/commit-status
- name: Install commit-status CLI tool
run: npm install -g commit-status
- name: Initiate commit status placeholders
if: github.event.pull_request.head.repo.full_name == github.repository
run: |
# commit-status <state> <context> <description> <link>
commit-status pending "DepCheck / dependencies" "Detecting unused packages..."
commit-status pending "DepCheck / devDependencies" "Detecting unused packages..."
- uses: actions/checkout@v4
- name: Install depcheck CLI tool
run: npm install -g depcheck
- name: Install project dependencies
working-directory: client-admin
run: npm install
- name: Run depcheck and save output
id: depcheck
working-directory: client-admin
env:
# See: https://github.com/depcheck/depcheck#special
DEPCHECK_SPECIALS: "webpack,babel,eslint,prettier,bin"
# Why ignoring?
# - prettier: because it's needed by eslint-plugin-prettier, but peerDependencies aren't yet supported.
# See: https://github.com/depcheck/depcheck/issues/522
# - webpack-cli: Needed for `webpack` command, but provide `webpack-cli` bin, which confuses depcheck.
DEPCHECK_IGNORES: "prettier,prettier-config-standard,webpack-cli"
run: |
# Note: Commit status descriptions can have 140 characters max. (We add an ellipsis in the final step as final char)
# Suppress failing exit codes with `true`.
depcheck --specials "$DEPCHECK_SPECIALS" --ignores "$DEPCHECK_IGNORES" --json > .results.json || true
echo ::set-output name=dependencies::$(cat .results.json | jq '.dependencies | join(", ") | .[:139]' --raw-output)
echo ::set-output name=devdependencies::$(cat .results.json | jq '.devDependencies | join(", ") | .[:139]' --raw-output)
- name: Set commit status messages and success states
if: github.event.pull_request.head.repo.full_name == github.repository
run: |
if [ "${{ steps.depcheck.outputs.dependencies }}" = "" ]; then
commit-status success "DepCheck / dependencies" "No unused packages detected."
else
commit-status failure "DepCheck / dependencies" "${{ steps.depcheck.outputs.dependencies }}…"
fi
if [ "${{ steps.depcheck.outputs.devdependencies }}" = "" ]; then
commit-status success "DepCheck / devDependencies" "No unused packages detected."
else
commit-status failure "DepCheck / devDependencies" "${{ steps.depcheck.outputs.devdependencies }}…"
fi