any GH Actions expert around? I have a reusable wo...
# gitops
w
any GH Actions expert around? I have a reusable workflow with pre-defined jobs, I need them to run in order (similar to a stage view in GitLab), i.e.: check -> build -> test -> deploy I am setting something like:
Copy code
jobs:
  check:
    ...
  build:
    needs: check
    ...
  test:
    needs: build
    ...
The problem is that some jobs are conditional, so they can be skipped. But because of
needs
, all subsequent jobs are also skipped.
I have found a few threads about this https://github.com/actions/runner/issues/491 https://github.com/orgs/community/discussions/26303 but the workarounds come with their own flaws
t
w
Thanks @Tomas Dabašinskas That is misbehaving inexplicably. Sometimes it works and sometimes doesn't, I can't tell. The documentation is also divergent. There it tells to use the syntax
if: ${{ success() }}
but on the same page, it tells to not use `${{ }}`on if conditions because it will convert the result to a string and strings are truthy.
OK this seems to work and I could add an extra conditional to enable only wanted workflows on a global run:
Copy code
jobs:
  check:
  if: contains(inputs.workflows, 'check')
    ...
  build:
  if: ${{ !cancelled() && needs.check.result != 'failure' && contains(inputs.workflows, 'build') }}
    needs: check
    ...
  test:
  if: ${{ !cancelled() && needs.build.result != 'failure' && contains(inputs.workflows, 'test') }}
    needs: build
    ...
So I can call this with:
Copy code
with:
  workflows: "build test"
And this will skip
check
, and run only
build
and
test