RamblingCookieMonster / BuildHelpers

Helper functions for PowerShell CI/CD scenarios
MIT License
214 stars 47 forks source link

GitHub Action support #96

Closed devblackops closed 5 years ago

devblackops commented 5 years ago

This is more of an FYI.

I'm experimenting with various PowerShell use cases in GitHub Actions and some of them use BuildHelpers to determine some folder paths. I receive the following error when running Set-BuildEnvironment -Force when run within an Action.

Cannot index into a null array.
At /github/home/.local/share/powershell/Modules/BuildHelpers/2.0.0/Public/Get-BuildVariables.ps1:78 char:9
+         $GitPath = (Get-Command $GitPath -ErrorAction SilentlyContinu ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray

I'm going to dig into this more and hopefully submit a fix.

RamblingCookieMonster commented 5 years ago

Interesting - is git not available? I think that just runs ‘get-command git’, picks first in case multiple results come back (that’s where error is coming up - indexing into nothing)

devblackops commented 5 years ago

Ah ya, right...git is probably not on the image I'm using (mcr.microsoft.com/powershell:6.1.0-ubuntu-18.04). I'll add that and try again. Thanks!

RamblingCookieMonster commented 5 years ago

git won't be there, but seems like we could:

$GitPath = @(Get-Command $GitPath -ErrorAction SilentlyContinue)[0].Path (the array @ is new), or $GitPath = (Get-Command $GitPath -ErrorAction SilentlyContinue | Select-Object -First 1).Path

That said, yeah, if git not available, you'll lose some of the functionality if it isn't mapped to an expected env variable... We should definitely add GitHub Actions support! https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#environment-variables

devblackops commented 5 years ago

Failing gracefully would be nice. And having official support for Action env vars would be sweet!