-
Notifications
You must be signed in to change notification settings - Fork 2
legg til reusable knip action #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8b66a49
c2471fe
b2afad8
3b86e5a
c077927
e6bfa57
4121fa2
3f28cae
3985674
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
sirimykland marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| GITHUB_TOKEN: ${{ inputs.github-token }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+67
to
+85
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 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 }} |
There was a problem hiding this comment.
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.numberevaluates to true even when the number is 0 (which shouldn't occur but is safer to guard against). Usegithub.event.pull_request.number != ''orgithub.event_name == 'pull_request'for more robust checking.