I am currently working my way into GitHub Actions as well as NUKE.build. My project consists of 2 jobs in GitHub Actions: The first job is responsible for reading the build configurations from a given .csproj file and setting it as a JSON array variable. The second job (which is spread across multiple runners) is then supposed to use this JSON array as the value for the matrix, executing my targets in NUKE, with the respective value as a parameter.
I have managed this so far with the following workflow (shortened):
name: Build Workflow
on:
...
jobs:
get-configurations:
runs-on: windows-latest
outputs:
configurations: ${{ steps.generate-matrix.outputs.configurations }}
steps:
...
- name: Get Build Configurations
id: generate-matrix
run: |
dotnet NukeComponents --root . --relative-project-file-path "PathToProjectFile" --dotnet --get-configurations
build:
needs: get-configurations
runs-on: windows-latest
strategy:
matrix:
configuration: ${{ fromJson(needs.get-configurations.outputs.configurations) }}
steps:
...
- name: Build and test
run: |
$configuration = "${{ matrix.configuration }}"
dotnet NukeComponents --root . --relative-project-file-path "PathToProjectFile" --configuration "$configuration"
And in my NUKE "GetConfigurations" target I have the following to set the variable:
var output = string.Join(',', configurations.Select(x => $"\"{x}\""));
Console.WriteLine($"::set-output name=configurations::[{output}]");
As I said, this also works so far. But now it is the case that "::set-output" is deprecated and should not be used anymore. It was said that you should use the following instead:
echo 'KEY=VALUE' >> $GITHUB_OUTPUT
I have tested this and it also works when I define it directly in the workflow:
- name: Set configurations
id: set-configurations
run: echo 'configurations=["20200-Release","20201-Release","20202-Release"]' >> "$env:GITHUB_OUTPUT"
- name: echo output of previous step for testing
run: echo ${{ steps.set-configurations.outputs.configurations }}
However, if I now go and try to adjust the line in my NUKE target:
var output = string.Join(',', configurations.Select(x => $"\"{x}\""));
Console.WriteLine($"echo 'configurations=[{output}]' >> '$env:GITHUB_OUTPUT'");
And the workflow file:
- name: Get Build Configurations
id: generate-matrix
run: |
dotnet NukeComponents --root . --relative-project-file-path "PathToProjectFile" --dotnet --get-configurations
- name: echo output of previous step for testing
run: echo ${{ steps.generate-matrix.outputs.configurations }}
Then apparently I have the problem that "configurations" remains empty (Get as error message that InputObject in echo command is empty).
I have also tried things like setting the configurations as an environment variable in the NUKE target.
But I can't get it to work. It looks like the echo command is not executed, but just output. But maybe I am wrong and the error is somewhere else.
Can someone help me here?