-
Notifications
You must be signed in to change notification settings - Fork 2
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
env-loader: Added gha-env writer #303
Conversation
Signed-off-by: Fred Heinecke <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the code can be greatly simplified.
// Generates a delimiter that is guaranteed to not contain the provided string. | ||
// This is required for writing multiline values to `GITHUB_ENV`, per | ||
// https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#multiline-strings | ||
func generateMultilineDelimiter(value string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're using UUID in your delimiter string, the chance of collision is negligible and this function is needlessly complicated and can be reduced to literally just
func getDelimiter() string {
return delimiterPrefix + "_" + uuid.NewString()
}
Maybe even no need for the function at all and just do it inline.
// Don't format strings without new lines as multiline. This would be valid, but a little | ||
// less readable. | ||
var renderedValue string | ||
if strings.Contains(value.UnderlyingValue, "\n") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth simplifying the logic and just using the multi-line format for everything?
Sure, I can simplify this as above. It'll just make the output much more difficult to visually parse when it's actually used. For example, it will turn this output:
into
|
@r0mant let me know what you think and I'll get the tests fixed. Using UUIDs everywhere every time will add an lot of boilerplate + regex to the tests, so I wanted to get feedback before I spend time on it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fheinecke Yeah it does look kinda ugly (which in hindsight it was kinda obvious it would). Up to you if you want to revert that particular change, lgtm either way.
I'm going to revert. If nothing else, this means that I can merge and move forward with the GHA env security project without spending more time on tests. |
92bddbe
to
5055ee5
Compare
This adds a new writer specifically for writing to
GITHUB_ENV
files. This format is close to dotenv files, but doesn't actually match it for multiline strings.Here's an example output:
Here's what it looks like for dotenv:
As shown above, dotenv doesn't handle new lines at all, and errors in this case as shown here.
While this is more GHA-specific logic, it is a necessary evil. We'll need something like this for any pipeline service.