Skip to content

Commit

Permalink
download report.xml to local filesystem even when DTP publishing is d…
Browse files Browse the repository at this point in the history
…isabled
  • Loading branch information
mattloveparasoft committed May 27, 2021
1 parent 8c7d862 commit 1899d36
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 132 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@ Add the following entry to your Github workflow YAML file with the required inpu
```yaml
uses: parasoft/execute-job-action@v1
with:
ctpUrl: 'http://exampleUrl'
ctpUrl: 'http://ctp.mycompany.org:8080/em/'
ctpUsername: 'username'
ctpPassword: ${{ secrets.password }}
ctpJob: 'Example Job'
abortOnTimeout: false
timeoutInMinutes: 5
publishReport: false
dtpUrl: 'http://dtp.mycompany.org:8080/grs/'
dtpUsername: 'username'
dtpPassword: ${{ secrets.password }}
dtpProject: 'My Project'
buildId: ${{ github.run_number }}
sessionTag: ${{ github.workflow }}
appendEnvironment: false
```
### Required Inputs
The following inputs are required:
Expand Down
2 changes: 1 addition & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ test('test runs', () => {
process.env['INPUT_CTPUSERNAME'] = 'demo'
process.env['INPUT_CTPPASSWORD'] = 'demo-user'
process.env['INPUT_CTPJOB'] = 'P1 Smoke Tests'
process.env['INPUT_PUBLISHREPORT'] = 'true'
process.env['INPUT_PUBLISHREPORT'] = 'false'
process.env['INPUT_DTPURL'] = 'http://18.236.243.147:8080/grs/'
process.env['INPUT_DTPUSERNAME'] = 'demo'
process.env['INPUT_DTPPASSWORD'] = 'demo-user'
Expand Down
104 changes: 40 additions & 64 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "execute-job-action",
"version": "1.0.6",
"version": "1.0.7",
"private": true,
"description": "Run a test execution job with Parasoft Continuous Testing Platform (CTP)",
"main": "lib/main.js",
Expand Down
75 changes: 30 additions & 45 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,20 @@ export async function run() {
let dtpService = null;
const publish = core.getInput('publishReport') === 'true';
const dtpEndpoint = core.getInput('dtpUrl', { required: false });
var dtpAuthorization: service.Authorization = null;
if (dtpEndpoint) {
dtpAuthorization = { username: core.getInput('dtpUsername'), password: core.getInput('dtpPassword') };
}
const dtpProject = core.getInput('dtpProject');
const dtpBuildId = core.getInput('buildId');
let dtpSessionTag = core.getInput('sessionTag');
const appendEnvironment = core.getInput('appendEnvironment') === 'true';
let metaData: report.ReportMetaData = {
dtpProject: dtpProject,
dtpBuildId: dtpBuildId,
dtpSessionTag: dtpSessionTag,
appendEnvironment : appendEnvironment
}
if (dtpEndpoint && publish) {
let metaData: report.ReportMetaData = {
dtpProject: dtpProject,
dtpBuildId: dtpBuildId,
dtpSessionTag: dtpSessionTag,
appendEnvironment : appendEnvironment
}
dtpService = new report.ReportPublisher(dtpEndpoint, 'grs', ctpService, metaData, dtpAuthorization);
dtpService = new service.WebService(dtpEndpoint, 'grs', { username: core.getInput('dtpUsername'), password: core.getInput('dtpPassword') });
}
let reportController = new report.ReportController(ctpService, dtpService, metaData);
const abortOnTimout = core.getInput('abortOnTimeout') === 'true';
const timeout = core.getInput('timeoutInMinutes');
const jobName = core.getInput('ctpJob', { required: true });
Expand Down Expand Up @@ -84,45 +81,33 @@ export async function run() {
}
if (status === 'RUNNING' || status === 'WAITING') {
setTimeout(checkStatus, 1000);
} else if (status === 'PASSED') {
core.info('All tests passed.');
if (dtpService) {
let environmentNames = extractEnvironmentNames(job);
res.reportIds.forEach((reportId, index) => {
dtpService.publishReport(reportId, index, environmentNames.length > 0 ? environmentNames.shift() : null).catch((err) => {
core.error("Failed to publish report to DTP");
}).then(() => {
if (index === 0) {
console.log(' View results in DTP: ' + dtpService.getBaseURL() + '/dtp/explorers/test?buildId=' + dtpBuildId);
}
});
});
} else {
res.reportIds.forEach((reportId, index) => {
core.info(` View report in CTP: ${ctpService.getBaseURL()}/testreport/${reportId}/report.html`);
});
}
} else if (status === 'CANCELED') {
core.warning('Test execution was canceled.');
} else {
core.error('Some tests failed.');
if (dtpService) {
res.reportIds.forEach((reportId, index) => {
let environmentNames = extractEnvironmentNames(job);
dtpService.publishReport(reportId, index, environmentNames.length > 0 ? environmentNames.shift() : null).catch((err) => {
core.error("Failed to publish report to DTP");
}).then(() => {
if (index === 0) {
console.log(' View results in DTP: ' + dtpService.getBaseURL() + '/dtp/explorers/test?buildId=' + dtpBuildId);
}
});
});
if (status === 'PASSED') {
core.info('All tests passed.');
} else {
res.reportIds.forEach((reportId, index) => {
core.info(` View report in CTP: ${ctpService.getBaseURL()}/testreport/${reportId}/report.html`);
});
core.setFailed('Some tests failed.');
}
core.setFailed('Job "' + jobName + '" failed.');
let environmentNames = extractEnvironmentNames(job);
res.reportIds.forEach((reportId, index) => {
let downloadPromise = reportController.downloadReport(reportId, index, environmentNames.length > 0 ? environmentNames.shift() : null).catch((err) => {
core.error("Failed to download report from CTP");
});
if (dtpService) {
downloadPromise.then(() => {
reportController.uploadFile(reportId).then(response => {
core.debug(` report.xml file upload successful: ${response}`);
if (index === 0) {
core.info(' View results in DTP: ' + dtpService.getBaseURL() + '/dtp/explorers/test?buildId=' + dtpBuildId);
}
}).catch((error) => {
core.error(`Error while uploading report.xml file: ${error}`);
core.error("Failed to publish report to DTP");
});
});
}
});
}
});
};
Expand Down
Loading

0 comments on commit 1899d36

Please sign in to comment.