From 2489fe215e7f4f7b17b6711b37c31dc2a1c642b4 Mon Sep 17 00:00:00 2001
From: "E. G. Patrick Bos" <egpbos@gmail.com>
Date: Thu, 24 Jun 2021 14:06:13 +0200
Subject: [PATCH] pass BASE_COMMIT to format_script.sh

It is not possible to use the base branch name in the GitHub Actions workflow to get the base SHA hash, because the branch name is not known there. To keep the format_script.sh universal, we just pass the SHA hash in from both the Travis and the GH Actions configurations instead.
---
 .ci/format_script.sh                | 1 -
 .github/workflows/code_analysis.yml | 2 +-
 .travis.yml                         | 6 +++++-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/.ci/format_script.sh b/.ci/format_script.sh
index 6bb51fa5129..67503dd8710 100755
--- a/.ci/format_script.sh
+++ b/.ci/format_script.sh
@@ -2,7 +2,6 @@
 
 set -ex
 
-BASE_COMMIT=$(git rev-parse $TRAVIS_BRANCH)
 echo "Running clang-format against branch $TRAVIS_BRANCH, with hash $BASE_COMMIT"
 COMMIT_FILES=$(git diff --name-only $BASE_COMMIT | grep -i -v LinkDef)
 RESULT_OUTPUT="$(git-clang-format --commit $BASE_COMMIT --diff --binary `which clang-format` $COMMIT_FILES)"
diff --git a/.github/workflows/code_analysis.yml b/.github/workflows/code_analysis.yml
index 03a4907b261..4b36e6597d9 100644
--- a/.github/workflows/code_analysis.yml
+++ b/.github/workflows/code_analysis.yml
@@ -12,7 +12,7 @@ jobs:
     env:
       TRAVIS_BRANCH: ${{ github.base_ref }} 
       TRAVIS_PULL_REQUEST_BRANCH: ${{ github.head_ref }}
-      # BASE_COMMIT: ${{ github.event.pull_request.base.sha }}
+      BASE_COMMIT: ${{ github.event.pull_request.base.sha }}
     steps:
     - uses: actions/checkout@v2
     - name: Fetch base_ref HEAD
diff --git a/.travis.yml b/.travis.yml
index 8041119e0be..180f5304dae 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -23,7 +23,11 @@ matrix:
   include:
     - env: TOOL=clang-format
       script: &format_script
-        - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then .ci/format_script.sh; fi
+        - |
+          if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
+            export BASE_COMMIT=$(git rev-parse $TRAVIS_BRANCH)
+            .ci/format_script.sh
+          fi
 
     - env: TOOL=clang-tidy-analyzer
       before_script: &copy_headers
-- 
GitLab