Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use concurrency option of GH actions to cancel previous workflow runs #920

Closed
lars-reimann opened this issue Nov 2, 2021 · 3 comments · Fixed by #921
Closed

Use concurrency option of GH actions to cancel previous workflow runs #920

lars-reimann opened this issue Nov 2, 2021 · 3 comments · Fixed by #921
Labels
enhancement New feature or request

Comments

@lars-reimann
Copy link
Contributor

lars-reimann commented Nov 2, 2021

Is your feature request related to a problem? Please describe.
This is a follow-up to #622, i.e. about cancelling previous workflow runs when a new push to a branch occurs.

Describe the solution you'd like
GitHub actions directly offers a means to prevent concurrent workflow runs and concurrent job runs and to cancel any previous runs.

Advantages:

  • It's not another job, so
    • cancellation happens faster,
    • it does not show up as a check in PRs,
    • you don't get billed for it.

Disadvantages:

  • skip-duplicate-actions offers more options.
  • One needs to be careful that only the mega-linter workflow is cancelled by assigning a unique concurrency group.

Example:

name: Mega-Linter

on:
  pull_request:
    branches: [main]

# Workflow can only run once per branch and any previous pending or in-progress runs are cancelled.
concurrency:
  group: ${{ github.ref }}-${{ github.workflow }}
  cancel-in-progress: true

env:
  APPLY_FIXES: all
  APPLY_FIXES_EVENT: pull_request
  APPLY_FIXES_MODE: commit
  FILTER_REGEX_EXCLUDE: (\.github/workflows/)

jobs:
  lint:
    # As usual...

Describe alternatives you've considered
Keep everything as is, which is also perfectly acceptable (so feel free to close this).

Additional context
Links (same as above):

@lars-reimann lars-reimann added the enhancement New feature or request label Nov 2, 2021
@nvuillam
Copy link
Member

nvuillam commented Nov 2, 2021

Oh, that's new to GHA Workflow ? Great , it would indeed be faster than the action we use today

Are you in the mood for a PR ? Template to update is here -> https://github.com/megalinter/megalinter/blob/main/mega-linter-runner/generators/mega-linter/templates/mega-linter.yml

If not, we'll definitely do that someday !

@lars-reimann
Copy link
Contributor Author

lars-reimann commented Nov 2, 2021

I can have a look at it this weekend (at the latest).

@nvuillam
Copy link
Member

nvuillam commented Nov 2, 2021

That would be great , thanks :)

If you are a crazy coder you can also update the --upgrade option of mega-linter-runner, to do some regex search/replace to update existing workflows in repo where ML is already installed ^^ ( https://github.com/megalinter/megalinter/blob/main/mega-linter-runner/lib/upgrade.js )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants