Skip to content

Commit

Permalink
refactor: use GH actions concurrency to cancel runs
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-reimann committed Nov 2, 2021
1 parent 698e42e commit e00bdac
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@ env: # Comment env block if you do not want to apply fixes
APPLY_FIXES_EVENT: pull_request # Decide which event triggers application of fixes in a commit or a PR (pull_request, push, all)
APPLY_FIXES_MODE: commit # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) or posted in a PR (pull_request)

jobs:
# Cancel duplicate jobs: https://github.com/fkirc/skip-duplicate-actions#option-3-cancellation-only
cancel_duplicates:
name: Cancel duplicate jobs
runs-on: ubuntu-latest
steps:
- uses: fkirc/skip-duplicate-actions@master
with:
github_token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
cancel_others: true
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
build:
name: Mega-Linter
runs-on: ubuntu-latest
Expand Down
45 changes: 45 additions & 0 deletions mega-linter-runner/lib/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,51 @@ class MegaLinterUpgrader {
test: "wesh nvuillam/mega-linter",
testRes: "wesh megalinter/megalinter",
},
// Cancellation of duplicate runs
// Job "cancel_duplicate"
{
regex: /(?<prev_jobs>jobs\s*:(?:.|\n)*)\n(?<indent> *)cancel_duplicates\s*:(?:.|\n)*\n(?<next_job_key>\k<indent>\S*\s*:)/gmi,
replacement: `concurrency:
group: \${{ github.ref }}-\${{ github.workflow }}
cancel-in-progress: true
$<prev_jobs>
$<next_job_key>
`,
test: `
jobs:
# Cancel duplicate jobs: https://github.com/fkirc/skip-duplicate-actions#option-3-cancellation-only
cancel_duplicates:
name: Cancel duplicate jobs
runs-on: ubuntu-latest
steps:
- uses: fkirc/skip-duplicate-actions@master
with:
github_token: \${{ secrets.PAT || secrets.GITHUB_TOKEN }}
cancel_others: true
build:
`,
testRes: `
jobs:
# Cancel duplicate jobs: https://github.com/fkirc/skip-duplicate-actions#option-3-cancellation-only
build:
`,
},
// Comment "# Cancel duplicate jobs: https://github.com/fkirc/..."
{
regex: /^\s*#\s*cancel\s*duplicate.*\n/gmi,
replacement: "",
test: `
jobs:
# Cancel duplicate jobs: https://github.com/fkirc/skip-duplicate-actions#option-3-cancellation-only
build:
`,
testRes: `
jobs:
build:
`,
},
];
}

Expand Down

0 comments on commit e00bdac

Please sign in to comment.