Skip to content

Commit

Permalink
Optional concurrent skipping (#51)
Browse files Browse the repository at this point in the history
* Optional concurrent skipping

* Typo

* Disable duplicate builds
  • Loading branch information
fkirc authored Oct 25, 2020
1 parent 9a62635 commit 6c53680
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
on:
push:
pull_request:
workflow_dispatch:
schedule:
- cron: '0 12 18 * *'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
paths_ignore: '["**/*.md"]'
cancel_others: 'true'
do_not_skip: '["pull_request", "workflow_dispatch", "schedule"]'
concurrent_skipping: 'true'
- if: ${{ steps.skip_check.outputs.should_skip == 'false' }}
run: |
echo "Do stuff..." && sleep 30
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ If true, then workflow-runs from outdated commits will be cancelled. Default `tr

A JSON-array with triggers that should never be skipped. Default `'["workflow_dispatch", "schedule"]'`.

### `concurrent_skipping`

If false, unfinished workflow-runs will be safely ignored. Default `true`.

## Outputs

### `should_skip`
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ inputs:
description: 'A JSON-array with triggers that should never be skipped'
required: false
default: '["workflow_dispatch", "schedule"]'
concurrent_skipping:
description: 'If false, unfinished workflow-runs will be safely ignored'
required: false
default: 'true'

outputs:
should_skip:
Expand Down
6 changes: 5 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9955,6 +9955,7 @@ async function main() {
pathsIgnore: getStringArrayInput("paths_ignore"),
paths: getStringArrayInput("paths"),
doNotSkip: getStringArrayInput("do_not_skip"),
concurrentSkipping: getBooleanInput("concurrent_skipping", true),
};
}
catch (e) {
Expand Down Expand Up @@ -10028,12 +10029,15 @@ function detectDuplicateRuns(context) {
}
return true;
});
if (concurrentDuplicate) {
if (concurrentDuplicate && context.concurrentSkipping) {
core.info(`Skip execution because the exact same files are concurrently checked in ${concurrentDuplicate.html_url}`);
exitSuccess({ shouldSkip: true });
}
}
function detectExplicitConcurrentTrigger(context) {
if (!context.concurrentSkipping) {
return;
}
const duplicateTriggerRun = context.allRuns.find((run) => {
if (run.treeHash !== context.currentRun.treeHash) {
return false;
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface WRunContext {
pathsIgnore: string[];
paths: string[];
doNotSkip: WRunTrigger[];
concurrentSkipping: boolean;
}

function parseWorkflowRun(run: ActionsGetWorkflowRunResponseData): WorkflowRun {
Expand Down Expand Up @@ -117,6 +118,7 @@ async function main() {
pathsIgnore: getStringArrayInput("paths_ignore"),
paths: getStringArrayInput("paths"),
doNotSkip: getStringArrayInput("do_not_skip") as WRunTrigger[],
concurrentSkipping: getBooleanInput("concurrent_skipping", true),
};
} catch (e) {
core.warning(e);
Expand Down Expand Up @@ -193,13 +195,16 @@ function detectDuplicateRuns(context: WRunContext) {
}
return true;
});
if (concurrentDuplicate) {
if (concurrentDuplicate && context.concurrentSkipping) {
core.info(`Skip execution because the exact same files are concurrently checked in ${concurrentDuplicate.html_url}`);
exitSuccess({ shouldSkip: true });
}
}

function detectExplicitConcurrentTrigger(context: WRunContext) {
if (!context.concurrentSkipping) {
return;
}
const duplicateTriggerRun = context.allRuns.find((run) => {
if (run.treeHash !== context.currentRun.treeHash) {
return false;
Expand Down

0 comments on commit 6c53680

Please sign in to comment.