From 636248ad67651849d7996314adfaf8812d18c306 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Wed, 3 Mar 2021 09:13:08 +0100 Subject: [PATCH] test: Ensure branches are also testable test-commit-message runs on PR, but also on push in other branches which aren't PRs. We need to test those too. This is fixed by ensuring the same kind of behaviour than travis CI: When a patch is put on a branch, it's using the branchname for testing [1]. [1]: https://docs-staging.travis-ci.com/user/environment-variables/#default-environment-variables --- test/test-commit-message.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/test-commit-message.sh b/test/test-commit-message.sh index 0e8c34b4c..d575e858a 100755 --- a/test/test-commit-message.sh +++ b/test/test-commit-message.sh @@ -123,7 +123,17 @@ then done elif [[ -n "$GITHUB_SHA" ]] then - commits=$(git log --no-merges --format=%H origin/${GITHUB_BASE_REF}..${GITHUB_SHA}) + # GITHUB_SHA is the HEAD of the branch + # GITHUB_REF: The branch or tag ref that triggered the workflow. For example, refs/heads/feature-branch-1. If neither a branch or tag is available for the event type, the variable will not exist. + # GITHUB_BASE_REF: Only set for pull request events. The name of the base branch. + if [[ -n "${GITHUB_BASE_REF}" ]]; then + ref=${GITHUB_BASE_REF} + head=${GITHUB_SHA} + else + ref=$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }') + head="" + fi + commits=$(git log --no-merges --format=%H origin/${ref}..${head}) [[ -n "$commits" ]] for commit in $commits