MozillaFirefox/create-tar.sh
branchfirefox71
changeset 1117 d6a688186de0
parent 1114 572ec48f3fe8
child 1119 4c5d44d40a03
--- a/MozillaFirefox/create-tar.sh	Mon Nov 25 08:41:45 2019 +0100
+++ b/MozillaFirefox/create-tar.sh	Wed Dec 18 02:16:48 2019 +0100
@@ -42,6 +42,7 @@
 # Make first letter of PRODCUT upper case
 PRODUCT_CAP="${PRODUCT^}"
 LOCALES_URL="https://product-details.mozilla.org/1.0/l10n/$PRODUCT_CAP"
+PRODUCT_URL="https://product-details.mozilla.org/1.0/$PRODUCT.json"
 # Exit script on CTRL+C
 trap "exit" INT
 
@@ -83,7 +84,7 @@
 function get_source_stamp() {
   BUILD_ID="$1"
   FTP_CANDIDATES_BASE_URL=$(get_ftp_candidates_url $VERSION$VERSION_SUFFIX)
-  FTP_CANDIDATES_JSON_SUFFIX="${BUILD_ID}/linux-x86_64/en-US/firefox-$VERSION$VERSION_SUFFIX.json"
+  FTP_CANDIDATES_JSON_SUFFIX="${BUILD_ID}/linux-x86_64/en-US/$PRODUCT-$VERSION$VERSION_SUFFIX.json"
   BUILD_JSON=$(curl --silent --fail "$FTP_CANDIDATES_BASE_URL/$FTP_CANDIDATES_JSON_SUFFIX") || return 1;
   REV=$(echo "$BUILD_JSON" | jq .moz_source_stamp)
   SOURCE_REPO=$(echo "$BUILD_JSON" | jq .moz_source_repo)
@@ -104,12 +105,21 @@
 function get_build_number() {
   LAST_FOUND=""
   VERSION_WITH_SUFFIX="$1"
-  FTP_CANDIDATES_BASE_URL=$(get_ftp_candidates_url $VERSION_WITH_SUFFIX)
-  # Unfortunately, locales-files are not associated to releases, but to builds.
-  # And since we don't know which build was the final build, we grep them all from
-  # the candidates-page, sort them and take the last one which should be the oldest
-  # Error only if not even the first one exists
-  LAST_FOUND=$(curl --silent --fail "$FTP_CANDIDATES_BASE_URL/" | grep -o "build[0-9]*/" | sort | uniq | tail -n 1 | cut -d "/" -f 1)
+
+  BUILD_ID=$(curl --silent "$PRODUCT_URL" | jq -e '.["releases"] | .["'$PRODUCT-$VERSION_WITH_SUFFIX'"] | .["build_number"]')
+
+  # Slow fall-back
+  if [ $? -ne 0 ]; then
+      echo "Build number not found in product URL, falling back to slow FTP-parsing." 1>&2
+      FTP_CANDIDATES_BASE_URL=$(get_ftp_candidates_url $VERSION_WITH_SUFFIX)
+      # Unfortunately, locales-files are not associated to releases, but to builds.
+      # And since we don't know which build was the final build, we grep them all from
+      # the candidates-page, sort them and take the last one which should be the oldest
+      # Error only if not even the first one exists
+      LAST_FOUND=$(curl --silent --fail "$FTP_CANDIDATES_BASE_URL/" | grep -o "build[0-9]*/" | sort | uniq | tail -n 1 | cut -d "/" -f 1)
+  else
+      LAST_FOUND="build$BUILD_ID"
+  fi
 
   if [ "$LAST_FOUND" != "" ]; then
     echo "$LAST_FOUND"
@@ -250,10 +260,9 @@
   hg update --check $FF_RELEASE_TAG
   [ "$FF_RELEASE_TAG" == "default" ] || hg update -r $FF_RELEASE_TAG
   # get repo and source stamp
-  echo -n "REV=" > ../source-stamp.txt
-  hg -R . parent --template="{node|short}\n" >> ../source-stamp.txt
-  echo -n "REPO=" >> ../source-stamp.txt
-  hg showconfig paths.default 2>/dev/null | head -n1 | sed -e "s/^ssh:/http:/" >> ../source-stamp.txt
+  REV=$(hg -R . parent --template="{node|short}\n")
+  SOURCE_REPO=$(hg showconfig paths.default 2>/dev/null | head -n1 | sed -e "s/^ssh:/http:/")
+  TIMESTAMP=$(date +%Y%m%d%H%M%S)
 
   if [ "$PRODUCT" = "thunderbird" ]; then
     pushd comm || exit 1
@@ -263,6 +272,19 @@
   fi
   popd || exit 1
 
+  echo "Extending $TAR_STAMP with:"
+  echo "RELEASE_REPO=${SOURCE_REPO}"
+  echo "RELEASE_TAG=${REV}"
+  echo "RELEASE_TIMESTAMP=${TIMESTAMP}"
+
+  # We "remove and add" instead of "replace" in case the entries are not there yet
+  # Removing the old RELEASE_-tags
+  sed -i "/RELEASE_\(TAG\|REPO\|TIMESTAMP\)=.*/d" "$TAR_STAMP"
+  # Appending the new 
+  echo "RELEASE_REPO=$SOURCE_REPO" >> "$TAR_STAMP"
+  echo "RELEASE_TAG=$REV" >> "$TAR_STAMP"
+  echo "RELEASE_TIMESTAMP=$TIMESTAMP" >> "$TAR_STAMP"
+
   echo "creating archive..."
   tar $compression -cf $PRODUCT-$VERSION$VERSION_SUFFIX.source.tar.xz --exclude=.hgtags --exclude=.hgignore --exclude=.hg --exclude=CVS $PRODUCT-$VERSION
 fi