Running Nuke inside a GitHub Action

Search for a command to run...

No comments yet. Be the first to comment.
Nuke is an open source, cross-platform build automation solution for .NET projects. Nuke prides itself on its simplicity and extensibility that makes build automation approachable for everyone.
Nuke helps us achieve a flexible, maintainable, automated build process. However, nothing stops us from automating any task we perform during our day-to-day work, especially if it is manual and repetitive. Thus, we would like to share other tasks we ...
Google processes tens of thousands of code changes every day across a codebase of hundreds of millions of lines. The secret isn't magic tooling — it's a documented, principled approach to code review

Amazon Simple Notification Service (SNS) looks straightforward on the surface — publish a message, deliver it to subscribers — but the gap between a topic that "works in dev" and one that is productio

Amazon Simple Queue Service (SQS) is deceptively simple to get started with, but surprisingly easy to misconfigure in ways that cause silent message loss, runaway costs, duplicate processing storms, o

HTTP API is the right default choice for the majority of .NET serverless workloads. At 70% less cost than REST API, lower latency, and native JWT authorization, it covers most production requirements

AWS Lambda has become a cornerstone of modern serverless architectures, but writing a function that "just works" is very different from writing one that is performant, cost-effective, secure, and read

This post is the official continuation of the post, Nuke: Deploy ASP. NET Web App to Azure (try to check it before and download the initial code from here). Here we'll see how easy it's to run Nuke inside a GitHub Action. We'll create two workflows, the first to compile the application on every push and the other to deploy the application on demand. We can generate the workflow files by adding the GitHubActions attribute at the top of the Build class:
[GitHubActions(
"compile",
GitHubActionsImage.UbuntuLatest,
OnPushBranches = new[] { "main" },
InvokedTargets = new[] { nameof(Compile) })]
Let's run the nuke --help command to generate the compile.yml workflow file(actually, every execution of the nuke command will generate the file):
name: compile
on:
push:
branches:
- main
jobs:
ubuntu-latest:
name: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Cache .nuke/temp, ~/.nuget/packages
uses: actions/cache@v2
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
- name: Run './build.cmd Compile'
run: ./build.cmd Compile
In the second workflow, we want to generate an artifact as part of the execution. Change the Zip target as follows:
Target Zip => _ => _
.DependsOn(Publish)
.Produces(ArtifactDirectory / "*.zip")
.Executes(() =>
{
ZipFile.CreateFromDirectory(OutputDirectory, ArtifactDirectory / "deployment.zip");
});
The attribute to add will be:
[GitHubActions(
"deploy",
GitHubActionsImage.UbuntuLatest,
On = new[] { GitHubActionsTrigger.WorkflowDispatch },
InvokedTargets = new[] { nameof(Deploy) },
ImportSecrets = new[] { nameof(WebAppPassword)},
AutoGenerate = false)]
In this case, the attribute has the AutoGenerate set to false because we want to control the generation explicitly by running the following command nuke --generate-configuration GitHubActions_deploy --host GitHubActions:
name: deploy
on: [workflow_dispatch]
jobs:
ubuntu-latest:
name: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Cache .nuke/temp, ~/.nuget/packages
uses: actions/cache@v2
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
- name: Run './build.cmd Deploy'
run: ./build.cmd Deploy
env:
WebAppPassword: ${{ secrets.WEB_APP_PASSWORD }}
- uses: actions/upload-artifact@v1
with:
name: artifact
path: artifact
Modify the deploy.yml file to complete the parameters needed by the Deploy target as follow:
name: deploy
on: [workflow_dispatch]
jobs:
ubuntu-latest:
name: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Cache .nuke/temp, ~/.nuget/packages
uses: actions/cache@v2
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
- name: Run './build.cmd Deploy'
run: ./build.cmd Deploy
env:
WebAppPassword: ${{ secrets.WEB_APP_PASSWORD }}
WebAppUser: $nuke-sandbox-app
WebAppName: nuke-sandbox-app
- uses: actions/upload-artifact@v1
with:
name: artifact
path: artifact
By default on Windows, the build.cmd and build.sh are not recognized as executable. We can set the executable flag on any file using the update-index git sub-command:
git update-index --chmod=+x .\build.sh
git update-index --chmod=+x .\build.cmd
Go to GitHub and add the WEB_APP_PASSWORD secret:

Push all the files to GitHub to start seeing the workflows in action:

Run the deploy workflow to see the following output:

You can find the final code here. Thanks, and happy coding.