I'm setting up GitHub Actions as a CI for one of my projects, and the entire build process is basically a PowerShell script, driven by environment variables.
This is both to minimize vendor lock in, and to make sure I can run a build locally with pretty much the same process.
Now, my build script determines some stuff and puts it into environment variables - specifically, I have an MH_IS_PROD_BUILD
variable that's either True or False, and determines which nuget package repository I push to.
However, when the step that runs the shell is done, the environment variable ceases to exist, as further steps are run in a new environment it seems.
What I want to do is something like this (abbreviated):
steps:
- name: Run build script
id: pwshbuild
shell: pwsh
run: |
cd scripts
./build.ps1
# The above sets $Env:MH_IS_PROD_BUILD to either True or False
- name: Push Publish to GPR (Dev Package)
if: steps.pwshbuild.outputs.MH_IS_PROD_BUILD == 'False'
shell: pwsh
run: |
# omitted: determine $nupkgPath
nuget push $nupkgPath -Source "GPR" -SkipDuplicate
- name: Push Publish to Nuget.org (Release Package)
if: steps.pwshbuild.outputs.MH_IS_PROD_BUILD == 'True'
shell: pwsh
run: |
# omitted: determine $nupkgPath
nuget push $nupkgPath -Source "NugetOrg" -SkipDuplicate
It appears that outputs is what I'd need, but that seems to require creation of a custom action?
The above does not work, of course (hence asking). So I'm wondering, what is the best way forward?
- Can I set the outputs of a step from PowerShell? (preferred)
- Do I have to create a custom action to encapsulate my call to build.ps1 so that I can return stuff via outputs?