Skip to content

Commit 6c2192e

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

File tree

5 files changed

+44
-27
lines changed

5 files changed

+44
-27
lines changed

dist/index.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113322,7 +113322,7 @@ const run = async (isLocal) => {
113322113322
: undefined;
113323113323
if (createComment)
113324113324
(0, comment_1.postComment)(octokit, comment, github_1.context);
113325-
await (0, push_1.push)();
113325+
await (0, push_1.push)(exports.COVERAGE_DIR);
113326113326
if (analyzeStr?.error || testStr?.error || coverageStr?.error) {
113327113327
(0, core_1.setFailed)(`${analyzeStr?.output}\n${testStr?.output}\n${coverageStr?.output}`);
113328113328
}
@@ -113687,6 +113687,7 @@ const artifact_1 = __nccwpck_require__(26984);
113687113687
const core_1 = __nccwpck_require__(72614);
113688113688
const core_2 = __nccwpck_require__(72614);
113689113689
const adm_zip_1 = __importDefault(__nccwpck_require__(98154));
113690+
const runTests_1 = __nccwpck_require__(99054);
113690113691
const ARTIFACT_NAME = "coverage";
113691113692
/**
113692113693
* Retrieve previous coverage report from the base branch
@@ -113768,13 +113769,21 @@ exports.retrievePreviousCoverage = retrievePreviousCoverage;
113768113769
const generatePreviousCoverage = async (prev_sha, current_branch, coverage_directory) => {
113769113770
const artifact = new artifact_1.DefaultArtifactClient();
113770113771
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;
113772+
let report;
113773+
try {
113774+
await (0, runTests_1.getTest)(coverage_directory);
113775+
report = await (0, utils_1.importLcov)(coverage_directory);
113776+
const { id, size } = await artifact.uploadArtifact(ARTIFACT_NAME + "-" + prev_sha, [`${coverage_directory}/${utils_1.COV_FILE}`], ".", {});
113777+
(0, core_2.debug)(`Artifact uploaded with id: ${id} and size: ${size}`);
113778+
}
113779+
catch (e) {
113780+
console.error("Failed to run tests");
113781+
}
113782+
finally {
113783+
await (0, exec_1.exec)(`git reset --hard`);
113784+
await (0, exec_1.exec)(`git checkout ${current_branch}`);
113785+
return report;
113786+
}
113778113787
};
113779113788

113780113789

@@ -113794,7 +113803,7 @@ const core_2 = __nccwpck_require__(72614);
113794113803
/**
113795113804
* Push changes to the branch
113796113805
*/
113797-
const push = async () => {
113806+
const push = async (coverageDirectory) => {
113798113807
(0, core_1.startGroup)("Check for changes");
113799113808
let stdout = "";
113800113809
try {
@@ -113812,7 +113821,7 @@ const push = async () => {
113812113821
(0, core_1.startGroup)("Push changes");
113813113822
await (0, exec_1.exec)('git config --global user.name "github-actions"');
113814113823
await (0, exec_1.exec)('git config --global user.email "[email protected]"');
113815-
await (0, exec_1.exec)("git add -A");
113824+
await (0, exec_1.exec)(`git add -A -- ':!${coverageDirectory}`);
113816113825
(0, child_process_1.execSync)(`git commit -m 'chore(automated): Lint commit and format' `);
113817113826
await (0, exec_1.exec)("git push -f");
113818113827
(0, core_2.debug)("Changes pushed onto branch");

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const run = async (isLocal: boolean) => {
5454

5555
if (createComment) postComment(octokit, comment!, context);
5656

57-
await push();
57+
await push(COVERAGE_DIR);
5858

5959
if (analyzeStr?.error || testStr?.error || coverageStr?.error) {
6060
setFailed(`${analyzeStr?.output}\n${testStr?.output}\n${coverageStr?.output}`);

src/scripts/coverage.ts

Lines changed: 1 addition & 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";

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
};

src/scripts/push.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { debug } from "@actions/core";
66
/**
77
* Push changes to the branch
88
*/
9-
export const push = async () => {
9+
export const push = async (coverageDirectory: string) => {
1010
startGroup("Check for changes");
1111
let stdout: string = "";
1212
try {
@@ -24,7 +24,7 @@ export const push = async () => {
2424
startGroup("Push changes");
2525
await exec('git config --global user.name "github-actions"');
2626
await exec('git config --global user.email "[email protected]"');
27-
await exec("git add -A");
27+
await exec(`git add -A -- ':!${coverageDirectory}`);
2828
execSync(`git commit -m 'chore(automated): Lint commit and format' `);
2929
await exec("git push -f");
3030
debug("Changes pushed onto branch");

0 commit comments

Comments
 (0)