Skip to content

Commit

Permalink
Merge pull request #43 from gitcoindev/refactor-knip-to-run-on-pull-r…
Browse files Browse the repository at this point in the history
…equest-event

chore: update knip configuration in the template to run on pull_request
  • Loading branch information
rndquu authored May 27, 2024
2 parents 0f9acf6 + 269bd86 commit c99c565
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 11 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/knip-reporter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Knip-reporter

on:
workflow_run:
workflows: ["Knip"]
types:
- completed

jobs:
knip-reporter:
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: knip-results
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Read pr number
id: pr-number
uses: juliangruber/read-file-action@v1
with:
path: ./pr-number.txt
trim: true

- name: Report knip results to pull request
if: ${{ github.event.workflow_run.conclusion != 'success' }}
uses: gitcoindev/knip-reporter@main
with:
verbose: true
comment_id: ${{ github.workflow }}-reporter
command_script_name: knip-ci
annotations: true
ignore_results: false
json_input: true
json_input_file_name: knip-results.json
pull_request_number: ${{ steps.pr-number.outputs.content }}
token: ${{ secrets.GITHUB_TOKEN }}
29 changes: 18 additions & 11 deletions .github/workflows/knip.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
name: Knip

on:
pull_request_target:
workflow_dispatch:

permissions: write-all
pull_request:

jobs:
run-knip:
Expand All @@ -13,6 +10,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

# needed to use yarn v4
- name: Enable corepack
run: corepack enable

- name: Setup Node
uses: actions/setup-node@v4
with:
Expand All @@ -21,11 +22,17 @@ jobs:
- name: Install toolchain
run: yarn install

- name: Report knip results to pull request
uses: Codex-/knip-reporter@v2
- name: Store PR number
run: echo ${{ github.event.number }} > pr-number.txt

- name: Run Knip
run: yarn knip || yarn knip --reporter json > knip-results.json

- name: Upload knip result
if: failure()
uses: actions/upload-artifact@v4
with:
verbose: true
comment_id: ${{ github.workflow }}-reporter
command_script_name: knip-ci
annotations: true
ignore_results: false
name: knip-results
path: |
knip-results.json
pr-number.txt

0 comments on commit c99c565

Please sign in to comment.