Skip to content

Commit

Permalink
Merge pull request #70 from Quramy/check_file_exist
Browse files Browse the repository at this point in the history
fix: Check summary json file exsit
  • Loading branch information
Quramy authored May 30, 2023
2 parents 5522ff1 + 631ba6d commit cfed313
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,14 @@ jobs:
### Custom coverage-diff options
check-criteria: lines
coverage-threshold: 80

- name: Test action.yaml (ENOTENT)
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
base-summary-json: coverage/coverage-summary-base.json
head-summary-json: coverage/not-existing-coverage-summary.json
body-header: |
### Custom coverage-diff options
check-criteria: lines
coverage-threshold: 80
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { cwd } from "node:process"
import { relative } from "node:path"
import { existsSync } from "node:fs"
import { readFile } from "node:fs/promises"
import { getInput, info } from "@actions/core"
import { getOctokit, context } from "@actions/github"
Expand Down Expand Up @@ -36,6 +37,15 @@ async function main() {
const coverageDecreaseThreshold = toInt(getInput("coverage-decrease-threshold"))
const newFileCoverageThreshold = toInt(getInput("new-file-coverage-threshold"))

if (!existsSync(headSummaryJsonFilename)) {
info(`Skip because ${headSummaryJsonFilename} does not exist`)
return
}
if (!existsSync(baseSummaryJsonFileName)) {
info(`Skip bacause ${baseSummaryJsonFileName} does not exist`)
return
}

const headSummary = JSON.parse(await readFile(headSummaryJsonFilename, "utf-8")) as JsonSummary
const baseSummary = JSON.parse(await readFile(baseSummaryJsonFileName, "utf-8")) as JsonSummary

Expand Down

0 comments on commit cfed313

Please sign in to comment.