Skip to content

Commit

Permalink
fix: updated jest and knip workflow to work on pull_request event i…
Browse files Browse the repository at this point in the history
…nstead of target
  • Loading branch information
gentlementlegen committed Jul 16, 2024
1 parent dbed05d commit e1043b1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 24 deletions.
20 changes: 9 additions & 11 deletions .github/workflows/jest-testing.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
name: Run Jest testing suite
on:
workflow_dispatch:
workflow_run:
workflows: ["Knip"]
types:
- completed
pull_request:

env:
NODE_ENV: "test"
SUPABASE_URL: "http://127.0.0.1:3000"
SUPABASE_KEY: "supabase-key"

jobs:
testing:
Expand All @@ -21,14 +20,13 @@ jobs:
- uses: actions/checkout@master
with:
fetch-depth: 0

- name: Enable corepack
run: corepack enable

- name: Jest With Coverage Comment
# Ensures this step is run even on previous step failure (e.g. test failed)
- name: Jest With Coverage
run: yarn install --immutable --immutable-cache --check-cache && yarn test

- name: Add Jest Report to Summary
if: always()
uses: ArtiomTr/jest-coverage-report-action@v2
with:
package-manager: yarn
prnumber: ${{ github.event.pull_request.number || github.event.workflow_run.pull_requests[0].number }}
run: echo "$(cat test-dashboard.md)" >> $GITHUB_STEP_SUMMARY
40 changes: 40 additions & 0 deletions .github/workflows/knip-reporter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Knip-reporter

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

permissions: write-all

jobs:
knip-reporter:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion != 'success' }}
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
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 }}
27 changes: 14 additions & 13 deletions .github/workflows/knip.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
name: Knip

on:
pull_request_target:
pull_request:
workflow_dispatch:

permissions: write-all

jobs:
run-knip:
runs-on: ubuntu-latest
Expand All @@ -17,18 +15,21 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20.10.0

- name: Enable corepack
run: corepack enable

- 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 e1043b1

Please sign in to comment.