Skip to content

Commit

Permalink
internal/ci: update base early git checks from alpha.cuelang.org
Browse files Browse the repository at this point in the history
We established some improved checks during work on alpha.cuelang.org.

Signed-off-by: Paul Jolly <paul@myitcv.io>
Change-Id: I1f0178ccdbc4ef93f607b569b9753fe437a0fa80
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/551472
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
  • Loading branch information
myitcv committed Mar 23, 2023
1 parent c3138e3 commit 4509e7f
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 5 deletions.
43 changes: 40 additions & 3 deletions .github/workflows/trybot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,50 @@ jobs:
# recently. Increase it to 5 or 10 soon, to also cover CL chains.
for commit in $(git rev-list --max-count=1 HEAD); do
if ! git rev-list --format=%B --max-count=1 $commit | grep -q '^Signed-off-by:'; then
echo -e "
Recent commit is lacking Signed-off-by:
"
echo -e "\nRecent commit is lacking Signed-off-by:\n"
git show --quiet $commit
exit 1
fi
done
# Ensure that commit messages have a blank second line.
# We know that a commit message must be longer than a single
# line because each commit must be signed-off.
if git log --format=%B -n 1 HEAD | sed -n '2{/^$/{q1}}'; then
echo "second line of commit message must be blank"
exit 1
fi
# Ensure that the commit author is the same as the signed-off-by. This
# is a basic requirement of DCO. It is enforced by Gerrit (although
# noting that in Gerrit the author name does not have to match, only
# the email address), but _not_ by the DCO GitHub app:
#
# https://github.com/dcoapp/app/issues/201
#
# Provide a sanity check as part of GitHub workflows that should enforce
# this, e.g. trybot workflows.
#
# We do so by comparing the commit author and "Signed-off-by" trailer for
# strict equality. Whilst this is more strict than Gerrit, it should
# generally be the case, and we can always relax this when presented with
# specific situations where it is is a problem.
# commit author email address
commitauthor="$(git log -1 --pretty="%ae")"
# signed-off-by trailer email address. There is no way to parse just the
# email address from the trailer in the same way as git log, so instead
# grab the relevant trailer and then take the last whitespace-delimited
# part as the "<>" contained email address.
# Getting the Signed-off-by trailer in this way causes blank
# lines for some reason. Use awk to remove them.
commitsigner="$(git log -1 --pretty='%(trailers:key=Signed-off-by,valueonly)' | sed -ne 's/.* <\(.*\)>/\1/p')"
if [[ "$commitauthor" != "$commitsigner" ]]; then
echo "commit author email address does not match signed-off-by trailer"
exit 1
fi
- if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) || (matrix.go-version == '1.19.x' && matrix.os == 'ubuntu-22.04')
run: echo CUE_LONG=true >> $GITHUB_ENV
- if: (matrix.go-version == '1.19.x' && matrix.os == 'ubuntu-22.04')
Expand Down
43 changes: 41 additions & 2 deletions internal/ci/base/base.cue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ import (

#earlyChecks: json.#step & {
name: "Early git and code sanity checks"
run: """
run: #"""
# Ensure the recent commit messages have Signed-off-by headers.
# TODO: Remove once this is enforced for admins too;
# see https://bugs.chromium.org/p/gerrit/issues/detail?id=15229
Expand All @@ -97,7 +97,46 @@ import (
exit 1
fi
done
"""
# Ensure that commit messages have a blank second line.
# We know that a commit message must be longer than a single
# line because each commit must be signed-off.
if git log --format=%B -n 1 HEAD | sed -n '2{/^$/{q1}}'; then
echo "second line of commit message must be blank"
exit 1
fi
# Ensure that the commit author is the same as the signed-off-by. This
# is a basic requirement of DCO. It is enforced by Gerrit (although
# noting that in Gerrit the author name does not have to match, only
# the email address), but _not_ by the DCO GitHub app:
#
# https://github.com/dcoapp/app/issues/201
#
# Provide a sanity check as part of GitHub workflows that should enforce
# this, e.g. trybot workflows.
#
# We do so by comparing the commit author and "Signed-off-by" trailer for
# strict equality. Whilst this is more strict than Gerrit, it should
# generally be the case, and we can always relax this when presented with
# specific situations where it is is a problem.
# commit author email address
commitauthor="$(git log -1 --pretty="%ae")"
# signed-off-by trailer email address. There is no way to parse just the
# email address from the trailer in the same way as git log, so instead
# grab the relevant trailer and then take the last whitespace-delimited
# part as the "<>" contained email address.
# Getting the Signed-off-by trailer in this way causes blank
# lines for some reason. Use awk to remove them.
commitsigner="$(git log -1 --pretty='%(trailers:key=Signed-off-by,valueonly)' | sed -ne 's/.* <\(.*\)>/\1/p')"
if [[ "$commitauthor" != "$commitsigner" ]]; then
echo "commit author email address does not match signed-off-by trailer"
exit 1
fi
"""#
}

#checkGitClean: json.#step & {
Expand Down

0 comments on commit 4509e7f

Please sign in to comment.