Prevent duplicate Workflow execution

Hey guys, Is there a way to ensure a workflow is only run once? Background: On Push the primary workflow is triggered, it has a pre-requisite dependency on the Init workflow. On Pull Request, the Pull-Request workflow is triggered which is also has a pre-requisite on the Init workflow. Also the Pull-Request workflow needs to run primary as well after it finishes. Currently this results in Init being run twice.

1 Like

I think I can answer my own question.

After a little redesign, I can rearrange the workflows so that:
“pull-request workflow” depends on “primary workflow” depends on “init”.
When the Push trigger runs the “primary workflow” it runs “init” as a pre-requisite which works fine.
When the Pull-Request trigger runs the “pull-request workflow” it must run the primary as a pre-requisite, and the primary must run a init as a pre-requisite. Which works fine too.
Problem solved :slight_smile:

1 Like

Hi @benrnz-sv,

Thanks for asking this here! :wink:

There’s no built in way, you have to design your config around this (mainly because by designing the workflows this way the configuration will be easier to understand than having multiple references (before_run/after_run) on the same workflow but actually running it only once, it’s a bit harder to follow).


Just one more note, which might help: you can have workflows which don’t have any steps, only before_run/after_run blocks. An example from our Docker image builder config:

    - _pinned_envs
    - _rebuild

The rebuild-pinned workflow has no steps at all, all it does is it connects a “prepare” workflow (in this case a workflow which sets some configuration params through env vars) with other workflow(s) (in this case a generic “rebuild” workflow, which requires certain configuration params - supplied by the other workflow).

Thanks for sharing your solution @benrnz-sv, and if you’d have any questions just let us know!
Happy Building! :wink: