From 7d22d25adf36995663dbba49f22bb1905e9bc810 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 28 Feb 2020 13:34:20 +0100 Subject: [PATCH] fetch-upstream-resources: simplify parsing of _config.yml This part of the script was setting variables for any "_version" property in the configuration file. We (currently) only need the engine API version, so simplifying the code to just do that, and fix some spaces -> tabs indentations. With this change the script only uses standard (POSIX) scripting, so switching to use the standard (/bin/sh) shell. Signed-off-by: Sebastiaan van Stijn --- Dockerfile | 2 +- _scripts/fetch-upstream-resources.sh | 26 ++++++++------------------ 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6adb8ba4f0..8f8229ec1c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -74,7 +74,7 @@ COPY ./_scripts/fetch-upstream-resources.sh ./_scripts/ # TODO find a different mechanism for substituting the API version, to prevent invalidating the cache COPY ./_config.yml . COPY ./_data/toc.yaml ./_data/ -RUN bash ./_scripts/fetch-upstream-resources.sh . +RUN ./_scripts/fetch-upstream-resources.sh . # Build the static HTML for the current docs. diff --git a/_scripts/fetch-upstream-resources.sh b/_scripts/fetch-upstream-resources.sh index c4029fa7fc..a76f6e69a0 100755 --- a/_scripts/fetch-upstream-resources.sh +++ b/_scripts/fetch-upstream-resources.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Fetches upstream resources from docker/docker and docker/distribution # before handing off the site to Jekyll to build @@ -10,29 +10,19 @@ # Helper function to deal with sed differences between osx and Linux # See https://stackoverflow.com/a/38595160 sedi () { - sed --version >/dev/null 2>&1 && sed -i -- "$@" || sed -i "" "$@" + sed --version >/dev/null 2>&1 && sed -i -- "$@" || sed -i "" "$@" } # Do some sanity-checking to make sure we are running this from the right place if ! [ -f _config.yml ]; then - echo "Could not find _config.yml. We may not be in the right place. Bailing." - exit 1 + echo "Could not find _config.yml. We may not be in the right place. Bailing." + exit 1 fi -# Parse some variables from _config.yml and make them available to this script -# This only finds top-level variables with _version in them that don't have any -# leading space. This is brittle! - -while read i; do - # Store the key as a variable name and the value as the variable value - varname=$(echo "$i" | sed 's/"//g' | awk -F ':' {'print $1'} | tr -d '[:space:]') - varvalue=$(echo "$i" | sed 's/"//g' | awk -F ':' {'print $2'} | tr -d '[:space:]') - echo "Setting \$${varname} to $varvalue" - declare "$varname=$varvalue" -done < <(cat ./_config.yml |grep '_version:' |grep '^[a-z].*') - -# Replace variable in toc.yml with value from above -sedi "s/{{ site.latest_engine_api_version }}/$latest_engine_api_version/g" ./_data/toc.yaml +# Parse latest_engine_api_version variables from _config.yml to replace the value +# in toc.yaml. This is brittle! +latest_engine_api_version="$(grep 'latest_engine_api_version:' ./_config.yml | grep -oh '"[0-9].*"$' | sed 's/"//g')" +sedi "s/{{ site.latest_engine_api_version }}/${latest_engine_api_version}/g" ./_data/toc.yaml # Translate branches for use by svn engine_svn_branch="branches/${ENGINE_BRANCH}"