I’m trying to wrap my head around GitHub actions for CI/review processes after coming from an arguably much simpler environment which was GitLab CI. If I understand correctly, workflows are meant to delineate specific processes which happen in a repo. With this mind, say I have the following workflows:
PR review: install deps, run lint, run tests, run code coverage.
Publish: install deps, run lint, run tests, run code coverage, build, publish.
You can see that the same jobs occur in both workflows which is a lot of copy-pasting. So, my first question is whether there exists a way to share these job definitions across multiple workflows that doesn’t involve creating a custom action?
The second problem is concerned with jobs in a workflow. “Install deps” is a common job that is needed for subsequent jobs in a workflow. Say I have caching added to this as well via actions/cache. I can add a
needs field to other jobs so that they execute once the “Install deps” job is done and cache is available. But, I now need to repeat these same steps from “Install deps” in other jobs as well which is again, repititive. Is there a way to share steps between jobs in the same workflow? I see that we can’t use YAML features like anchors which would’ve solved this problem but is there something else? Or if there’s a chance that I’m doing caching wrong, let me know.
If not, I would like to request to add these features which would not only make writing workflows a joy, but also avoid a lot of potential errors that come from copy-pasting or resorting to needlessly complicated methods.