From 93abf699b878c6a088ce33d96ce94bc3a3d1f690 Mon Sep 17 00:00:00 2001 From: Amir Zarrinkafsh Date: Sun, 22 Mar 2020 00:42:29 +1100 Subject: [PATCH] [Buildkite] Fix docs bypass for origin/master divergences (#764) If origin/master diverges beyond the initial fork-point on branches or external forks, the `git merge-base` command exits unsuccessfully. This will cause commits to incorrectly be recognised as a docs bypass. This change will catch the unsuccessful exit and treat it as a normal CI/CD run. Examples: - https://buildkite.com/authelia/authelia/builds/932 - https://buildkite.com/authelia/authelia/builds/933 - https://buildkite.com/authelia/authelia/builds/941 --- .buildkite/deployment.sh | 14 ++++++++++---- .buildkite/pipeline.sh | 22 ++++++++++++++-------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/.buildkite/deployment.sh b/.buildkite/deployment.sh index c16e8a562..15eb1e8ee 100755 --- a/.buildkite/deployment.sh +++ b/.buildkite/deployment.sh @@ -1,11 +1,17 @@ #!/bin/bash set -u -if [[ $BUILDKITE_TAG == "" ]]; then - if [[ $BUILDKITE_BRANCH == "master" ]]; then - CI_DOCS_BYPASS=$(git diff --name-only HEAD~1 | sed -rn '/^docs\/.*/!{q1}' && echo true || echo false) +DIVERGED=$(git merge-base --fork-point origin/master > /dev/null; echo $?) + +if [[ $DIVERGED -eq 0 ]]; then + if [[ $BUILDKITE_TAG == "" ]]; then + if [[ $BUILDKITE_BRANCH == "master" ]]; then + CI_DOCS_BYPASS=$(git diff --name-only HEAD~1 | sed -rn '/^docs\/.*/!{q1}' && echo true || echo false) + else + CI_DOCS_BYPASS=$(git diff --name-only `git merge-base --fork-point origin/master` | sed -rn '/^docs\/.*/!{q1}' && echo true || echo false) + fi else - CI_DOCS_BYPASS=$(git diff --name-only `git merge-base --fork-point origin/master` | sed -rn '/^docs\/.*/!{q1}' && echo true || echo false) + CI_DOCS_BYPASS="false" fi else CI_DOCS_BYPASS="false" diff --git a/.buildkite/pipeline.sh b/.buildkite/pipeline.sh index 8eee27cfe..aaa74767e 100755 --- a/.buildkite/pipeline.sh +++ b/.buildkite/pipeline.sh @@ -1,15 +1,21 @@ #!/bin/bash set -u -if [[ $BUILDKITE_TAG == "" ]]; then - if [[ $BUILDKITE_BRANCH == "master" ]]; then - CI_DOCS_BYPASS=$(git diff --name-only HEAD~1 | sed -rn '/^docs\/.*/!{q1}' && echo true || echo false) - else - CI_DOCS_BYPASS=$(git diff --name-only `git merge-base --fork-point origin/master` | sed -rn '/^docs\/.*/!{q1}' && echo true || echo false) - fi +DIVERGED=$(git merge-base --fork-point origin/master > /dev/null; echo $?) - if [[ $CI_DOCS_BYPASS == "true" ]]; then - cat .buildkite/annotations/documentation | buildkite-agent annotate --style "info" --context "ctx-info" +if [[ $DIVERGED -eq 0 ]]; then + if [[ $BUILDKITE_TAG == "" ]]; then + if [[ $BUILDKITE_BRANCH == "master" ]]; then + CI_DOCS_BYPASS=$(git diff --name-only HEAD~1 | sed -rn '/^docs\/.*/!{q1}' && echo true || echo false) + else + CI_DOCS_BYPASS=$(git diff --name-only `git merge-base --fork-point origin/master` | sed -rn '/^docs\/.*/!{q1}' && echo true || echo false) + fi + + if [[ $CI_DOCS_BYPASS == "true" ]]; then + cat .buildkite/annotations/documentation | buildkite-agent annotate --style "info" --context "ctx-info" + fi + else + CI_DOCS_BYPASS="false" fi else CI_DOCS_BYPASS="false"