Created
July 20, 2023 10:17
-
-
Save ohaval/98b0face7f28d3555327a0873e8e4137 to your computer and use it in GitHub Desktop.
Pass dynamic secrets to an action based on an input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Secrets trial | |
on: | |
workflow_dispatch: | |
inputs: | |
secrets_list: | |
required: true | |
description: 'List of secrets to pass to action' | |
jobs: | |
tmp-secrets: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Pass Secrets to Action | |
id: tmp-secrets | |
env: | |
SECRETS: ${{ toJSON(secrets) }} # Place the secrets as an env of the step, otherwise it's not possible to set them as environment variable inside a step's code | |
run: | | |
# Using jq to filter the secrets JSON only with keys requested by the user from the `secrets_list` input | |
echo "SECRETS_TO_PASS=$(echo "$SECRETS" | jq -c "with_entries(select(.key | IN($(echo '${{ inputs.secrets_list }}' | jq -r '@csv'))))")" > $GITHUB_OUTPUT | |
- name: Call action | |
uses: some-org/some-action-repo@some-tag | |
with: | |
s_dict: ${{ steps.tmp-secrets.outputs.SECRETS_TO_PASS }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment