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

Support for starting job service on condition is met #822

Open
igagis opened this issue Nov 25, 2020 · 14 comments
Open

Support for starting job service on condition is met #822

igagis opened this issue Nov 25, 2020 · 14 comments
Labels
enhancement New feature or request

Comments

@igagis
Copy link

igagis commented Nov 25, 2020

Describe the enhancement
Add support of if: property to jobs.<job-id>.services.<service-id> to start services only in case a condition is met.

Code Snippet

jobs:
  my_job:
    services:
      my_service:
        if: ${{ some expression }}
        ....
@tanguyantoine
Copy link

That would be very helpful if you have a shared workflow. We could turn on/off services based on workflow inputs

@imclem
Copy link

imclem commented Dec 21, 2022

Couldn't agree more, we add steps to run docker run manually because we don't have conditions on services.

@thobianchi
Copy link

thobianchi commented Jan 16, 2023

leaving service.<service-name>.image empty does not start the service, this is the output:

The service 'postgres' will not be started because the container definition has an empty image.

This can be used to build a basic conditional, it is a workaround, a proper solution should be implemented.

@bvtk
Copy link

bvtk commented Jan 26, 2023

Yes this would be a cool feature, we have the same problem on a shared workflow

@vyacheslav-korneev
Copy link

vyacheslav-korneev commented Feb 15, 2023

Got here searching for the solution of our problem with shared workflows :)
Hope this feature will be implemented as it would increase the utility of shared workflows dramatically.

@flozano
Copy link

flozano commented Apr 26, 2023

this would be very useful when reusing workflows, please consider implementing it

@ChristopherHX
Copy link
Contributor

I think the following is supported, since 3e19635 aka v2.299.0 or later

jobs:
  my_job:
    services:
      my_service:
        image: ${{ (some expression) && 'image:tag' || '' }}

It's very similar to an if, just not so nice to write.

@flozano
Copy link

flozano commented Apr 27, 2023

thanks a lot, I was trying something similar. not nice aesthetically but if it works it's great.

@cezar-tech
Copy link

That would be very helpful for my organization as well

@Keramblock
Copy link

Almost 3 years passed

@sergbar
Copy link

sergbar commented Nov 29, 2023

I think the following is supported, since 3e19635 aka v2.299.0 or later

jobs:
  my_job:
    services:
      my_service:
        image: ${{ (some expression) && 'image:tag' || '' }}

It's very similar to an if, just not so nice to write.

In my example it works as designed. If database_name input not provided (is empty) skip the installation and if it's provided then use postgres image with the version as provided in the postgres_version input.

    services:
      postgres:
        image: ${{ ( inputs.database_name != '' ) && format('postgres:{0}', inputs.postgres_version) || '' }}

@Cyberboss
Copy link

Workaround works perfectly for me

@Cyberboss
Copy link

Best GH can do is update the docs with this workaround.

@knu
Copy link

knu commented Mar 4, 2024

The workaround is not ideal as the image names specified in expressions will fall off from automated updates via Renovate.

amstilp added a commit to UW-GAC/django-anvil-consortium-manager that referenced this issue Apr 1, 2024
GitBluub added a commit to GitBluub/act that referenced this issue Apr 8, 2024
It is used to skip empty image name in services which is the only way to handle condition services in github action currently actions/runner#822
payam1374 added a commit to payam1374/starknet that referenced this issue Apr 23, 2024
  # TODO - periodically check if conditional services are supported; actions/runner#822
    services:
      devnet:
        image: ${{ (inputs.use-devnet) && 'shardlabs/starknet-devnet-rs:b41e566a3f17aa0e51871f02d5165959e50ce358-amd-seed0' || '' }}
        image: ${{ (inputs.use-devnet) && 'shardlabs/starknet-devnet-rs:0.0.3-seed0' || '' }}
        ports:
          - 5050:5050
GitBluub added a commit to GitBluub/act that referenced this issue Jun 4, 2024
It is used to skip empty image name in services which is the only way to handle condition services in github action currently actions/runner#822
mergify bot pushed a commit to nektos/act that referenced this issue Jun 5, 2024
* fix: skip service container for empty image

It is used to skip empty image name in services which is the only way to handle condition services in github action currently actions/runner#822

* test: add testdata for empty image in services

* fix: add missing test call

* fix: wring test call

* fix: invalid without expression

---------

Co-authored-by: ChristopherHX <[email protected]>
chhe pushed a commit to chhe/act that referenced this issue Nov 1, 2024
* fix: skip service container for empty image

It is used to skip empty image name in services which is the only way to handle condition services in github action currently actions/runner#822

* test: add testdata for empty image in services

* fix: add missing test call

* fix: wring test call

* fix: invalid without expression

---------

Co-authored-by: ChristopherHX <[email protected]>
chhe pushed a commit to chhe/act that referenced this issue Nov 26, 2024
* fix: skip service container for empty image

It is used to skip empty image name in services which is the only way to handle condition services in github action currently actions/runner#822

* test: add testdata for empty image in services

* fix: add missing test call

* fix: wring test call

* fix: invalid without expression

---------

Co-authored-by: ChristopherHX <[email protected]>
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

No branches or pull requests