Enable using loaded secrets from step's output

This commit is contained in:
Eddy Filip
2021-09-01 18:23:35 +02:00
parent ac12d2e3c4
commit 4baca64066
2 changed files with 23 additions and 11 deletions

View File

@@ -8,6 +8,9 @@ inputs:
unset-previous: unset-previous:
description: Whether to unset environment variables populated by 1Password in earlier job steps description: Whether to unset environment variables populated by 1Password in earlier job steps
default: false default: false
export-env:
description: Export the secrets as environment variables
default: false
runs: runs:
using: 'node12' using: 'node12'
main: 'dist/index.js' main: 'dist/index.js'

View File

@@ -62,6 +62,7 @@ for env_var in $(op env ls); do
done done
unset IFS unset IFS
if [ "$INPUT_EXPORT_ENV" == "true" ]; then
# To support multiline secrets, we'll use the heredoc syntax to populate the environment variables. # To support multiline secrets, we'll use the heredoc syntax to populate the environment variables.
# As the heredoc identifier, we'll use a randomly generated 64-character string, # As the heredoc identifier, we'll use a randomly generated 64-character string,
# so that collisions are practically impossible. # so that collisions are practically impossible.
@@ -75,6 +76,14 @@ for env_var in $(op env ls); do
} >> $GITHUB_ENV } >> $GITHUB_ENV
managed_variables+=("$env_var") managed_variables+=("$env_var")
else
# Prepare the secret_value to be outputed properly (especially multiline secrets)
secret_value=$(echo "$secret_value" | awk -v ORS='%0A' '1')
echo "::set-output name=$env_var::$secret_value"
fi
done done
unset IFS unset IFS