diff --git a/.gitlab/README.md.template b/.gitlab/README.md.template index f1737298909cc067c8d36837c87e358240ac7f1a..d48a45ed6c3d34848156d0cdf54f763bb1372191 100644 --- a/.gitlab/README.md.template +++ b/.gitlab/README.md.template @@ -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. diff --git a/README.md b/README.md index c2e88f42bd106ab79e482b207465a79e9e2bfb3a..11e74bb8dd06b5ad5dffc2f99f7ac5941eaca90b 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/gitlab-tofu.sh b/src/gitlab-tofu.sh index 075c6d212f2ead8230f186f05dde34e79b1f691e..3e9c167d34abe5f53acb24bc9d215f848412b3bb 100644 --- a/src/gitlab-tofu.sh +++ b/src/gitlab-tofu.sh @@ -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 diff --git a/tests/unit/gitlab-tofu.bats b/tests/unit/gitlab-tofu.bats index faf2d312ed717a377ccb243c4585886a5a9cb84f..5b00ef1879529ec32d0fea08091ea368675e0c83 100644 --- a/tests/unit/gitlab-tofu.bats +++ b/tests/unit/gitlab-tofu.bats @@ -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