44
55echo " Checking for updates to workbench-template from GitHub"
66
7+ # Ensure jq is installed for JSON parsing
8+ if ! command -v jq & > /dev/null; then
9+ echo " Installing jq for JSON parsing..."
10+ sudo apt-get update && sudo apt-get install -y jq
11+ fi
12+
713WORKSPACE_DIR=" /workspaces/spark-template"
814
915MARKER_DIR=" /var/lib/spark/.versions"
@@ -12,11 +18,28 @@ TOOLS_MARKER_FILE="$MARKER_DIR/tools"
1218
1319sudo mkdir -p " $MARKER_DIR "
1420
21+ # Check if TEMPLATE_PAT is set
22+ if [ -z " $TEMPLATE_PAT " ]; then
23+ echo " TEMPLATE_PAT environment variable is not set. Skipping tools update."
24+ exit 0
25+ fi
26+
1527# Fetch the latest release information
1628LATEST_RELEASE=$( curl -s -H " Authorization: token $TEMPLATE_PAT " https://api.github.com/repos/github/spark-template/releases/latest)
1729
30+ # Check if the API call succeeded
31+ if [ $? -ne 0 ] || [ -z " $LATEST_RELEASE " ]; then
32+ echo " Failed to fetch release information from GitHub. Skipping tools update."
33+ exit 0
34+ fi
35+
1836# Check if marker file exists and has the same release ID
1937RELEASE_ID=$( echo " $LATEST_RELEASE " | jq -r ' .id' )
38+ if [ " $RELEASE_ID " == " null" ] || [ -z " $RELEASE_ID " ]; then
39+ echo " Invalid release data received from GitHub. Skipping tools update."
40+ exit 0
41+ fi
42+
2043if [ -f " $RELEASE_MARKER_FILE " ] && [ " $( cat " $RELEASE_MARKER_FILE " ) " == " $RELEASE_ID " ]; then
2144 echo " Already at the latest release. Skipping download."
2245 exit 0
@@ -28,6 +51,13 @@ TEMP_DIR=$(mktemp -d)
2851cd $TEMP_DIR
2952
3053DOWNLOAD_URL=$( echo " $LATEST_RELEASE " | jq -r ' .assets[0].url' )
54+ if [ " $DOWNLOAD_URL " == " null" ] || [ -z " $DOWNLOAD_URL " ]; then
55+ echo " No download URL found in release data. Skipping tools update."
56+ cd - > /dev/null
57+ rm -rf $TEMP_DIR
58+ exit 0
59+ fi
60+
3161curl -L -o dist.zip -H " Authorization: token $TEMPLATE_PAT " -H " Accept: application/octet-stream" " $DOWNLOAD_URL "
3262
3363unzip -o dist.zip
0 commit comments