AArnott / Library.Template

A template for a NuGet package with tests, stylecop, fxcop, versioning, and Azure Pipelines build ready to go.
MIT License
131 stars 26 forks source link

Unable to process GitAssemblyInformationVersion environment variable on GitHub Action on Mac Agent #116

Closed SteveBush closed 3 years ago

SteveBush commented 3 years ago

On GitHub Actions, a build running on the Mac agent fails because it cannot process the GitAssemblyInformationalVersion environment variable.

Below is an example of the error and env: output.


2021-09-12T16:06:08.6504860Z ##[error]Unable to process file command 'env' successfully.
2021-09-12T16:06:08.6522240Z ##[error]Invalid environment variable format 'GitAssemblyInformationalVersio'
2021-09-12T16:06:08.6849210Z ##[group]Run azure-pipelines/artifacts/_stage_all.ps1
2021-09-12T16:06:08.6850020Z azure-pipelines/artifacts/_stage_all.ps1
2021-09-12T16:06:08.6961780Z shell: /usr/local/bin/pwsh -command ". '{0}'"
2021-09-12T16:06:08.6962190Z env:
2021-09-12T16:06:08.6962640Z   TreatWarningsAsErrors: true
2021-09-12T16:06:08.6963200Z   DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
2021-09-12T16:06:08.6963770Z   codecov_token: 4dc9e7e2-6b01-4932-a180-847b52b43d35
2021-09-12T16:06:08.6964590Z   NUGET_PACKAGES: /Users/runner/work/NetworkVisor.Core/NetworkVisor.Core/.nuget/packages
2021-09-12T16:06:08.6965640Z   NUGET_NAME: networkvisor-eng
2021-09-12T16:06:08.6966530Z   NUGET_URL: https://pkgs.dev.azure.com/NetworkVisor/_packaging/networkvisor-eng/nuget/v3/index.json
2021-09-12T16:06:08.6967470Z   BUILDCONFIGURATION: Release-macOS
2021-09-12T16:06:08.6968210Z   DOTNET_MULTILEVEL_LOOKUP: 0
2021-09-12T16:06:08.6968750Z   DOTNET_ROOT: /Users/runner/hostedtoolcache/dotnet
2021-09-12T16:06:08.6969510Z   DOTNETSDKVERSION: 6.0.100-preview.7.21379.14
2021-09-12T16:06:08.6970370Z   GitAssemblyInformationalVersion: 2.3.168-prerelease+fde304b90b
2021-09-12T16:06:08.6971140Z   GitBuildVersion: 2.3.168.58365
2021-09-12T16:06:08.6971640Z   GitBuildVersionSimple: 2.3.168
2021-09-12T16:06:08.6972200Z   n: 2.3.168-prerelease+fde304b90b
2021-09-12T16:06:08.6972650Z ##[endgroup]
AArnott commented 3 years ago

I'm curious why you're filing this issue on this repo. The error comes from github in response to an operation executed by Nerdbank.GitVersioning, which this repo happens to consume. I haven't seen this error on this repo before. Can you file that over at Nerdbank.GitVersioning instead for triage?

AArnott commented 3 years ago

Oh, I think I understand a bit more now. You've probably changed your instance of this template to enable this task on mac:

https://github.com/AArnott/Library.Template/blob/eba9acb28b6c66b40a14d7759365b20a9d89df0f/.github/workflows/build.yml#L96-L101

And then it fails. I'm not sure why. But the failure talks about an env var set by Nerdbank.GitVersioning. I suspect it may be a bug in github actions itself, or it might be nerdbank.gitversioning. But I'll reactivate here to investigate a bit more.

SteveBush commented 3 years ago

Sorry, I should have mentioned that I have enabled Build on macOS. I created the issue here because I wasn't sure if it was a problem with Nerdbank.GitVersioning, the template or GitHub Actions.

parameters:
- name: includeMacOS
  displayName: Build on macOS
  type: boolean
  default: true # macOS is often bogged down in Azure Pipelines

Also, here's my version.json:

{
  "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
  "version": "2.3-prerelease",
  "publicReleaseRefSpec": [
    "^refs/heads/main$",
    "^refs/heads/v\\d+(?:\\.\\d+)?$"
  ]
}
AArnott commented 3 years ago

Your includeMacOS parameter snippet is specific to Azure Pipelines. Our GitHub Actions workflow file has nothing like that. It always runs on mac. I just enabled more build steps on the mac github workflow in #117 and I don't repro the error you're seeing.

Can you please provide more context into your problem? Such as:

  1. Which step is failing? Is it a step included in the template?
  2. Can you find the equivalent step in the template and observe whether it's working here on this repo's github workflows?
  3. Is this failing consistently for you, or was this a one-time failure?
  4. I wonder if you're setting env vars twice. I see in setting GitAssemblyInformationalVersio (which is missing an n). I also see in your env listing that both n and GitAssemblyInformationalVersion (with an n!) are set. This suggests that both a failure and a success occurred.
SteveBush commented 3 years ago

I should wait until I've had coffee to respond to issues. I should have included the Github build.yml.

Let me do some more investigation before I waste more of your time. Given your investigations above, it seems likely this is a problem with my Mac build on GitHub Actions (mac build on Azure Pipelines works fine) and not a general problem with the template or Nerdbank.GitVersioning.

I will also merge #117 into my repository. Thanks again.

SteveBush commented 3 years ago

I finally had some bandwidth to dig into this further. On Mac, creating an environment variable using >> corrupted the $GITHUB_ENV file. I believe this is a UTF8 issue. I changed to using PowerShell to append to the file with utf8 encoding and everything works fine.

FYI. I use the build configuration of Release-MacOS to determine which projects are built on the MacOS pipeline host. Similar for Linux, and Windows. I had create per host build configurations so I could build mobile apps (IOS, MacCatalyst, Android, WinUI) on a compatible agent/runner.

    - name: Set build configuration on Mac
      run: |
OLD:        echo "BUILDCONFIGURATION=Release-MacOS" >> $GITHUB_ENV
NEW:        echo "BUILDCONFIGURATION=Release-MacOS" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
      shell: pwsh
      if: runner.os == 'macOS'