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?
I think you can set outputs from Powershell by just echoing them to the console. Powershell has an alias mapping echo to Write-Output.
jobs:
  windows-test:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v1
      - name: Set outputs
        id: vars
        shell: pwsh
        run: echo "::set-output name=production::true"
      - name: Check outputs
        shell: pwsh
        run: echo ${{ steps.vars.outputs.production }}
ref: https://help.github.com/en/github/automating-your-workflow-with-github-actions/development-tools-for-github-actions#set-an-output-parameter-set-output
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With