-
Notifications
You must be signed in to change notification settings - Fork 347
Expand file tree
/
Copy pathgitlab-utils.sh
More file actions
executable file
·72 lines (59 loc) · 2.59 KB
/
Copy pathgitlab-utils.sh
File metadata and controls
executable file
·72 lines (59 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# From https://docs.gitlab.com/ci/jobs/job_logs/#use-a-script-to-improve-display-of-collapsible-sections
# function for starting the section
function gitlab_section_start () {
local section_title="${1}"
local section_description="${2:-$section_title}"
echo -e "section_start:`date +%s`:${section_title}[collapsed=true]\r\e[0K${section_description}"
}
# Function for ending the section
function gitlab_section_end () {
local section_title="${1}"
echo -e "section_end:`date +%s`:${section_title}\r\e[0K"
}
# Bootstrap Gradle through MASS, retrying upstream because the wrapper supports only one URL.
# The pinned checksum applies to either source. Call after `.gradle` and the Gradle environment are
# prepared.
function bootstrap_gradle_distribution () {
local props="gradle/wrapper/gradle-wrapper.properties"
local upstream_props="/tmp/gradle-wrapper.upstream.properties"
local mass_read_host
if [ -z "${MASS_READ_URL:-}" ]; then
./gradlew --version
return
fi
mass_read_host="${MASS_READ_URL#https://}"
mass_read_host="${mass_read_host%/}"
# Derive upstream even if an earlier call already routed the URL through MASS.
sed "/^distributionUrl=/ s|${mass_read_host}/internal/artifact/||" "$props" > "$upstream_props"
if grep -q "^distributionUrl=.*${mass_read_host}" "$props"; then
# Avoid nesting the MASS prefix.
echo "Gradle distribution is already routed through ${mass_read_host}"
else
# Redirect because GNU and BSD `sed -i` differ.
sed "/^distributionUrl=/ s|services.gradle.org|${mass_read_host}/internal/artifact/services.gradle.org|" "$props" > "$props.mass" &&
mv "$props.mass" "$props"
fi
if ./gradlew --version; then
rm -f "$upstream_props"
return
fi
if ! grep -q "^distributionUrl=" "$upstream_props"; then
echo -e "${TEXT_RED}Gradle distribution bootstrap failed and no upstream distributionUrl could be derived from ${props} to fall back to${TEXT_CLEAR}" >&2
return 1
fi
# Keep upstream: changing the URL changes the wrapper cache key and would download twice.
echo -e "${TEXT_YELLOW}MASS_FALLBACK gradle-distribution: ${MASS_READ_URL} could not serve the Gradle distribution, retrying via services.gradle.org${TEXT_CLEAR}" >&2
cp "$upstream_props" "$props"
rm -f "$upstream_props"
./gradlew --version
}
# A subset of ansi color/formatting codes https://misc.flogisoft.com/bash/tip_colors_and_formatting
export TEXT_RED="\e[31m"
export TEXT_GREEN="\e[32m"
export TEXT_YELLOW="\e[33m"
export TEXT_BLUE="\e[34m"
export TEXT_MAGENTA="\e[35m"
export TEXT_CYAN="\e[36m"
export TEXT_CLEAR="\e[0m"
export TEXT_BOLD="\e[1m"