I have a GitHub Action. In it I have several steps that should only be executed under certain conditions - in this case, these steps should be executed if the branch name matches a certain pattern. Like this:
- name: Deploy infrastructure
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/features/lrd')
This if block recurs several times in my Action. Is it possible to extract it to a shared variable, condition or function so I can get rid of the ugly code duplication? What would be the nicest way to do this?
I suppose that one option would be to compute the variable in an earlier step and reference it in the later steps, as explained in this post: https://stackoverflow.com/a/58676568/4290962
It just seems a bit ugly to have a separate step to compute this value. Is it the best we can do? Or is there a nicer option?
Thanks in advance!