From 3da0f839b424c7747a160fece4e0bc63fe87b861 Mon Sep 17 00:00:00 2001 From: rderbier Date: Fri, 27 Jan 2023 14:32:33 -0800 Subject: [PATCH 1/7] change build script for branches --- netlify.toml | 12 ++++++++++-- scripts/branchdeploy.sh | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 scripts/branchdeploy.sh diff --git a/netlify.toml b/netlify.toml index 4b9bb164..5b17e189 100644 --- a/netlify.toml +++ b/netlify.toml @@ -15,8 +15,16 @@ HUGO_VERSION = "0.79.0" LOOP = "false" HOST = "/" - +[context.branch-deploy] + command = "./scripts/branchdeploy.sh $DEPLOY_PRIME_URL" [context.branch-deploy.environment] HUGO_VERSION = "0.79.0" LOOP = "false" - HOST = "/" \ No newline at end of file + HOST = "/" +[[plugins]] + package = "@algolia/netlify-plugin-crawler" + [plugins.inputs] + branches = ['main','release/*'] + disabled = false + renderJavaScript = false + template = "hierarchical" diff --git a/scripts/branchdeploy.sh b/scripts/branchdeploy.sh new file mode 100644 index 00000000..f200cec7 --- /dev/null +++ b/scripts/branchdeploy.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +set -e + +GREEN='\033[32;1m' +RESET='\033[0m' + +# script used to build a release branch +# expect the branch to be named release/ +# argument is the netlify base url + +releaseVersion=$(git rev-parse --abbrev-ref HEAD | sed 's/release\///') + + +run() { + export DGRAPH_ENDPOINT=${DGRAPH_ENDPOINT:-"https://play.dgraph.io/query?latency=true"} + export HUGO_TITLE="Dgraph Doc - Preview" \ + + pushd "$(dirname "$0")/.." > /dev/null + pushd themes > /dev/null + + if [ ! -d "hugo-docs" ]; then + echo -e "$(date) $GREEN Hugo-docs repository not found. Cloning the repo. $RESET" + git clone https://github.com/dgraph-io/hugo-docs.git + else + echo -e "$(date) $GREEN Hugo-docs repository found. Pulling the latest version from master. $RESET" + pushd hugo-docs > /dev/null + git checkout master + git pull + popd > /dev/null + fi + popd > /dev/null + + echo -e "$(date) $GREEN Generating documentation static pages in the public folder. $RESET" + hugo --destination="public/docs/$releaseVersion" --baseURL="$1/docs/$releaseVersion" 1> /dev/null + cp "public/docs/$releaseVersion/sitemap.xml" public > /dev/null + echo -e "$(date) $GREEN Done building. $RESET" + + popd > /dev/null +} + +run "$1" From 32f22cee0929f329b739bf3d475e0ebb3225a313 Mon Sep 17 00:00:00 2001 From: rderbier Date: Fri, 27 Jan 2023 14:42:53 -0800 Subject: [PATCH 2/7] add clean builds --- scripts/branchdeploy.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/branchdeploy.sh b/scripts/branchdeploy.sh index f200cec7..62bc3b6e 100644 --- a/scripts/branchdeploy.sh +++ b/scripts/branchdeploy.sh @@ -1,6 +1,11 @@ #!/bin/bash set -e +# Important for clean builds on Netlify +if ! git remote | grep -q origin ; then + git remote add origin https://github.com/dgraph-io/dgraph-docs.git + git fetch --all +fi GREEN='\033[32;1m' RESET='\033[0m' From 42920e852bcc248bdc613a3843daea691f708b20 Mon Sep 17 00:00:00 2001 From: rderbier Date: Fri, 27 Jan 2023 16:20:51 -0800 Subject: [PATCH 3/7] minor change to trigger a netlify deploy --- scripts/branchdeploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/branchdeploy.sh b/scripts/branchdeploy.sh index 62bc3b6e..09f5e841 100644 --- a/scripts/branchdeploy.sh +++ b/scripts/branchdeploy.sh @@ -15,7 +15,7 @@ RESET='\033[0m' # argument is the netlify base url releaseVersion=$(git rev-parse --abbrev-ref HEAD | sed 's/release\///') - +echo "branchdeploy => '$releaseVersion'" run() { export DGRAPH_ENDPOINT=${DGRAPH_ENDPOINT:-"https://play.dgraph.io/query?latency=true"} From 6a25ef3441ef6976318f35590d37520d11522a5a Mon Sep 17 00:00:00 2001 From: rderbier Date: Mon, 30 Jan 2023 08:43:08 -0800 Subject: [PATCH 4/7] update execute authorization --- scripts/branchdeploy.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/branchdeploy.sh diff --git a/scripts/branchdeploy.sh b/scripts/branchdeploy.sh old mode 100644 new mode 100755 From af53a2f24559aaf42e915c61b38d092eac0a3f5f Mon Sep 17 00:00:00 2001 From: rderbier Date: Mon, 30 Jan 2023 08:58:20 -0800 Subject: [PATCH 5/7] Update branchdeploy.sh --- scripts/branchdeploy.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/branchdeploy.sh b/scripts/branchdeploy.sh index f2304c43..3e75d405 100755 --- a/scripts/branchdeploy.sh +++ b/scripts/branchdeploy.sh @@ -14,14 +14,14 @@ RESET='\033[0m' # expect the branch to be named release/ # argument is the netlify base url -releaseVersion=$(git rev-parse --abbrev-ref HEAD | sed 's/release\///') +releaseVersion=$(git rev-parse --abbrev-ref HEAD | sed 's/.*\///') echo "branchdeploy => '$releaseVersion'" run() { export DGRAPH_ENDPOINT=${DGRAPH_ENDPOINT:-"https://play.dgraph.io/query?latency=true"} - export HUGO_TITLE="Dgraph Doc - Preview" \ + export HUGO_TITLE="Dgraph Doc - ${releaseVersion}" pushd "$(dirname "$0")/.." > /dev/null pushd themes > /dev/null @@ -39,6 +39,8 @@ run() { popd > /dev/null echo -e "$(date) $GREEN Generating documentation static pages in the public folder. $RESET" + + CURRENT_VERSION=${releaseVersion} \ hugo --destination="public/docs/$releaseVersion" --baseURL="$1/docs/$releaseVersion" 1> /dev/null cp "public/docs/$releaseVersion/sitemap.xml" public > /dev/null echo -e "$(date) $GREEN Done building. $RESET" From 0bfff0416bedfc273b579b3a47f2cd0f401a3526 Mon Sep 17 00:00:00 2001 From: rderbier Date: Mon, 30 Jan 2023 17:53:49 -0800 Subject: [PATCH 6/7] test branch name --- scripts/local.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/local.sh b/scripts/local.sh index 981f7e73..eb6e3b03 100755 --- a/scripts/local.sh +++ b/scripts/local.sh @@ -5,6 +5,8 @@ set -e GREEN='\033[32;1m' RESET='\033[0m' +branch=$(git rev-parse --abbrev-ref HEAD) +echo "branch => '$branch'" VERSIONS_ARRAY=( 'preview' ) @@ -54,4 +56,3 @@ run() { } run "$1" "$2" - From b6c8ac25e5a076f756b5e39b8a8f4eee3f592e58 Mon Sep 17 00:00:00 2001 From: rderbier Date: Tue, 31 Jan 2023 13:37:01 -0800 Subject: [PATCH 7/7] use $HEAD to get the version in the branch name --- netlify.toml | 2 +- scripts/branchdeploy.sh | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/netlify.toml b/netlify.toml index 5b17e189..3269b86e 100644 --- a/netlify.toml +++ b/netlify.toml @@ -16,7 +16,7 @@ LOOP = "false" HOST = "/" [context.branch-deploy] - command = "./scripts/branchdeploy.sh $DEPLOY_PRIME_URL" + command = "./scripts/branchdeploy.sh $DEPLOY_PRIME_URL $HEAD" [context.branch-deploy.environment] HUGO_VERSION = "0.79.0" LOOP = "false" diff --git a/scripts/branchdeploy.sh b/scripts/branchdeploy.sh index 3e75d405..bfc89f0d 100755 --- a/scripts/branchdeploy.sh +++ b/scripts/branchdeploy.sh @@ -12,12 +12,15 @@ RESET='\033[0m' # script used to build a release branch # expect the branch to be named release/ -# argument is the netlify base url +# argument $1 is the netlify base url +# argument $2 is the $HEAD netlify variable which is the branch name -releaseVersion=$(git rev-parse --abbrev-ref HEAD | sed 's/.*\///') +releaseVersion=$(echo $2 | sed 's/.*\///') echo "branchdeploy => '$releaseVersion'" - +VERSION_STRING="$releaseVersion" +# In Unix environments, env variables should also be exported to be seen by Hugo +export VERSIONS=${VERSION_STRING} run() { export DGRAPH_ENDPOINT=${DGRAPH_ENDPOINT:-"https://play.dgraph.io/query?latency=true"} @@ -38,9 +41,10 @@ run() { fi popd > /dev/null - echo -e "$(date) $GREEN Generating documentation static pages in the public folder. $RESET" + echo -e "$(date) $GREEN Generating documentation static pages in the folder public/docs/$releaseVersion. $RESET" CURRENT_VERSION=${releaseVersion} \ + VERSIONS=${VERSION_STRING} \ hugo --destination="public/docs/$releaseVersion" --baseURL="$1/docs/$releaseVersion" 1> /dev/null cp "public/docs/$releaseVersion/sitemap.xml" public > /dev/null echo -e "$(date) $GREEN Done building. $RESET"