|
| 1 | +name: Kjør Knip |
| 2 | +description: Kjører Knip for å finne ubrukt kode og eksporter |
| 3 | +inputs: |
| 4 | + npm-auth-token: |
| 5 | + description: Token med `packages:read` for navikt organisasjonen. |
| 6 | + required: true |
| 7 | + package-manager: |
| 8 | + description: Package manager som skal brukes (pnpm|yarn). |
| 9 | + required: true |
| 10 | + node-version: |
| 11 | + description: Node version som brukes. |
| 12 | + default: "22" |
| 13 | + required: false |
| 14 | + github-token: |
| 15 | + description: Token som skal brukes for å publisere en PR kommentar. |
| 16 | + required: true |
| 17 | + |
| 18 | +runs: |
| 19 | + using: composite |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # ratchet:actions/checkout@v4 |
| 22 | + |
| 23 | + - uses: navikt/fp-gha-workflows/.github/actions/setup-yarnrc@main |
| 24 | + if: inputs.package-manager == 'yarn' |
| 25 | + with: |
| 26 | + npmAuthToken: ${{ inputs.npm-auth-token }} |
| 27 | + |
| 28 | + - uses: navikt/fp-gha-workflows/.github/actions/setup-npmrc@main |
| 29 | + if: inputs.package-manager == 'pnpm' |
| 30 | + with: |
| 31 | + npmAuthToken: ${{ inputs.npm-auth-token }} |
| 32 | + |
| 33 | + - uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # ratchet:pnpm/action-setup@v2 |
| 34 | + if: inputs.package-manager == 'pnpm' |
| 35 | + with: |
| 36 | + version: 10.18.3 |
| 37 | + |
| 38 | + - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # ratchet:actions/setup-node@v3 |
| 39 | + with: |
| 40 | + node-version: ${{ inputs.node-version }} |
| 41 | + cache: ${{ inputs.package-manager }} |
| 42 | + |
| 43 | + - name: Yarn install |
| 44 | + if: inputs.package-manager == 'yarn' |
| 45 | + shell: bash |
| 46 | + run: | |
| 47 | + yarn install --immutable |
| 48 | +
|
| 49 | + - name: Pnpm install |
| 50 | + if: inputs.package-manager == 'pnpm' |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + pnpm install --frozen-lockfile |
| 54 | +
|
| 55 | + - name: Run Knip |
| 56 | + shell: bash |
| 57 | + run: | |
| 58 | + if [ "${{ inputs.package-manager }}" = "yarn" ]; then |
| 59 | + yarn knip --no-exit-code --reporter=markdown > knip-report.md |
| 60 | + elif [ "${{ inputs.package-manager }}" = "pnpm" ]; then |
| 61 | + pnpm knip --no-exit-code --reporter=markdown > knip-report.md |
| 62 | + else |
| 63 | + echo "Unsupported package manager: ${{ inputs.package-manager }}" |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | +
|
| 67 | + - name: Slett forrige kommentar fra Knip |
| 68 | + if: github.event.pull_request.number |
| 69 | + shell: bash |
| 70 | + continue-on-error: true |
| 71 | + run: gh pr comment ${{ github.event.pull_request.number }} --delete-last --yes |
| 72 | + env: |
| 73 | + GITHUB_TOKEN: ${{ inputs.github-token }} |
| 74 | + |
| 75 | + - name: Post Knip rapport |
| 76 | + if: github.event.pull_request.number |
| 77 | + shell: bash |
| 78 | + run: | |
| 79 | + number_of_words=$(wc -w < knip-report.md) |
| 80 | + if [ $number_of_words -gt 3 ]; then |
| 81 | + gh pr comment ${{ github.event.pull_request.number }} --body-file knip-report.md |
| 82 | + fi |
| 83 | + env: |
| 84 | + GITHUB_TOKEN: ${{ inputs.github-token }} |
| 85 | + |
| 86 | + - name: Oppsummer Knip rapport |
| 87 | + shell: bash |
| 88 | + run: cat knip-report.md >> $GITHUB_STEP_SUMMARY |
0 commit comments