pkgjs / action

Github Actions tooling for testing Node.js packages
MIT License
12 stars 2 forks source link

Support setting arbitrary secrets for tests step #33

Closed dominykas closed 2 years ago

dominykas commented 2 years ago

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: