Skip to content

Commit

Permalink
feat: add fail job capability
Browse files Browse the repository at this point in the history
  • Loading branch information
deblockt committed Aug 25, 2022
1 parent ef4595b commit d45e603
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,20 @@ jobs:
name: "success empty report"
access-token: ${{ secrets.GITHUB_TOKEN }}
path: "**/cucumber-report-empty.json"
- uses: ./
id: job-failed
continue-on-error: true
name: "fail job due to failed test"
with:
name: "fail job due to failed test"
access-token: ${{ secrets.GITHUB_TOKEN }}
path: "**/cucumber-report-non-failed.json"
check-status-on-pending: "failure"
annotation-status-on-pending: "failure"
number-of-test-error-to-fail-job: 1
- name: 'check that job-failed outcome is failed'
if: steps.job-failed.outcome == 'failure'
run: exit 0
- name: 'check that job-failed outcome is failed'
if: steps.job-failed.outcome != 'failure'
run: exit 1
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ inputs:
description: "if it is set to true, the number of errors will be indicated on the check title (visible on the pr check)"
require: true
default: 'true'
number-of-test-error-to-fail-job:
description: "indicate the number of test in error to fail the build. If the value is -1 this action will never fail the build."
require: true
default: -1
name:
description: "the name of the check"
require: true
Expand Down
9 changes: 7 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12974,6 +12974,7 @@ async function buildPendingAnnotation(cucumberError, statusOnPending) {
const annotationStatusOnUndefined = core.getInput('annotation-status-on-undefined');
const annotationStatusOnPending = core.getInput('annotation-status-on-pending');
const showNumberOfErrorOnCheckTitle = core.getInput('show-number-of-error-on-check-title');
const numberOfTestErrorToFailJob = core.getInput('number-of-test-error-to-fail-job');

const globber = await glob.create(inputPath, {
followSymbolicLinks: false,
Expand Down Expand Up @@ -13020,11 +13021,11 @@ async function buildPendingAnnotation(cucumberError, statusOnPending) {
}

// TODO make an update request if there are more than 50 annotations
errorAnnotations = errorAnnotations.slice(0, 49);
const errorAnnotationsToCreate = errorAnnotations.slice(0, 49);
const pullRequest = github.context.payload.pull_request;
const head_sha = (pullRequest && pullRequest.head.sha) || github.context.sha;
const annotations = [
...errorAnnotations
...errorAnnotationsToCreate
];

var additionnalTitleInfo = '';
Expand Down Expand Up @@ -13063,6 +13064,10 @@ async function buildPendingAnnotation(cucumberError, statusOnPending) {
core.info('Sending cucumber annotations');
const octokit = github.getOctokit(accessToken);
await octokit.checks.create(createCheckRequest);

if (numberOfTestErrorToFailJob != -1 && errorAnnotations.length >= numberOfTestErrorToFailJob) {
core.setFailed(`${errorAnnotations.length} test(s) in error`);
}
}
})();

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

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ async function buildPendingAnnotation(cucumberError, statusOnPending) {
const annotationStatusOnUndefined = core.getInput('annotation-status-on-undefined');
const annotationStatusOnPending = core.getInput('annotation-status-on-pending');
const showNumberOfErrorOnCheckTitle = core.getInput('show-number-of-error-on-check-title');
const numberOfTestErrorToFailJob = core.getInput('number-of-test-error-to-fail-job');

const globber = await glob.create(inputPath, {
followSymbolicLinks: false,
Expand Down Expand Up @@ -119,11 +120,11 @@ async function buildPendingAnnotation(cucumberError, statusOnPending) {
}

// TODO make an update request if there are more than 50 annotations
errorAnnotations = errorAnnotations.slice(0, 49);
const errorAnnotationsToCreate = errorAnnotations.slice(0, 49);
const pullRequest = github.context.payload.pull_request;
const head_sha = (pullRequest && pullRequest.head.sha) || github.context.sha;
const annotations = [
...errorAnnotations
...errorAnnotationsToCreate
];

var additionnalTitleInfo = '';
Expand Down Expand Up @@ -162,6 +163,10 @@ async function buildPendingAnnotation(cucumberError, statusOnPending) {
core.info('Sending cucumber annotations');
const octokit = github.getOctokit(accessToken);
await octokit.checks.create(createCheckRequest);

if (numberOfTestErrorToFailJob != -1 && errorAnnotations.length >= numberOfTestErrorToFailJob) {
core.setFailed(`${errorAnnotations.length} test(s) in error`);
}
}
})();

Expand Down

0 comments on commit d45e603

Please sign in to comment.