Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #101 from technote-space/feature/#97
Browse files Browse the repository at this point in the history
feat: add strict success flag (#97)
  • Loading branch information
technote-space committed Jun 2, 2022
2 parents ffba76d + 8f7b3c3 commit ea49915
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ inputs:
description: Fallback conclusion
required: false
default: skipped
STRICT_SUCCESS:
description: Whether to report as success only if all jobs are successful
required: false
default: "false"

outputs:
conclusion:
Expand Down
24 changes: 18 additions & 6 deletions src/process.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-magic-numbers */
import { resolve } from 'path';
import { Logger } from '@technote-space/github-action-log-helper';
import {
Expand Down Expand Up @@ -89,21 +88,34 @@ describe('getWorkflowConclusion', () => {

it('should get workflow conclusion', () => {
expect(getWorkflowConclusion([])).toBe('skipped');
expect(getWorkflowConclusion(['test'])).toBe('skipped');
expect(getWorkflowConclusion([
'neutral',
'success',
'cancelled',
'success',
])).toBe('cancelled');
expect(getWorkflowConclusion([
'failure',
'cancelled',
])).toBe('failure');
});

it('should get fallback conclusion 1', () => {
it('should get specified fallback conclusion', () => {
process.env.INPUT_FALLBACK_CONCLUSION = 'failure';
expect(getWorkflowConclusion([])).toBe('failure');
});

it('should get fallback conclusion 2', () => {
process.env.INPUT_FALLBACK_CONCLUSION = '';
expect(getWorkflowConclusion([])).toBe('');
it('should get workflow conclusion (strict success)', () => {
process.env.INPUT_STRICT_SUCCESS = 'true';
expect(getWorkflowConclusion(['success'])).toBe('success');
expect(getWorkflowConclusion(['success', 'success'])).toBe('success');

expect(getWorkflowConclusion(['skipped'])).toBe('failure');
expect(getWorkflowConclusion(['success', 'success', 'skipped'])).toBe('failure');
expect(getWorkflowConclusion([])).toBe('skipped');

process.env.INPUT_FALLBACK_CONCLUSION = 'failure';
expect(getWorkflowConclusion([])).toBe('failure');
});
});

Expand Down
7 changes: 5 additions & 2 deletions src/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ export const getJobConclusions = (jobs: Array<{ conclusion: string | null }>): A
.map(job => job.conclusion),
);

// eslint-disable-next-line no-magic-numbers
export const getWorkflowConclusion = (conclusions: Array<string>): string => CONCLUSIONS.filter(conclusion => conclusions.includes(conclusion)).slice(-1)[0] ?? getInput('FALLBACK_CONCLUSION');
export const getWorkflowConclusion = (conclusions: Array<string>): string =>
!conclusions.length ? getInput('FALLBACK_CONCLUSION') :
Utils.getBoolValue(getInput('STRICT_SUCCESS')) ?
conclusions.some(conclusion => conclusion !== 'success') ? 'failure' : 'success' :
CONCLUSIONS.filter(conclusion => conclusions.includes(conclusion)).slice(-1)[0] ?? getInput('FALLBACK_CONCLUSION');

export const execute = async(logger: Logger, octokit: Octokit, context: Context): Promise<void> => {
const jobs = await getJobs(octokit, context);
Expand Down

0 comments on commit ea49915

Please sign in to comment.