fix: only push results when the url is set

This commit is contained in:
A.J. Kaptijn 2024-02-09 10:55:38 +01:00
parent 108abd4de9
commit 59060a80a8
2 changed files with 42 additions and 38 deletions

36
dist/index.js generated vendored
View file

@ -192,7 +192,7 @@ class TestReporter {
} }
} }
run() { run() {
var _a; var _a, _b;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
if (this.workDirInput) { if (this.workDirInput) {
core.info(`Changing directory to '${this.workDirInput}'`); core.info(`Changing directory to '${this.workDirInput}'`);
@ -218,21 +218,23 @@ class TestReporter {
const parser = this.getParser(this.reporter, options); const parser = this.getParser(this.reporter, options);
const results = []; const results = [];
const input = yield inputProvider.load(); const input = yield inputProvider.load();
try { if (((_a = this.resultsEndpoint) === null || _a === void 0 ? void 0 : _a.length) > 0) {
const readStream = input.trxZip.toBuffer(); try {
const version = fs_1.default.existsSync('test/EVA.TestSuite.Core/bin/Release/version.txt') const readStream = input.trxZip.toBuffer();
? fs_1.default.readFileSync('test/EVA.TestSuite.Core/bin/Release/version.txt').toString() const version = fs_1.default.existsSync('test/EVA.TestSuite.Core/bin/Release/version.txt')
: null; ? fs_1.default.readFileSync('test/EVA.TestSuite.Core/bin/Release/version.txt').toString()
const commitID = fs_1.default.existsSync('test/EVA.TestSuite.Core/bin/Release/commit.txt') : null;
? fs_1.default.readFileSync('test/EVA.TestSuite.Core/bin/Release/commit.txt').toString() const commitID = fs_1.default.existsSync('test/EVA.TestSuite.Core/bin/Release/commit.txt')
: null; ? fs_1.default.readFileSync('test/EVA.TestSuite.Core/bin/Release/commit.txt').toString()
core.info(`Using EVA version ${version}, commit ${commitID}, branch ${this.context.branch}, current directory: ${(0, process_1.cwd)()}`); : null;
const post = (0, bent_1.default)(this.resultsEndpoint, 'POST', {}, 200); core.info(`Using EVA version ${version}, commit ${commitID}, branch ${this.context.branch}, current directory: ${(0, process_1.cwd)()}`);
yield post(`TestResults?Secret=${this.resultsEndpointSecret}${version ? '&EVAVersion=' + version : ''}${commitID ? '&EVACommitID=' + commitID : ''}&EVABranch=${encodeURI(this.context.branch)}`, readStream); const post = (0, bent_1.default)(this.resultsEndpoint, 'POST', {}, 200);
core.info(`Uploaded TRX files`); yield post(`TestResults?Secret=${this.resultsEndpointSecret}${version ? '&EVAVersion=' + version : ''}${commitID ? '&EVACommitID=' + commitID : ''}&EVABranch=${encodeURI(this.context.branch)}`, readStream);
} core.info(`Uploaded TRX files`);
catch (ex) { }
core.warning(`Could not upload TRX ZIP file: ${ex}`); catch (ex) {
core.warning(`Could not upload TRX ZIP file: ${ex}`);
}
} }
for (const [reportName, files] of Object.entries(input.reports)) { for (const [reportName, files] of Object.entries(input.reports)) {
try { try {
@ -270,7 +272,7 @@ class TestReporter {
core.endGroup(); core.endGroup();
return; return;
} }
core.info(`${t.name}: ${(_a = t.error) === null || _a === void 0 ? void 0 : _a.message}`); core.info(`${t.name}: ${(_b = t.error) === null || _b === void 0 ? void 0 : _b.message}`);
} }
} }
} }

View file

@ -105,29 +105,31 @@ class TestReporter {
const results: TestRunResultWithUrl[] = [] const results: TestRunResultWithUrl[] = []
const input = await inputProvider.load() const input = await inputProvider.load()
try { if (this.resultsEndpoint?.length > 0) {
const readStream = input.trxZip.toBuffer() try {
const version = fs.existsSync('test/EVA.TestSuite.Core/bin/Release/version.txt') const readStream = input.trxZip.toBuffer()
? fs.readFileSync('test/EVA.TestSuite.Core/bin/Release/version.txt').toString() const version = fs.existsSync('test/EVA.TestSuite.Core/bin/Release/version.txt')
: null ? fs.readFileSync('test/EVA.TestSuite.Core/bin/Release/version.txt').toString()
const commitID = fs.existsSync('test/EVA.TestSuite.Core/bin/Release/commit.txt') : null
? fs.readFileSync('test/EVA.TestSuite.Core/bin/Release/commit.txt').toString() const commitID = fs.existsSync('test/EVA.TestSuite.Core/bin/Release/commit.txt')
: null ? fs.readFileSync('test/EVA.TestSuite.Core/bin/Release/commit.txt').toString()
: null
core.info( core.info(
`Using EVA version ${version}, commit ${commitID}, branch ${this.context.branch}, current directory: ${cwd()}` `Using EVA version ${version}, commit ${commitID}, branch ${this.context.branch}, current directory: ${cwd()}`
) )
const post = bent(this.resultsEndpoint, 'POST', {}, 200) const post = bent(this.resultsEndpoint, 'POST', {}, 200)
await post( await post(
`TestResults?Secret=${this.resultsEndpointSecret}${version ? '&EVAVersion=' + version : ''}${ `TestResults?Secret=${this.resultsEndpointSecret}${version ? '&EVAVersion=' + version : ''}${
commitID ? '&EVACommitID=' + commitID : '' commitID ? '&EVACommitID=' + commitID : ''
}&EVABranch=${encodeURI(this.context.branch)}`, }&EVABranch=${encodeURI(this.context.branch)}`,
readStream readStream
) )
core.info(`Uploaded TRX files`) core.info(`Uploaded TRX files`)
} catch (ex) { } catch (ex) {
core.warning(`Could not upload TRX ZIP file: ${ex}`) core.warning(`Could not upload TRX ZIP file: ${ex}`)
}
} }
for (const [reportName, files] of Object.entries(input.reports)) { for (const [reportName, files] of Object.entries(input.reports)) {