So assume I have 2 workflows, one for building and testing for all pushes, then one for creating a release and packaging the app then adding it to the release, but this should only run on tagged pushes.
Currently I've found loads of posts which tell me how to only run for tags:
on:
push:
tag: *
So with this in place I then needed to check how I can have the 2nd workflow depend on the first one. I could find a brief bit of information which implied I should do:
on:
workflow_run:
workflows: ["first_one"]
types:
- completed
However I cannot find any examples which combine the two, and I assume this is a common use case, so im baffled as to how to do it.
In Azure devops I would probably have two stages with second stage dependsOn
the first one with a condition on it for only tags.
So can anyone provides way to do this or at least best way to structure it so I can get test feedback on all pushes and create releases with artifact automatically on tags?
CodePudding user response:
If these two workflows are only used in one project, I would structure it like the following: Create a job for building and testing (or make it two jobs) and then another one to package and release. All in one file.
The workflow would look like so:
on:
push:
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- run: build.sh && test.sh
package-and-release:
runs-on: ubuntu-latest
if: startsWith(github.event.ref, 'refs/tags/')
needs: [build-and-test]
steps:
- run: package.sh && release.sh
With this setup, the second job package-and-release
is run after the first one and only if the push
is triggered by a tag.
If you have this setup in multiple repositories, I would recommend using reusable workflows and either have one big reusable workflow that basically contains both of the above jobs, or have one reusable workflow per job. Note that "job" in this case can also be more than one job: While a reusable workflow is referenced from a job, it can itself contain more than one job.
The condition to only trigger the package & release on tag pushes could then be either inside the reusable workflow or outside. I would make that decision based on wether all of the users will do it this way or not.