Skip to content

Commit

Permalink
Merge pull request #33 from pkgjs/arbitrary-test-secrets
Browse files Browse the repository at this point in the history
Support setting arbitrary secrets for tests step
  • Loading branch information
dominykas authored Jan 5, 2022
2 parents e9066b2 + aa6fd00 commit edd1297
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions .github/workflows/node-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ on:
required: false
type: string

secrets:
test-secrets:
description: "A JSON object with the secret environment variables to be set for the 'Run tests' step. Values will be masked in output."
required: false

jobs:

prepare-node-matrix:
Expand Down Expand Up @@ -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
run: |
# mask all values in the input vars
echo ${INPUT_VARS} | jq -c -r '.[] | "::add-mask::" + .'
# set the matrix variables into env for tests
MERGED_VARS=$(cat <<EOF | jq -c -s '.[0] * .[1]'
${INPUT_VARS}
{
"MATRIX_NODE_VERSION":"${{ matrix.node-version }}",
"NODE_LTS_LATEST":"${{ needs.prepare-node-matrix.outputs.lts-latest }}"
}
EOF
)
# output the merged variables
echo "::set-output name=env-vars::${MERGED_VARS}"
env:
INPUT_VARS: ${{ secrets.test-secrets || '{}' }}

- name: Run tests
run: ${{ inputs.test-command }}
env:
MATRIX_NODE_VERSION: ${{ matrix.node-version }}
NODE_LTS_LATEST: ${{ needs.prepare-node-matrix.outputs.lts-latest }}
env: ${{ fromJson(steps.set-env-vars-for-tests.outputs.env-vars) }}

- name: Run post-test steps
if: ${{ inputs.post-test-steps }}
Expand Down

0 comments on commit edd1297

Please sign in to comment.