Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

Commit

Permalink
chore: add support for dotenv var exporting
Browse files Browse the repository at this point in the history
Script for manual reloading without issuing direnv reload command
should arrive within this week, as I need to check if I borked the CI.

Signed-off-by: Andrei Jiroh Eugenio Halili <[email protected]>
  • Loading branch information
ajhalili2006 committed Dec 21, 2021
1 parent 958c4ef commit f3cd9e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This is an example dotenv file for everyone to duplicate as .env. Remember not to
# commit secrets!

# Change text editors, especially if you're inside an container.
# EDITOR=nano
# VISUAL=nano
18 changes: 12 additions & 6 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
#!/usr/bin/env bash
# shellcheck disable=SC2155

REPO_ROOT="$(git rev-parse --show-toplevel)"
export PATH="$REPO_ROOT/.gitlab/ci/scripts:$PATH"
export REPO_ROOT="$(git rev-parse --show-toplevel)"
export PATH="$REPO_ROOT/.gitlab/ci/scripts:$REPO_ROOT/devkit/bin:$PATH"

# Simulate GitLab CI environment as much as possible.
# Simulate GitLab CI environment as much as possible. The only problem would be if the URL is SSH clone one.
export CI_PROJECT_URL=$(git remote get-url origin)
# https://stackoverflow.com/a/50126161
export CI_PROJECT_PATH="$(grep -Po '\w\K/\w+[^?]+' <<< "$CI_PROJECT_URL")"
# https://gist.github.com/oneohthree/f528c7ae1e701ad990e6#gistcomment-2862791
CI_PROJECT_PATH_SLUG_TMP="$(echo "$CI_PROJECT_PATH" | iconv -t ascii//TRANSLIT | sed -r s/[~\^]+//g | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z)"
export CI_PROJECT_PATH_SLUG=${CI_PROJECT_PATH_SLUG_TMP:-"gitpodify-gitpodified-wworkspace-images"}
# Tip: If you really need to simulate some scripts in an GitLab MR context,
# touch .emulate-gitlab-mergerequest-pipelines in the root directory of this repo.

# Tip: If you really need to simulate some scripts in an GitLab MR context, touch .emulate-gitlab-mergerequest-pipelines
# in the root directory of this repo, then `direnv reload`.
if [[ -f "${REPO_ROOT:-"$PWD"}/.emulate-gitlab-mergerequest-pipelines" ]]; then
export CI_PIPELINE_SOURCE="merge_request_event"
fi
fi

# Export key-value pairs with this magic from dotenv.
if [ -f .env ]; then
export $(echo $(cat ".env" | sed 's/#.*//g'| xargs) | envsubst)
fi

0 comments on commit f3cd9e1

Please sign in to comment.