GitHub Actions with .NET, Part 2 - Dependent Jobs
Full source code available here.
- Part 1 - Hello World and Downloading the Artifact
- Part 2 - Dependant Jobs
- Part 3 - Manual Approvals
- Part 4 - Building an S3 bucket with Pulumi
- Part 5 - Build a .NET Application and Upload to S3
In the previous post, I gave a quick introduction to GitHub Actions showing how to build a small Hello World application and make the artifact available for download.
In this post, I’ll show how to build debug and release versions of the same application, with the release only being built if the debug one builds successfully. This in itself is not a whole lot of use, but in the next post, I’m going to show how to add manual approvals before performing certain jobs, like deploying built code to AWS. In that scenario, a build will occur, a user needs to inspect the output and approve deploying the artifact, now that is useful.
But for now, I’m keeping it simple without the complications of external services, secrets, environment variables, etc.
The Code
The C# is very simple, print a different piece of text depending on the build configuration.
|
|
Two Jobs in a GitHub Action
In the previous post, there was only one job, but you can have as many as you want, and these jobs can run independently (and in parallel) or have dependencies on each other, e.g. job 2 runs only if job 1 succeeds.
In this example, I want to run the release build only if the debug build succeeds.
The overall structure of the workflow looks like this -
|
|
In this example there are two jobs - debug-build
and release-build
. release-build
depends on debug-build
completing successfully.
They both upload artifacts to which will be available for download from GitHub after the action completes.
When the code is pushed to GitHub the debug-build
starts.
Once that completes successfully, the release-build
starts.
When that finishes the two artifacts will be available to download.
Here is the full workflow.
|
|
You Can Run (Almost) Anything in a Job
You are not limited to building software in jobs, you can run other things too.
After the build step in each job I have a run command that runs the compiled code, there is no good reason to do this here, but I’ve included it to show the flexibility of what you can do.
- name: Run it for fun
run: dotnet ./bin/debug/net5.0/GitHubActionsHelloWorldConsole.dll
You can also use commands that are available on the host Ubuntu operating system where the build is happening.
In the next post, I’ll show how to add a manual approval before performing a step.
Full source code available here.