Skip to content
Snippets Groups Projects
Commit 3f22d1f6 authored by Timo Furrer's avatar Timo Furrer
Browse files

Merge branch 'rename-sourced-var' into 'main'

Rename `TF_GITLAB_SOURCED` variable to `GITLAB_TOFU_SOURCED`

See merge request components/opentofu!188
parents 543cda32 d003be31
Branches
Tags
No related merge requests found
......@@ -300,6 +300,9 @@ and will try to execute a `tofu` command.
In this case you can set the `GITLAB_TOFU_SOURCE` environment variable
to `true` before sourcing `gitlab-tofu`.
When the `gitlab-tofu` script is sourced it'll set the `GITLAB_TOFU_SOURCED`
variable to `true`. This variable is not exported by the script itself.
### Best Practices
This section is a collection of *some* best practices.
......
......@@ -315,6 +315,9 @@ and will try to execute a `tofu` command.
In this case you can set the `GITLAB_TOFU_SOURCE` environment variable
to `true` before sourcing `gitlab-tofu`.
When the `gitlab-tofu` script is sourced it'll set the `GITLAB_TOFU_SOURCED`
variable to `true`. This variable is not exported by the script itself.
### Best Practices
This section is a collection of *some* best practices.
......
......@@ -18,6 +18,7 @@ fi
# Evaluate if this script is being sourced or executed directly.
# See https://stackoverflow.com/a/28776166
sourced=0
# shellcheck disable=SC2153 # it's actually a different variable, thanks shelllcheck.
if [ "$GITLAB_TOFU_SOURCE" = 'true' ]; then
sourced=1
elif [ -n "$ZSH_VERSION" ]; then
......@@ -276,5 +277,5 @@ if [ $sourced -eq 0 ]; then
else
# This variable can be used if the script is sourced
# shellcheck disable=SC2034
TF_GITLAB_SOURCED=true
GITLAB_TOFU_SOURCED=true
fi
......@@ -151,9 +151,9 @@ EOF
cat <<'EOF' > test.sh
set -x
test -z "$TF_GITLAB_SOURCED"
test -z "$GITLAB_TOFU_SOURCED"
. $(which gitlab-tofu)
test "$TF_GITLAB_SOURCED"
test "$GITLAB_TOFU_SOURCED"
EOF
$SHELL test.sh
......@@ -165,9 +165,9 @@ EOF
cat <<'EOF' > test.sh
set -x
test -z "$TF_GITLAB_SOURCED"
test -z "$GITLAB_TOFU_SOURCED"
. $(which gitlab-tofu)
test "$TF_GITLAB_SOURCED"
test "$GITLAB_TOFU_SOURCED"
EOF
mkdir -p /usr/local/sbin
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment