Skip to content

Commit dedc18b

Browse files
committed
Properly handle the different environments
1 parent 31e8080 commit dedc18b

File tree

5 files changed

+109
-35
lines changed

5 files changed

+109
-35
lines changed

src/commands/prepare-env.yml

+3
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,8 @@ steps:
7676
PARAM_GIT_PRIVATE_TOKEN: << parameters.git-private-token-var-name >>
7777
PARAM_PROJECT_PATH: << parameters.project-path >>
7878
SCRIPT_UTILS: << include(scripts/utils.sh) >>
79+
SCRIPT_GIT_CREDENTIAL_LINUX: << include(scripts/linux/set-gitcredential.sh) >>
80+
SCRIPT_GIT_CREDENTIAL_WINDOWS: << include(scripts/windows/set-gitcredential.sh) >>
81+
SCRIPT_GIT_CREDENTIAL_MACOS: << include(scripts/macos/set-gitcredential.sh) >>
7982
command: << include(scripts/set-gitcredential.sh) >>
8083

src/scripts/linux/git-credential.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/false
2+
# shellcheck shell=bash
3+
# shellcheck disable=SC2154
4+
5+
if [ -z "${GIT_PRIVATE_TOKEN}" ]
6+
then
7+
echo "GIT_PRIVATE_TOKEN unset skipping"
8+
else
9+
echo "GIT_PRIVATE_TOKEN is set configuring git credentials"
10+
11+
git config --global credential.helper store
12+
git config --global --replace-all url."https://token:$GIT_PRIVATE_TOKEN@github.com/".insteadOf ssh://[email protected]/
13+
git config --global --add url."https://token:$GIT_PRIVATE_TOKEN@github.com/".insteadOf [email protected]
14+
git config --global --add url."https://token:$GIT_PRIVATE_TOKEN@github.com/".insteadOf "https://github.com/"
15+
16+
git config --global url."https://ssh:$GIT_PRIVATE_TOKEN@github.com/".insteadOf "ssh://[email protected]/"
17+
git config --global url."https://git:$GIT_PRIVATE_TOKEN@github.com/".insteadOf "[email protected]:"
18+
19+
fi
20+
21+
echo "---------- git config --list -------------"
22+
git config --list
23+
24+
echo "---------- git config --list --show-origin -------------"
25+
git config --list --show-origin
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/false
2+
# shellcheck shell=bash
3+
# shellcheck disable=SC2154
4+
5+
if [ -z "${GIT_PRIVATE_TOKEN}" ]
6+
then
7+
echo "GIT_PRIVATE_TOKEN unset skipping"
8+
else
9+
echo "GIT_PRIVATE_TOKEN is set configuring git credentials"
10+
11+
git config --global credential.helper store
12+
git config --global --replace-all url."https://token:$GIT_PRIVATE_TOKEN@github.com/".insteadOf ssh://[email protected]/
13+
git config --global --add url."https://token:$GIT_PRIVATE_TOKEN@github.com/".insteadOf [email protected]
14+
git config --global --add url."https://token:$GIT_PRIVATE_TOKEN@github.com/".insteadOf "https://github.com/"
15+
16+
git config --global url."https://ssh:$GIT_PRIVATE_TOKEN@github.com/".insteadOf "ssh://[email protected]/"
17+
git config --global url."https://git:$GIT_PRIVATE_TOKEN@github.com/".insteadOf "[email protected]:"
18+
19+
fi
20+
21+
echo "---------- git config --list -------------"
22+
git config --list
23+
24+
echo "---------- git config --list --show-origin -------------"
25+
git config --list --show-origin

src/scripts/set-gitcredential.sh

+3-35
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,7 @@ detect-os
1414
readonly git_private_token="${!PARAM_GIT_PRIVATE_TOKEN}"
1515
readonly CONTAINER_NAME="${CIRCLE_PROJECT_REPONAME}-${CIRCLE_BUILD_NUM}"
1616

17-
trap_exit() {
18-
local exit_status="$?"
19-
20-
if [ "$exit_status" -ne 0 ]; then
21-
printf '%s\n' 'The script did not complete successfully.'
22-
23-
printf '%s\n' "Removing the container \"$CONTAINER_NAME\"."
24-
docker rm -f "$CONTAINER_NAME" &> /dev/null || true
25-
26-
exit "$exit_status"
27-
fi
28-
}
29-
trap trap_exit EXIT
30-
31-
32-
if [ -z "${git_private_token}" ]
33-
then
34-
echo "GIT_PRIVATE_TOKEN unset skipping"
35-
else
36-
echo "GIT_PRIVATE_TOKEN is set configuring git credentials"
37-
38-
docker exec "$CONTAINER_NAME" "git config --global credential.helper store"
39-
docker exec "$CONTAINER_NAME" "git config --global --replace-all url.\"https://token:$git_private_token@github.com/\".insteadOf ssh://[email protected]/"
40-
docker exec "$CONTAINER_NAME" "git config --global --add url.\"https://token:$git_private_token@github.com/\".insteadOf [email protected]"
41-
docker exec "$CONTAINER_NAME" "git config --global --add url.\"https://token:$git_private_token@github.com/\".insteadOf \"https://github.com/\""
42-
43-
docker exec "$CONTAINER_NAME" "git config --global url.\"https://ssh:$git_private_token@github.com/\".insteadOf \"ssh://[email protected]/\""
44-
docker exec "$CONTAINER_NAME" "git config --global url.\"https://git:$git_private_token@github.com/\".insteadOf \"[email protected]:\""
45-
17+
if [ "$PLATFORM" = "linux" ]; then eval "$SCRIPT_GIT_CREDENTIAL_LINUX";
18+
elif [ "$PLATFORM" = "macos" ]; then eval "$SCRIPT_GIT_CREDENTIAL_MACOS";
19+
elif [ "$PLATFORM" = "windows" ]; then eval "$SCRIPT_GIT_CREDENTIAL_WINDOWS";
4620
fi
47-
48-
echo "---------- git config --list -------------"
49-
docker exec "$CONTAINER_NAME" "git config --list"
50-
51-
echo "---------- git config --list --show-origin -------------"
52-
docker exec "$CONTAINER_NAME" "git config --list --show-origin"
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/false
2+
# shellcheck shell=bash
3+
# shellcheck disable=SC2016,SC2154
4+
5+
readonly base_dir="${CIRCLE_WORKING_DIRECTORY/\~/$HOME}"
6+
readonly unity_project_full_path="$base_dir/$PARAM_PROJECT_PATH"
7+
8+
# Import "utils.sh".
9+
eval "$SCRIPT_UTILS"
10+
11+
# Detect host OS.
12+
detect-os
13+
14+
# Expand environment name variable parameters.
15+
readonly git_private_token="${!PARAM_GIT_PRIVATE_TOKEN}"
16+
readonly CONTAINER_NAME="${CIRCLE_PROJECT_REPONAME}-${CIRCLE_BUILD_NUM}"
17+
18+
trap_exit() {
19+
local exit_status="$?"
20+
21+
if [ "$exit_status" -ne 0 ]; then
22+
printf '%s\n' 'The script did not complete successfully.'
23+
24+
printf '%s\n' "Removing the container \"$CONTAINER_NAME\"."
25+
docker rm -f "$CONTAINER_NAME" &> /dev/null || true
26+
27+
exit "$exit_status"
28+
fi
29+
}
30+
trap trap_exit EXIT
31+
32+
33+
if [ -z "${git_private_token}" ]
34+
then
35+
echo "GIT_PRIVATE_TOKEN unset skipping"
36+
else
37+
echo "GIT_PRIVATE_TOKEN is set configuring git credentials"
38+
39+
docker exec "$CONTAINER_NAME" "git config --global credential.helper store"
40+
docker exec "$CONTAINER_NAME" "git config --global --replace-all url.\"https://token:$git_private_token@github.com/\".insteadOf ssh://[email protected]/"
41+
docker exec "$CONTAINER_NAME" "git config --global --add url.\"https://token:$git_private_token@github.com/\".insteadOf [email protected]"
42+
docker exec "$CONTAINER_NAME" "git config --global --add url.\"https://token:$git_private_token@github.com/\".insteadOf \"https://github.com/\""
43+
44+
docker exec "$CONTAINER_NAME" "git config --global url.\"https://ssh:$git_private_token@github.com/\".insteadOf \"ssh://[email protected]/\""
45+
docker exec "$CONTAINER_NAME" "git config --global url.\"https://git:$git_private_token@github.com/\".insteadOf \"[email protected]:\""
46+
47+
fi
48+
49+
echo "---------- git config --list -------------"
50+
docker exec "$CONTAINER_NAME" "git config --list"
51+
52+
echo "---------- git config --list --show-origin -------------"
53+
docker exec "$CONTAINER_NAME" "git config --list --show-origin"

0 commit comments

Comments
 (0)