Skip to content

Commit 6a7417d

Browse files
committed
fix: Action fails when previous commit had a failing test
1 parent 1a53f5d commit 6a7417d

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed

dist/index.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113661,6 +113661,7 @@ const getCoverage = (prevCoverage, coverageDirectory) => {
113661113661
console.error("Error checking coverage", error);
113662113662
response = { output: exports.COV_FAILURE, error: true };
113663113663
}
113664+
(0, node_fs_1.unlinkSync)(`${coverageDirectory}/lcov.info`);
113664113665
(0, core_2.debug)("Finished checking coverage; generated response");
113665113666
(0, core_1.endGroup)();
113666113667
return response;
@@ -113687,6 +113688,7 @@ const artifact_1 = __nccwpck_require__(26984);
113687113688
const core_1 = __nccwpck_require__(72614);
113688113689
const core_2 = __nccwpck_require__(72614);
113689113690
const adm_zip_1 = __importDefault(__nccwpck_require__(98154));
113691+
const runTests_1 = __nccwpck_require__(99054);
113690113692
const ARTIFACT_NAME = "coverage";
113691113693
/**
113692113694
* Retrieve previous coverage report from the base branch
@@ -113768,13 +113770,21 @@ exports.retrievePreviousCoverage = retrievePreviousCoverage;
113768113770
const generatePreviousCoverage = async (prev_sha, current_branch, coverage_directory) => {
113769113771
const artifact = new artifact_1.DefaultArtifactClient();
113770113772
await (0, exec_1.exec)(`git checkout ${prev_sha}`);
113771-
await (0, exec_1.exec)(`flutter test --coverage --coverage-path ${coverage_directory}/lcov.info`);
113772-
const report = await (0, utils_1.importLcov)(coverage_directory);
113773-
const { id, size } = await artifact.uploadArtifact(ARTIFACT_NAME + "-" + prev_sha, [`${coverage_directory}/${utils_1.COV_FILE}`], ".", {});
113774-
(0, core_2.debug)(`Artifact uploaded with id: ${id} and size: ${size}`);
113775-
await (0, exec_1.exec)(`git reset --hard`);
113776-
await (0, exec_1.exec)(`git checkout ${current_branch}`);
113777-
return report;
113773+
let report;
113774+
try {
113775+
await (0, runTests_1.getTest)(coverage_directory);
113776+
report = await (0, utils_1.importLcov)(coverage_directory);
113777+
const { id, size } = await artifact.uploadArtifact(ARTIFACT_NAME + "-" + prev_sha, [`${coverage_directory}/${utils_1.COV_FILE}`], ".", {});
113778+
(0, core_2.debug)(`Artifact uploaded with id: ${id} and size: ${size}`);
113779+
}
113780+
catch (e) {
113781+
console.error("Failed to run tests");
113782+
}
113783+
finally {
113784+
await (0, exec_1.exec)(`git reset --hard`);
113785+
await (0, exec_1.exec)(`git checkout ${current_branch}`);
113786+
return report;
113787+
}
113778113788
};
113779113789

113780113790

src/scripts/coverage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Lcov, LcovDigest, parse, sum } from "lcov-utils";
2-
import { readFileSync } from "node:fs";
2+
import { readFileSync, unlinkSync } from "node:fs";
33
import { endGroup, startGroup } from "@actions/core";
44
import { stepResponse } from "../main";
55
import { debug } from "@actions/core";
@@ -62,6 +62,7 @@ export const getCoverage = (prevCoverage: Lcov | undefined, coverageDirectory: s
6262
console.error("Error checking coverage", error);
6363
response = { output: COV_FAILURE, error: true };
6464
}
65+
unlinkSync(`${coverageDirectory}/lcov.info`);
6566
debug("Finished checking coverage; generated response");
6667
endGroup();
6768
return response;

src/scripts/prevCoverage.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { DefaultArtifactClient } from "@actions/artifact";
77
import { endGroup, startGroup } from "@actions/core";
88
import { debug } from "@actions/core";
99
import AdmZip from "adm-zip";
10+
import { getTest } from "./runTests";
1011

1112
const ARTIFACT_NAME = "coverage";
1213

@@ -104,20 +105,27 @@ const generatePreviousCoverage = async (
104105
prev_sha: string,
105106
current_branch: string,
106107
coverage_directory: string
107-
): Promise<Lcov> => {
108+
): Promise<Lcov | undefined> => {
108109
const artifact = new DefaultArtifactClient();
109110
await exec(`git checkout ${prev_sha}`);
110-
await exec(`flutter test --coverage --coverage-path ${coverage_directory}/lcov.info`);
111-
const report = await importLcov(coverage_directory);
112-
const { id, size } = await artifact.uploadArtifact(
113-
ARTIFACT_NAME + "-" + prev_sha,
114-
[`${coverage_directory}/${COV_FILE}`],
115-
".",
116-
{}
117-
);
111+
let report: Lcov | undefined;
112+
try {
113+
await getTest(coverage_directory);
114+
report = await importLcov(coverage_directory);
118115

119-
debug(`Artifact uploaded with id: ${id} and size: ${size}`);
120-
await exec(`git reset --hard`);
121-
await exec(`git checkout ${current_branch}`);
122-
return report;
116+
const { id, size } = await artifact.uploadArtifact(
117+
ARTIFACT_NAME + "-" + prev_sha,
118+
[`${coverage_directory}/${COV_FILE}`],
119+
".",
120+
{}
121+
);
122+
123+
debug(`Artifact uploaded with id: ${id} and size: ${size}`);
124+
} catch (e) {
125+
console.error("Failed to run tests");
126+
} finally {
127+
await exec(`git reset --hard`);
128+
await exec(`git checkout ${current_branch}`);
129+
return report;
130+
}
123131
};

0 commit comments

Comments
 (0)