Browse Source

build.sh: rework site checkout

Karsten Böddeker 6 years ago
parent
commit
58dfe27099
3 changed files with 15 additions and 22 deletions
  1. 1 1
      ReadMe.md
  2. 1 1
      build-version.sh
  3. 13 20
      build.sh

+ 1 - 1
ReadMe.md

@@ -45,7 +45,7 @@ optional:
 * **MAKEJOBS** spezifiziert die Anzahl der parallel laufenden Compiler-Prozesse (default: ein Prozess pro CPU/Kern)
 * **PRIORITY** spezifiziert die maximale Anzahl an Tagen, die ein Knoten das Einspielen des Updates verzögern darf (default: $(DEFAULT_GLUON_PRIORITY))
 * **PUBLISH** falls "1", veröffentliche die Firmware nach dem bauen
-* **SITE_ID** gibt die Commit-ID des Site-Repos an (default: HEAD)
+* **SITE** gibt die Site-Version an, die für den Build genutzt werden soll (default: identisch zu **BRANCH**)
 * **TARGETS** ein Liste durch Leerzeichen separierter Hardware-Zielplattformen (default: alle bekannten Plattformen)
 * **VERBOSE** falls "1", schaltet Debug-Ausgaben mit an - dies ist nur notwendig wenn Fehler beim Build auftreten (default: "0")
 * **VERSIONS_DIR** gibt das Verzeichnis für die Versions-Dateien an (default: ./versions)

+ 1 - 1
build-version.sh

@@ -43,6 +43,6 @@ echo " * Targets    = ${targets}"
 echo
 
 # invoke build script
-BASE="${base}" BRANCH="${branch}" SITE_ID="${site}" VERSION="${version}" BUILD_TS="${ts}" TARGETS="${targets}" BROKEN="${BROKEN}" ./build.sh
+BASE="${base}" BRANCH="${branch}" SITE="${site}" VERSION="${version}" BUILD_TS="${ts}" TARGETS="${targets}" BROKEN="${BROKEN}" ./build.sh
 
 popd > /dev/null #${MY_DIR}

+ 13 - 20
build.sh

@@ -18,7 +18,7 @@
 # MAKEJOBS    = number of compiler processes running in parallel (default: number of CPUs/Cores)
 # PRIORITY    = determines the number of day a rollout phase should last at most
 # PUBLISH     = 0 (default) or 1, publish firmware at the end
-# SITE_ID     = specific site repository commit-id (leave blank to use HEAD)
+# SITE        = site repository version (branch, tag or commit, default: '$BRANCH')
 # TARGETS     = a space separated list of target platforms (if unset, all platforms will be build)
 # VERBOSE     = 0 (default) or 1, call the make commands with 'V=s' to see actual errors better
 # VERSIONS_DIR = specify directory for version files
@@ -69,6 +69,7 @@ fi
 [ -n "${MAKEJOBS}" ] || MAKEJOBS=$(grep -c "^processor" /proc/cpuinfo)
 [ -n "${PRIORITY}" ] || PRIORITY=0
 [ -n "${PUBLISH}" ] || PUBLISH=0
+[ -n "${SITE}" ] || SITE=${BRANCH}
 [ -n "${VERBOSE}" ] || VERBOSE=0
 
 if [ -n "${VERSIONS_DIR}" ]; then
@@ -131,24 +132,16 @@ popd > /dev/null #${CODE_DIR}
 ### CHECKOUT SITE REPO
 progress "Checking out SITE REPO ..."
 pushd ${SITE_DIR} > /dev/null
-if [ $(git remote | wc -l) -ge "1" ]; then
-	git fetch
-	# TODO: check if site got modified locally and bail out if necessary
-	if [ -z "${SITE_ID}" ]; then
-		# no specific site given - get the most current one
-		git checkout -q ${BRANCH}
-		git branch -r | grep ${BRANCH} > /dev/null
-		if [ "$?" -eq "0" ]; then
-			git rebase
-			[ "$?" -eq "0" ] || abort "Failed to get newest '${BRANCH}' in site repository, mimimi."
-		fi
-	else
-		# fetch site repo updates
-		git fetch || true
-		# commit given - use this one
-		git checkout -q ${SITE_ID}
-		[ "$?" -eq "0" ] || abort "Failed to checkout requested site commit '${SITE_ID}', mimimi."
-	fi
+# check if site repo got modified and bail out if necessary
+[ "$(git status --porcelain)" ] && abort "Local changes to site directory. Cowardly refusing to update repository." >&2
+git fetch
+git show-ref --verify --quiet refs/remotes/origin/${SITE}
+if [ "$?" -eq "0" ]; then
+	git checkout -B build origin/${SITE}
+	[ "$?" -eq "0" ] || abort "Failed to checkout site repo 'origin/${SITE}'."
+else
+	git checkout -q ${SITE}
+	[ "$?" -eq "0" ] || abort "Failed to checkout site repo '${SITE}'." >&2
 fi
 SITE_COMMIT=$(git rev-list --max-count=1 HEAD)
 popd > /dev/null #${SITE_DIR}
@@ -187,7 +180,7 @@ touch $(dirname ${build_info_path})
 echo "VERSION=${VERSION}" >> ${build_info_path}
 echo "GLUON=${GLUON_COMMIT} # ${BASE}" >> ${build_info_path}
 echo "BRANCH=${BRANCH}" >> ${build_info_path}
-echo "SITE=${SITE_COMMIT} # ${VERSION}" >> ${build_info_path}
+echo "SITE=${SITE_COMMIT} # ${SITE}" >> ${build_info_path}
 echo "TARGETS='${TARGETS}'" >> ${build_info_path}
 echo "TS=${BUILD_TS}" >> ${build_info_path}