Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For GitHub Actions, outgoing env vars need to be written to $GITHUV_ENV file #2450

Merged
merged 3 commits into from
Nov 12, 2020

Conversation

DavidBoike
Copy link
Contributor

It turns out #2422 was an incorrect implementation of GitHub Actions' new way of exporting environment variables from a workflow step. GitHub Actions does not parse environment variables out of the log output. It generates a temporary file, which is different for every step of a workflow, that it identifies using the $GITHUB_ENV environment variable. You need to write each key as {NAME}={VALUE} to that temp file. GitHub Actions then parses that file and then (I believe) disposes of it before the next step starts.

So while #2422 still resulted in a correctly built binary, the exported environment variables essentially disappeared from any later step, making it impossible to do things like deploy prerelease builds to one environment and production builds to a different one.

Description

  • Identify file path from GITHUB_ENV value
  • Output key=value pairs to file
  • Change log output to indicate values are being written to file, to erase confusion that they are parsed from log output
  • If GITHUB_ACTIONS is set but GITHUB_ENV is missing, log a warning message

Related Issue

Motivation and Context

Regression in behavior previously working in GitHub Actions

How Has This Been Tested?

  • Updated unit tests for GitHub Actions to provide a temporary file in GITHUB_ENV and assert its contents are written correctly.
  • All unit tests run successfully.
  • Though I'd like to generate a package and test on my target project, I'm getting errors executing build.ps1.

Screenshots (if appropriate):

N/A

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@DavidBoike
Copy link
Contributor Author

Downloaded the NuGet artifact and tested it in my project - now all GitVersion variables are availble when dumping all env vars with Get-ChildItem Env:*.

Copy link
Member

@asbjornu asbjornu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Just a tiny nitpick and this should be good to go.

src/GitVersionCore/BuildAgents/GitHubActions.cs Outdated Show resolved Hide resolved
@asbjornu asbjornu added this to the 5.5.1 milestone Nov 12, 2020
@asbjornu asbjornu merged commit 19e7556 into GitTools:master Nov 12, 2020
@asbjornu
Copy link
Member

Excellent, thank you so much @DavidBoike & @danielmarbach! 🙏

@JesperMonsted
Copy link

Looking forward to having your fix in a release 👍

@github-actions
Copy link

🎉 This issue has been resolved in version 5.5.1 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] New GenerateBuildLogOutput for GitHub Actions in 5.5.0 doesn't export variables
4 participants