forked from IBM/action-runner-image-pz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure-runner.sh
More file actions
executable file
·104 lines (83 loc) · 2.45 KB
/
Copy pathconfigure-runner.sh
File metadata and controls
executable file
·104 lines (83 loc) · 2.45 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
set -euo pipefail
header() {
TS=$(date +"%Y-%m-%dT%H:%M:%S%:z")
echo "${TS} +--------------------------------------------+"
echo "${TS} | $*"
echo "${TS} +--------------------------------------------+"
echo
}
msg() {
# shellcheck disable=SC2046
echo $(date +"%Y-%m-%dT%H:%M:%S%:z") "$*"
}
check_idempotency() {
header "Checking Idempotency"
msg "Fetching latest upstream version from ${RUNNERREPO}..."
UPSTREAM_TAG=$(git ls-remote --tags --refs --sort='v:refname' "${RUNNERREPO}" | tail -n1 | awk -F/ '{print $NF}')
UPSTREAM_VER="${UPSTREAM_TAG#v}"
msg "Latest Upstream Version: ${UPSTREAM_VER}"
CURRENT_VER="none"
if [ -f "/opt/runner-cache/bin/Runner.Listener" ]; then
CURRENT_VER=$(/opt/runner-cache/bin/Runner.Listener --version 2>/dev/null || echo "error")
fi
msg "Current Installed Version: ${CURRENT_VER}"
if [ "${UPSTREAM_VER}" == "${CURRENT_VER}" ]; then
header "Versions match (${UPSTREAM_VER}). Skipping build."
exit 0
else
msg "Versions do not match or runner not installed. Proceeding with build..."
fi
}
patch_runner() {
header "Cloning repo and Patching runner"
cd /tmp
git clone --tags -q "${RUNNERREPO}"
cd runner
# shellcheck disable=SC2046
git checkout $(git tag --sort=-v:refname | grep '^v[0-9]' | head -n1)
git apply --whitespace=nowarn "${IMAGE_FOLDER}"/runner-sdk-8.patch
sed -i'' -e '/version/s/8......"$/8.0.100"/' src/global.json
}
build_runner() {
export DOTNET_NUGET_SIGNATURE_VERIFICATION=false
header "Building runner binary"
cd src
msg "Running dev layout"
./dev.sh layout Release
msg "Creating package"
./dev.sh package Release
msg "Running tests"
./dev.sh test
}
install_runner() {
header "Installing runner"
mkdir -p /opt/runner-cache
tar -xf /tmp/runner/_package/*.tar.gz -C /opt/runner-cache
}
pre_cleanup() {
rm -rf /tmp/runner /opt/runner-cache
}
post_cleanup() {
rm -rf "${IMAGE_FOLDER}"/runner-sdk-8.patch \
/tmp/preseed-yaml /home/ubuntu/.nuget \
/home/runner/.local/share
}
run() {
check_idempotency
pre_cleanup
patch_runner
build_runner
install_runner
post_cleanup
}
RUNNERREPO="https://github.com/actions/runner"
# Parse arguments
while getopts "a:" opt; do
case ${opt} in
a) RUNNERREPO=${OPTARG} ;;
*) exit 1 ;;
esac
done
shift $(( OPTIND - 1 ))
run