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
This commit is contained in:
Jean-Philippe Evrard
2021-03-03 09:13:08 +01:00
parent 4511c54fad
commit 636248ad67

View File

@@ -123,7 +123,17 @@ then
done done
elif [[ -n "$GITHUB_SHA" ]] elif [[ -n "$GITHUB_SHA" ]]
then 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" ]] [[ -n "$commits" ]]
for commit in $commits for commit in $commits