From d003be31b40f63b0779839de292f4a5e6cc20dff Mon Sep 17 00:00:00 2001 From: Timo Furrer <tfurrer@gitlab.com> Date: Wed, 13 Nov 2024 12:02:21 +0100 Subject: [PATCH] Rename `TF_GITLAB_SOURCED` variable to `GITLAB_TOFU_SOURCED`. This change set renames the `TF_GITLAB_SOURCED` environment variable to `GITLAB_TOFU_SOURCED` and document the existence of the variable accordingly in the README. The reason for renaming it is that the `TF_` variable prefix is "owned" by OpenTofu / Terraform and not GitLab Tofu. Therefore, we make an effort to rename these variables to have the `GITLAB_TOFU_` prefix instead. Changelog: changed --- .gitlab/README.md.template | 3 +++ README.md | 3 +++ src/gitlab-tofu.sh | 3 ++- tests/unit/gitlab-tofu.bats | 8 ++++---- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.gitlab/README.md.template b/.gitlab/README.md.template index f173729..d48a45e 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 c2e88f4..11e74bb 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 075c6d2..3e9c167 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 faf2d31..5b00ef1 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 -- GitLab