Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .github/actions/knip-it/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Kjør Knip
description: Kjører Knip for å finne ubrukt kode og eksporter
inputs:
npm-auth-token:
description: Token med `packages:read` for navikt organisasjonen.
required: true
package-manager:
description: Package manager som skal brukes (pnpm|yarn).
required: true
node-version:
description: Node version som brukes.
default: "22"
required: false
github-token:
description: Token som skal brukes for å publisere en PR kommentar.
required: true

runs:
using: composite
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # ratchet:actions/checkout@v4

- uses: navikt/fp-gha-workflows/.github/actions/setup-yarnrc@main
if: inputs.package-manager == 'yarn'
with:
npmAuthToken: ${{ inputs.npm-auth-token }}

- uses: navikt/fp-gha-workflows/.github/actions/setup-npmrc@main
if: inputs.package-manager == 'pnpm'
with:
npmAuthToken: ${{ inputs.npm-auth-token }}

- uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # ratchet:pnpm/action-setup@v2
if: inputs.package-manager == 'pnpm'
with:
version: 10.18.3

- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # ratchet:actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}
cache: ${{ inputs.package-manager }}

- name: Yarn install
if: inputs.package-manager == 'yarn'
shell: bash
run: |
yarn install --immutable

- name: Pnpm install
if: inputs.package-manager == 'pnpm'
shell: bash
run: |
pnpm install --frozen-lockfile

- name: Run Knip
shell: bash
run: |
if [ "${{ inputs.package-manager }}" = "yarn" ]; then
yarn knip --no-exit-code --reporter=markdown > knip-report.md
elif [ "${{ inputs.package-manager }}" = "pnpm" ]; then
pnpm knip --no-exit-code --reporter=markdown > knip-report.md
else
echo "Unsupported package manager: ${{ inputs.package-manager }}"
exit 1
fi

- name: Slett forrige kommentar fra Knip
if: github.event.pull_request.number
Comment on lines +67 to +68
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition github.event.pull_request.number evaluates to true even when the number is 0 (which shouldn't occur but is safer to guard against). Use github.event.pull_request.number != '' or github.event_name == 'pull_request' for more robust checking.

Copilot uses AI. Check for mistakes.
shell: bash
continue-on-error: true
run: gh pr comment ${{ github.event.pull_request.number }} --delete-last --yes
env:
GITHUB_TOKEN: ${{ inputs.github-token }}

- name: Post Knip rapport
if: github.event.pull_request.number
shell: bash
run: |
number_of_words=$(wc -w < knip-report.md)
if [ $number_of_words -gt 3 ]; then
gh pr comment ${{ github.event.pull_request.number }} --body-file knip-report.md
fi
env:
GITHUB_TOKEN: ${{ inputs.github-token }}

Comment on lines +67 to +85
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --delete-last flag deletes the last comment by any user on the PR, not just comments from this action. This could accidentally delete unrelated comments. Consider using a comment identifier or marker to target only Knip comments, or use a dedicated action like marocchino/sticky-pull-request-comment that can update/replace specific comments.

Suggested change
- name: Slett forrige kommentar fra Knip
if: github.event.pull_request.number
shell: bash
continue-on-error: true
run: gh pr comment ${{ github.event.pull_request.number }} --delete-last --yes
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
- name: Post Knip rapport
if: github.event.pull_request.number
shell: bash
run: |
number_of_words=$(wc -w < knip-report.md)
if [ $number_of_words -gt 3 ]; then
gh pr comment ${{ github.event.pull_request.number }} --body-file knip-report.md
fi
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
- name: Post/oppdater Knip rapport
if: github.event.pull_request.number
uses: marocchino/sticky-pull-request-comment@v2
with:
header: knip-report
path: knip-report.md
GITHUB_TOKEN: ${{ inputs.github-token }}

Copilot uses AI. Check for mistakes.
- name: Oppsummer Knip rapport
shell: bash
run: cat knip-report.md >> $GITHUB_STEP_SUMMARY
4 changes: 1 addition & 3 deletions .github/workflows/deploy-storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
package-manager:
required: false
type: string
description: Hvilken package manager en skal bruke (npm|pnpm|yarn)
description: Package manager som skal brukes (pnpm|yarn).
default: "yarn"
node-version:
required: false
Expand Down Expand Up @@ -64,8 +64,6 @@ jobs:
if: inputs.package-manager == 'pnpm'
run: |
pnpm install --frozen-lockfile
env:
GH_TOKEN: ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}

- name: Set remote url med token
run: git remote set-url origin https://git:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git
Expand Down