ci: Add Load runner environment action to copy variables from runner process into job environment
This commit is contained in:
1 file changed
+51
@@ -0,0 +1,51 @@
|
|||||||
|
name: Load runner environment
|
||||||
|
description: Copy named variables from the runner process into the job env context.
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
names:
|
||||||
|
description: Space-separated variable names, loaded in the given order.
|
||||||
|
required: true
|
||||||
|
required:
|
||||||
|
description: Fail when a named variable is missing or empty.
|
||||||
|
required: false
|
||||||
|
default: "true"
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: composite
|
||||||
|
steps:
|
||||||
|
- name: Load runner environment
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
LOAD_ENV_NAMES: ${{ inputs.names }}
|
||||||
|
LOAD_ENV_REQUIRED: ${{ inputs.required }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
if [[ -z "${LOAD_ENV_NAMES// }" ]]; then
|
||||||
|
echo "No environment variable names were given"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
for name in $LOAD_ENV_NAMES; do
|
||||||
|
if [[ ! "$name" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]]; then
|
||||||
|
echo "Invalid environment variable name: ${name}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
value="${!name-}"
|
||||||
|
if [[ -z "$value" ]]; then
|
||||||
|
if [[ "${LOAD_ENV_REQUIRED}" == "true" ]]; then
|
||||||
|
echo "${name} is not set on this runner"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Skipping unset ${name}"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [[ "$value" != *$'\n'* ]]; then
|
||||||
|
echo "::add-mask::${value}"
|
||||||
|
fi
|
||||||
|
delimiter="LOAD_ENV_${name}_${RANDOM}_$$"
|
||||||
|
{
|
||||||
|
printf '%s<<%s\n' "$name" "$delimiter"
|
||||||
|
printf '%s\n' "$value"
|
||||||
|
printf '%s\n' "$delimiter"
|
||||||
|
} >> "$GITHUB_ENV"
|
||||||
|
echo "Loaded ${name} from the runner"
|
||||||
|
done
|
||||||
Reference in new issue
Block a user