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

Command to early-exit the job and set check conclusion #662

Closed
ylemkimon opened this issue Aug 16, 2020 · 53 comments
Closed

Command to early-exit the job and set check conclusion #662

ylemkimon opened this issue Aug 16, 2020 · 53 comments
Labels
actions-feature enhancement New feature or request

Comments

@ylemkimon
Copy link

ylemkimon commented Aug 16, 2020

Describe the enhancement
Currently to skip the rest of steps during a job, an if condition has to be added to all of steps or steps have to be moved to another job.

It'd be nice to have a command to early-exit (premature, prematurely, graceful, gracefully) (end, finish, terminate, termination, stop, halt, skip, cancel, discontinue, fail) the job during a step without failing the job:

::exit::

It'd be also nice to set the conclusion of early-exited job:

::exit::failure

(equivalent to exit 1)
or

::exit::neutral

(equivalent to exit 78 in Actions v1)
and other check conclusions.

This would help save build time for both GitHub and customers.

Additional information

Related StackOverflow and GitHub Community posts:

Related issues:

Other CIs:

@ylemkimon ylemkimon added the enhancement New feature or request label Aug 16, 2020
@a-tokyo
Copy link

a-tokyo commented Sep 24, 2020

This is really useful and is quite needed!

@remorses
Copy link

remorses commented Oct 9, 2020

This is useful to not repeat the same if statement many times, you can instead do an early exit

@christian-kreuzberger-dtx

This would be a great addition. Right now I have a pre-condition that I can only check in a bash-script, and I'm exiting with exit 1 for a purpose. However, in my PR it shows up as a failure :(

image

@bartlettroscoe
Copy link

I can't believe GHA does not support this. I guess you need to just implement and entire job as one big step run by your own driver script and then you can put whatever logic you want in that script to terminate early and with a zero exist (and a nice informational message). Is that the only current workaround for this?

GHA seems to be a new unique declarative language with somewhat limited functionality.

aaron-prindle added a commit to aaron-prindle/skaffold that referenced this issue Jun 17, 2021
    Fixes GoogleContainerTools#6032, add code to not run Github Actions on docs-only changes. This PR:
    - Updates linux and osx github actions to check if the PR only changes docs/* files and if so, pass the test w/o running the full test suite

    Github actions does not have support for exiting the job from a step easily. See:
    - https://stackoverflow.com/questions/60589373/how-to-force-to-exit-in-github-actions-step
    - actions/runner#662
    The approach here uses an env var and checks this env var in all subsequent steps, this way no single command fails and tests are skipped as desired.  The downside is that all subsequent steps need to have this check but there is no better solution at the moment from my investigation

  I considered directly using the the 'conclusion' value github actions provides, eg:
  - "if: steps.s1.conclusion == 'failure'"
  but I believe that if a step fails then the test fails which is not what we want.

   There shouldn't be any side effects w/ this approach, all steps have a conditional on the docs-only check and should work correctly as before in the non-docs file are updated case

    N/A.  Future work generally might include a tag that also skips testing but is not directly related
aaron-prindle added a commit to aaron-prindle/skaffold that referenced this issue Jun 17, 2021
    Fixes GoogleContainerTools#6032, add code to not run Github Actions on docs-only changes. This PR:
    - Updates linux and osx github actions to check if the PR only changes docs/* files and if so, pass the test w/o running the full test suite

    Github actions does not have support for exiting the job from a step easily. See:
    - https://stackoverflow.com/questions/60589373/how-to-force-to-exit-in-github-actions-step
    - actions/runner#662
    The approach here uses an env var and checks this env var in all subsequent steps, this way no single command fails and tests are skipped as desired.  The downside is that all subsequent steps need to have this check but there is no better solution at the moment from my investigation

  I considered directly using the the 'conclusion' value github actions provides, eg:
  - "if: steps.s1.conclusion == 'failure'"
  but I believe that if a step fails then the test fails which is not what we want.

   There shouldn't be any side effects w/ this approach, all steps have a conditional on the docs-only check and should work correctly as before in the non-docs file are updated case

    N/A.  Future work generally might include a tag that also skips testing but is not directly related
aaron-prindle added a commit to aaron-prindle/skaffold that referenced this issue Jun 17, 2021
    Fixes GoogleContainerTools#6032, add code to not run Github Actions on docs-only changes. This PR:
    - Updates linux and osx github actions to check if the PR only changes docs/* files and if so, pass the test w/o running the full test suite

    Github actions does not have support for exiting the job from a step easily. See:
    - https://stackoverflow.com/questions/60589373/how-to-force-to-exit-in-github-actions-step
    - actions/runner#662
    The approach here uses an env var and checks this env var in all subsequent steps, this way no single command fails and tests are skipped as desired.  The downside is that all subsequent steps need to have this check but there is no better solution at the moment from my investigation

  I considered directly using the the 'conclusion' value github actions provides, eg:
  - "if: steps.s1.conclusion == 'failure'"
  but I believe that if a step fails then the test fails which is not what we want.

   There shouldn't be any side effects w/ this approach, all steps have a conditional on the docs-only check and should work correctly as before in the non-docs file are updated case

    N/A.  Future work generally might include a tag that also skips testing but is not directly related
aaron-prindle added a commit to aaron-prindle/skaffold that referenced this issue Jun 17, 2021
    Fixes GoogleContainerTools#6032, add code to not run Github Actions on docs-only changes. This PR:
    - Updates linux and osx github actions to check if the PR only changes docs/* files and if so, pass the test w/o running the full test suite

    Github actions does not have support for exiting the job from a step easily. See:
    - https://stackoverflow.com/questions/60589373/how-to-force-to-exit-in-github-actions-step
    - actions/runner#662
    The approach here uses an env var and checks this env var in all subsequent steps, this way no single command fails and tests are skipped as desired.  The downside is that all subsequent steps need to have this check but there is no better solution at the moment from my investigation

  I considered directly using the the 'conclusion' value github actions provides, eg:
  - "if: steps.s1.conclusion == 'failure'"
  but I believe that if a step fails then the test fails which is not what we want.

   There shouldn't be any side effects w/ this approach, all steps have a conditional on the docs-only check and should work correctly as before in the non-docs file are updated case

    N/A.  Future work generally might include a tag that also skips testing but is not directly related
aaron-prindle added a commit to aaron-prindle/skaffold that referenced this issue Jun 17, 2021
    Fixes GoogleContainerTools#6032, add code to not run Github Actions on docs-only changes. This PR:
    - Updates linux and osx github actions to check if the PR only changes docs/* files and if so, pass the test w/o running the full test suite

    Github actions does not have support for exiting the job from a step easily. See:
    - https://stackoverflow.com/questions/60589373/how-to-force-to-exit-in-github-actions-step
    - actions/runner#662
    The approach here uses an env var and checks this env var in all subsequent steps, this way no single command fails and tests are skipped as desired.  The downside is that all subsequent steps need to have this check but there is no better solution at the moment from my investigation

  I considered directly using the the 'conclusion' value github actions provides, eg:
  - "if: steps.s1.conclusion == 'failure'"
  but I believe that if a step fails then the test fails which is not what we want.

   There shouldn't be any side effects w/ this approach, all steps have a conditional on the docs-only check and should work correctly as before in the non-docs file are updated case

    N/A.  Future work generally might include a tag that also skips testing but is not directly related
aaron-prindle added a commit to aaron-prindle/skaffold that referenced this issue Jun 17, 2021
    Fixes GoogleContainerTools#6032, add code to not run Github Actions on docs-only changes. This PR:
    - Updates linux and osx github actions to check if the PR only changes docs/* files and if so, pass the test w/o running the full test suite

    Github actions does not have support for exiting the job from a step easily. See:
    - https://stackoverflow.com/questions/60589373/how-to-force-to-exit-in-github-actions-step
    - actions/runner#662
    The approach here uses an env var and checks this env var in all subsequent steps, this way no single command fails and tests are skipped as desired.  The downside is that all subsequent steps need to have this check but there is no better solution at the moment from my investigation

  I considered directly using the the 'conclusion' value github actions provides, eg:
  - "if: steps.s1.conclusion == 'failure'"
  but I believe that if a step fails then the test fails which is not what we want.

   There shouldn't be any side effects w/ this approach, all steps have a conditional on the docs-only check and should work correctly as before in the non-docs file are updated case

    N/A.  Future work generally might include a tag that also skips testing but is not directly related
aaron-prindle added a commit to aaron-prindle/skaffold that referenced this issue Jun 17, 2021
    Fixes GoogleContainerTools#6032, add code to not run Github Actions on docs-only changes. This PR:
    - Updates linux and osx github actions to check if the PR only changes docs/* files and if so, pass the test w/o running the full test suite

    Github actions does not have support for exiting the job from a step easily. See:
    - https://stackoverflow.com/questions/60589373/how-to-force-to-exit-in-github-actions-step
    - actions/runner#662
    The approach here uses an env var and checks this env var in all subsequent steps, this way no single command fails and tests are skipped as desired.  The downside is that all subsequent steps need to have this check but there is no better solution at the moment from my investigation

  I considered directly using the the 'conclusion' value github actions provides, eg:
  - "if: steps.s1.conclusion == 'failure'"
  but I believe that if a step fails then the test fails which is not what we want.

   There shouldn't be any side effects w/ this approach, all steps have a conditional on the docs-only check and should work correctly as before in the non-docs file are updated case

    N/A.  Future work generally might include a tag that also skips testing but is not directly related
aaron-prindle added a commit to aaron-prindle/skaffold that referenced this issue Jun 17, 2021
    Fixes GoogleContainerTools#6032, add code to not run Github Actions on docs-only changes. This PR:
    - Updates linux and osx github actions to check if the PR only changes docs/* files and if so, pass the test w/o running the full test suite

    Github actions does not have support for exiting the job from a step easily. See:
    - https://stackoverflow.com/questions/60589373/how-to-force-to-exit-in-github-actions-step
    - actions/runner#662
    The approach here uses an env var and checks this env var in all subsequent steps, this way no single command fails and tests are skipped as desired.  The downside is that all subsequent steps need to have this check but there is no better solution at the moment from my investigation

  I considered directly using the the 'conclusion' value github actions provides, eg:
  - "if: steps.s1.conclusion == 'failure'"
  but I believe that if a step fails then the test fails which is not what we want.

   There shouldn't be any side effects w/ this approach, all steps have a conditional on the docs-only check and should work correctly as before in the non-docs file are updated case

    N/A.  Future work generally might include a tag that also skips testing but is not directly related
@user1689
Copy link

user1689 commented Dec 6, 2023

interested

@user1689
Copy link

user1689 commented Dec 6, 2023

@ruvceskistefan ruvceskistefan added actions-feature and removed Actions Feature Feature requires both runner, pipelines service and launch changes labels Dec 26, 2023
Copy link
Contributor

Thank you for your interest in the runner application and taking the time to provide your valuable feedback. We kindly ask you to redirect this feedback to the GitHub Community Support Forum which our team actively monitors and would be a better place to start a discussion for new feature requests in GitHub Actions. For more information on this policy please read our contribution guidelines. 😃

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 28, 2023
@ljharb
Copy link

ljharb commented Dec 28, 2023

This is a pretty user-hostile way to close this issue (as any bot closure is); this issue has been opened for 4 years, so even quite inactive monitoring should have surfaced it to your team.

@Jackenmen
Copy link

Either way, it would be good to get people to move their upvotes to some common discussion on the GitHub Actions product feedback discussion forum (putting a correct link here since the one given by the bot doesn't fully work) since that is in fact where they want all feature requests to go to nowadays.

As far as I can tell, there weren't any existing discussions there that would represent the same problem as this issue (there's https://github.com/orgs/community/discussions/67407 but it's a question, not an enhancement request) so I made one here, mostly just copy-pasting the description from the original comment by ylemkinon with a few added remarks:
https://github.com/orgs/community/discussions/82744

juliangruber added a commit to filecoin-station/desktop that referenced this issue Feb 9, 2024
juliangruber added a commit to filecoin-station/desktop that referenced this issue Feb 9, 2024
* ci: disable always failing windows pr builds

* fix ignore subsequent steps

actions/runner#662
Sekhmet added a commit to snapshot-labs/sx-monorepo that referenced this issue Feb 12, 2024
Cancelled state means failure for Github Actions so we have to work it around.

There is no functionality to exit-early: actions/runner#662
@ljharb
Copy link

ljharb commented Mar 16, 2024

@joshmgross since you directed people here in actions/github-script#147 (comment), is there any chance this could be reopened, or that https://github.com/orgs/community/discussions/82744 could be updated?

@silverqx
Copy link

Has anything changed about this? I'm searching for how to successfully exit the workflow in the middle to skip the rest of the steps. Is it possible?

@nsalfos
Copy link

nsalfos commented Apr 17, 2024

Has anything changed about this? I'm searching for how to successfully exit the workflow in the middle to skip the rest of the steps. Is it possible?

i dont think anything changed in GHA iteself... i might be wrong tho...
there is a way but is not pretty... you have to put a conditional for each step after the one you want to skip.
like:

- name: I dont want anything to run after this
  id: boss-step
  run: |
    echo "skipnext=true" >> $GITHUB_OUTPUT

- name: Some next step
  if : ( steps.boss-step.outputs.skipnext  != 'true' ) 
  run: |
    echo "will only run if skipnext is not true"
  
- name: Some other step
  if : ( steps.boss-step.outputs.skipnext  != 'true' ) 
  run: |
    echo "will only run if skipnext is not true"

and so on... for how many steps you have after your condition

@silverqx
Copy link

Ok, thx for reply, I have 27 steps to skip so this isn't a solution for my workflow. I will have to create a new workflow for this case.

@ArkadiuszMichalski
Copy link

I experienced the same problem myself. I am unable to terminate entire workflow as success without adding conditions in subsequent steps, which significantly obfuscates the entire code.

Closing this issue after a few years is not serious, considering how many people expect it.

@dirkf
Copy link

dirkf commented Apr 26, 2024

"For avoidance of doubt", he's surely saying that GH is not treating the issue seriously, rather than that closing the issue is not serious for the people who want the issue resolved.

infinisil added a commit to tweag/nixpkgs that referenced this issue Apr 26, 2024
This avoids sending emails when there's merge conflicts.
The check will appear to be green,
but it doesn't matter since the PR can't be merged anyways.

Unfortunately there's no better way to do this right now: actions/runner#662
infinisil added a commit to tweag/nixpkgs that referenced this issue Apr 27, 2024
This avoids sending emails when there's merge conflicts.
The check will appear to be green,
but it doesn't matter since the PR can't be merged anyways.

Unfortunately there's no better way to do this right now: actions/runner#662
@burhanyasar
Copy link

It might not fit all scenarios but in our similar too many if else case, it was possible to split the single pipeline to tag a new version on push and other pipelines would just run on a new tag, instead of checking an if statement.

infinisil added a commit to NixOS/nixpkgs that referenced this issue May 14, 2024
This avoids sending emails when there's merge conflicts.
The check will appear to be green,
but it doesn't matter since the PR can't be merged anyways.

Unfortunately there's no better way to do this right now: actions/runner#662
malt3 pushed a commit to malt3/nixpkgs that referenced this issue May 15, 2024
This avoids sending emails when there's merge conflicts.
The check will appear to be green,
but it doesn't matter since the PR can't be merged anyways.

Unfortunately there's no better way to do this right now: actions/runner#662
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actions-feature enhancement New feature or request
Projects
None yet
Development

No branches or pull requests