Giter Club home page Giter Club logo

Comments (4)

Conchylicultor avatar Conchylicultor commented on August 14, 2024 1

Thanks, how is it different from:

- if: {{ github.ref_name != 'main' }}
  uses: styfle/[email protected]
  with:
          access_token: ${{ github.token }}

Which is what we're currently using and which is not working: https://github.com/tensorflow/datasets/blob/076de8657a32bac79fad46644c1a4ba24e1a8d7b/.github/workflows/pytest.yml#L17

It looks like your solution is only triggering cancel event when the "push" is not the main branch. But it doesn't prevent cancel to cancel actions in the main branch.

For example, a push on branch A will trigger a cancel event, which will cancel the current tests on the main branch. This will make our tests red.

Maybe it would be nice to add some:

- uses: styfle/[email protected]
   with:
       do_not_cancel_branch: 'main'
       access_token: ${{ github.token }}

So the event is triggered on all branch (including main), but never the cancel "main" tests

from cancel-workflow-action.

Conchylicultor avatar Conchylicultor commented on August 14, 2024 1

For update, we ended up not using cancel-action but instead use the native cancel-in-progress feature from Github:

https://github.com/tensorflow/datasets/blob/4adc2b61a8ed6b56c5fc3259f5ccd46d3be3bab2/.github/workflows/pytest.yml#L14

# Cancel in-progress runs for the current workflow if not on the main branch
# (as it mark the unittests as failed).
# Conditionals to concurrent are based on the solution proposed in this link:
# https://github.community/t/concurrency-cancel-in-progress-but-not-when-ref-is-master/194707
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}-${{ github.ref != 'refs/heads/master' || github.run_number }}
  # Cancel only PR intermediate builds
  cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

from cancel-workflow-action.

styfle avatar styfle commented on August 14, 2024

I use a separate workflow to control the push events that should cancel.

Then pass the workflow ids that should be canceled:

name: Cancel
on:
  push:
    branches:
    - '**'
    - '!main'

jobs:
  cancel:
    name: 'Cancel Previous Runs'
    runs-on: ubuntu-latest
    timeout-minutes: 2
    steps:
      - uses: styfle/[email protected]
        with:
          workflow_id: 849295, 849296, 849297, 849298
          access_token: ${{ github.token }}

from cancel-workflow-action.

styfle avatar styfle commented on August 14, 2024

It looks like your solution is only triggering cancel event when the "push" is not the main branch. But it doesn't prevent cancel to cancel actions in the main branch.

It does prevent canceling the main branch. The current branch is considered for cancelation here

let branch = ref.slice(11);
let headSha = sha;
if (payload.pull_request) {
branch = payload.pull_request.head.ref;
headSha = payload.pull_request.head.sha;
} else if (payload.workflow_run) {
branch = payload.workflow_run.head_branch;
headSha = payload.workflow_run.head_sha;
}

So if you never run on the main branch then it wont cancel the main branch.

from cancel-workflow-action.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.