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

Support setting arbitrary secrets for tests step #33

Merged
merged 1 commit into from
Jan 5, 2022

Conversation

dominykas
Copy link
Member

Closes #32

Sometimes tests require secret tokens to run (e.g. https://github.com/pkgjs/wiby needs GITHUB_TOKEN to properly test integration with Github). Reusable workflows do not make this easy - unlike regular steps, you're not allowed to set jobs.<job_id>.env for reusable workflows; the env vars set on the calling workflow are not passed through; the secrets need to be explicitly enumerated in the called (shared) workflow.

Hence the hack - pass the secrets as a JSON object 🤷‍♂️.

Usage:

jobs:
  test:
    uses: pkgjs/action/.github/workflows/node-test.yaml@main
    secrets:
      test-secrets: |-
        {
          "VERY_SECRET": ${{ toJSON(secrets.VERY_SECRET) }} 
        }

The param is called test-secrets, because it only sets the values for the test step. We have scope to explicitly add install-secrets, checkout-secrets, etc in the future.

I'll be writing up the documentation next, and I'll make sure to add the usual caveats of leaking secrets via environment.

Test runs:

@dominykas dominykas added the enhancement New feature or request label Jan 2, 2022
@@ -127,11 +132,31 @@ jobs:
uses: ./.github/tmp/post-install-steps


- name: Set environment variables for tests
id: set-env-vars-for-tests
shell: bash
Copy link
Member

Choose a reason for hiding this comment

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

What happens on a windows test run?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@ljharb ljharb Jan 2, 2022

Choose a reason for hiding this comment

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

Ah i see, because it’s just used to inform GHA, not to change anything about the runner. Nice!

This one step alone seems like it’d be useful as a reusable action :-)

@dominykas dominykas merged commit edd1297 into main Jan 5, 2022
@dominykas dominykas deleted the arbitrary-test-secrets branch January 5, 2022 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support passing in additional secrets into the test step
3 participants