Skip to content

pathogen-repo-ci: Allow caller to pass env vars#23

Merged
tsibley merged 2 commits intomasterfrom
trs/pathogen-repo-ci/env
May 23, 2022
Merged

pathogen-repo-ci: Allow caller to pass env vars#23
tsibley merged 2 commits intomasterfrom
trs/pathogen-repo-ci/env

Conversation

@tsibley
Copy link
Copy Markdown
Contributor

@tsibley tsibley commented May 23, 2022

This can be useful to set variables respected by Augur, Nextstrain CLI,
etc. Implemented ourselves as a workflow input since the usual job.env
block is not (yet?) supported by GitHub Actions for jobs which call a
reusable workflow.

The input value is a YAML-formatted string, which you can easily produce
by pretending you're writing normal nested YAML within a literal
multi-line block scalar (introduced by "|"):

   with:
     env: |
       FOO: bar
       I_CANT_BELIEVE: "it's not YAML"

When (if?) the usual job.env block is supported for reusable workflows,
it will be a small transformation for each caller to use it.

Testing

Tested in a separate GitHub Actions testbed, though I may have mucked up the syntax in this particular file. We'll see when I try to use it!

Update: Usage in nextstrain/mpox#8 found a small place I mucked up, which is now fixed and that PR's CI ran successfully.

tsibley added a commit to nextstrain/mpox that referenced this pull request May 23, 2022
@tsibley tsibley requested a review from a team May 23, 2022 22:30
This can be useful to set variables respected by Augur, Nextstrain CLI,
etc.  Implemented ourselves as a workflow input since the usual job.env
block is not (yet?) supported by GitHub Actions for jobs which call a
reusable workflow.

The input value is a YAML-formatted string, which you can easily produce
by pretending you're writing normal nested YAML within a literal
multi-line block scalar (introduced by "|"):

   with:
     env: |
       FOO: bar
       I_CANT_BELIEVE: "it's not YAML"

When (if?) the usual job.env block is supported for reusable workflows,
it will be a small transformation for each caller to use it.
Copy link
Copy Markdown
Member

@victorlin victorlin left a comment

Choose a reason for hiding this comment

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

Seems hacky but probably the best option for now!

| yq --output-format json .
| jq --raw-output '
to_entries
| map("\(.key)<<__EOF__\n\(.value)\n__EOF__")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[non-blocking]

Is this heredoc for variables? How'd you know it works for $GITHUB_ENV? I tried running it directly:

I_CANT_BELIEVE<<__EOF__
it's not YAML
__EOF__
# bash: I_CANT_BELIEVE: command not found

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's not standard Bash, but something that GitHub Actions implements, see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings.

Copy link
Copy Markdown
Contributor Author

@tsibley tsibley May 23, 2022

Choose a reason for hiding this comment

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

Added a comment about this in c90c1b1.

@tsibley tsibley merged commit 96a99a9 into master May 23, 2022
@tsibley tsibley deleted the trs/pathogen-repo-ci/env branch May 23, 2022 23:52
@tsibley
Copy link
Copy Markdown
Contributor Author

tsibley commented May 23, 2022

Seems hacky but probably the best option for now!

Definitely hacky! but yeah…

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants