Skip to content

Commit

Permalink
Skip outdated runs (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
fkirc committed Dec 15, 2020
1 parent f05289c commit 4aa7907
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -54,7 +54,7 @@ jobs:
github_token: ${{ github.token }}
paths_ignore: '["**/*.md"]'
cancel_others: 'true'
concurrent_skipping: 'always'
concurrent_skipping: 'outdated_runs'
do_not_skip: '["pull_request", "workflow_dispatch", "schedule"]'
- if: ${{ steps.skip_check.outputs.should_skip == 'false' }}
run: |
Expand Down
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -29,8 +29,10 @@ Sometimes, there are workflows that you do not want to run twice at the same tim
Therefore, `skip-duplicate-actions` provides the following options to skip a workflow-run if the same workflow is already running:

- **Always skip:** This is useful if you have a workflow that you never want to run twice at the same time.
In contrast to the [cancel_others](#cancel-outdated-workflow-runs) option, this option lets the older run finish.
In contrast to the [cancel_others](#cancel-outdated-workflow-runs) option, this option allows older runs to finish.
- **Only skip same content:** For example, this can be useful if a workflow has both a `push` and a `pull_request` trigger, or if you push a tag right after pushing a commit.
- **Only skip outdated runs:** For example, this can be useful for skip-checks that are not at the beginning of a job.
In contrast to the [cancel_others](#cancel-outdated-workflow-runs) option, this option skips at pre-defined places instead of cancelling at arbitrary places.
- **Never skip:** This disables the concurrent skipping functionality, but still lets you use all other options like duplicate skipping.

## Skip ignored paths
Expand Down Expand Up @@ -92,7 +94,7 @@ A JSON-array with triggers that should never be skipped. Default `'["workflow_di

### `concurrent_skipping`

One of `never`, `same_content`, `always`. Default `never`.
One of `never`, `same_content`, `outdated_runs`, `always`. Default `never`.

## Outputs

Expand Down
2 changes: 1 addition & 1 deletion action.yml
Expand Up @@ -26,7 +26,7 @@ inputs:
required: false
default: '["workflow_dispatch", "schedule"]'
concurrent_skipping:
description: 'One of never, same_content, always'
description: 'One of never, same_content, outdated_runs, always'
required: true
default: 'never'

Expand Down
20 changes: 14 additions & 6 deletions dist/index.js
Expand Up @@ -9883,6 +9883,7 @@ const micromatch = __webpack_require__(6228);
const concurrentSkippingMap = {
"always": null,
"same_content": null,
"outdated_runs": null,
"never": null,
};
function getConcurrentSkippingOptions() {
Expand Down Expand Up @@ -10047,14 +10048,21 @@ function detectConcurrentRuns(context) {
core.info(`Skip execution because another instance of the same workflow is already running in ${concurrentRuns[0].html_url}`);
exitSuccess({ shouldSkip: true });
}
const concurrentDuplicate = concurrentRuns.find((run) => run.treeHash === context.currentRun.treeHash);
if (concurrentDuplicate) {
core.info(`Skip execution because the exact same files are concurrently checked in ${concurrentDuplicate.html_url}`);
exitSuccess({ shouldSkip: true });
else if (context.concurrentSkipping === "outdated_runs") {
const newerRun = concurrentRuns.find((run) => new Date(run.createdAt).getTime() > new Date(context.currentRun.createdAt).getTime());
if (newerRun) {
core.info(`Skip execution because a newer instance of the same workflow is running in ${newerRun.html_url}`);
exitSuccess({ shouldSkip: true });
}
}
else {
core.info(`Did not find any duplicate concurrent workflow-runs`);
else if (context.concurrentSkipping === "same_content") {
const concurrentDuplicate = concurrentRuns.find((run) => run.treeHash === context.currentRun.treeHash);
if (concurrentDuplicate) {
core.info(`Skip execution because the exact same files are concurrently checked in ${concurrentDuplicate.html_url}`);
exitSuccess({ shouldSkip: true });
}
}
core.info(`Did not find any skippable concurrent workflow-runs`);
}
async function backtracePathSkipping(context) {
var _a, _b;
Expand Down
21 changes: 14 additions & 7 deletions src/index.ts
Expand Up @@ -13,6 +13,7 @@ type WorkflowRunConclusion = 'success' | 'failure' | 'neutral' | 'cancelled' | '
const concurrentSkippingMap = {
"always": null,
"same_content": null,
"outdated_runs": null,
"never": null,
}
function getConcurrentSkippingOptions(): string[] {
Expand Down Expand Up @@ -214,14 +215,20 @@ function detectConcurrentRuns(context: WRunContext) {
if (context.concurrentSkipping === "always") {
core.info(`Skip execution because another instance of the same workflow is already running in ${concurrentRuns[0].html_url}`);
exitSuccess({ shouldSkip: true });
} else if (context.concurrentSkipping === "outdated_runs") {
const newerRun = concurrentRuns.find((run) => new Date(run.createdAt).getTime() > new Date(context.currentRun.createdAt).getTime());
if (newerRun) {
core.info(`Skip execution because a newer instance of the same workflow is running in ${newerRun.html_url}`);
exitSuccess({ shouldSkip: true });
}
} else if (context.concurrentSkipping === "same_content") {
const concurrentDuplicate = concurrentRuns.find((run) => run.treeHash === context.currentRun.treeHash);
if (concurrentDuplicate) {
core.info(`Skip execution because the exact same files are concurrently checked in ${concurrentDuplicate.html_url}`);
exitSuccess({ shouldSkip: true });
}
}
const concurrentDuplicate = concurrentRuns.find((run) => run.treeHash === context.currentRun.treeHash);
if (concurrentDuplicate) {
core.info(`Skip execution because the exact same files are concurrently checked in ${concurrentDuplicate.html_url}`);
exitSuccess({ shouldSkip: true });
} else {
core.info(`Did not find any duplicate concurrent workflow-runs`);
}
core.info(`Did not find any skippable concurrent workflow-runs`);
}

async function backtracePathSkipping(context: WRunContext) {
Expand Down

0 comments on commit 4aa7907

Please sign in to comment.