forked from flyteorg/flyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added dco signoff preecommit (flyteorg#89)
* Added dco signoff preecommit Signed-off-by: Yuvraj <[email protected]>
- Loading branch information
1 parent
0f29f0b
commit 5358f23
Showing
13 changed files
with
172 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# WARNING: THIS FILE IS MANAGED IN THE 'BOILERPLATE' REPO AND COPIED TO OTHER REPOSITORIES. | ||
# ONLY EDIT THIS FILE FROM WITHIN THE 'FLYTEORG/BOILERPLATE' REPOSITORY: | ||
# | ||
# TO OPT OUT OF UPDATES, SEE https://github.com/flyteorg/boilerplate/blob/master/Readme.rst | ||
|
||
|
||
.PHONY: setup-precommit | ||
setup-precommit: #setup the precommit | ||
@boilerplate/flyte/precommit/update.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
DUMMY_SHA=0000000000000000000000000000000000000000 | ||
|
||
echo "Running pre-push check; to skip this step use 'push --no-verify'" | ||
|
||
while read LOCAL_REF LOCAL_SHA REMOTE_REF REMOTE_SHA | ||
do | ||
if [ "$LOCAL_SHA" = $DUMMY_SHA ] | ||
then | ||
# Branch deleted. Do nothing. | ||
exit 0 | ||
else | ||
if [ "$REMOTE_SHA" = $DUMMY_SHA ] | ||
then | ||
# New branch. Verify the last commit, since this is very likely where the new code is | ||
# (though there is no way to know for sure). In the extremely uncommon case in which someone | ||
# pushes more than 1 new commit to a branch, CI will enforce full checking. | ||
RANGE="$LOCAL_SHA~1..$LOCAL_SHA" | ||
else | ||
# Updating branch. Verify new commits. | ||
RANGE="$REMOTE_SHA..$LOCAL_SHA" | ||
fi | ||
|
||
# Verify DCO signoff. We do this before the format checker, since it has | ||
# some probability of failing spuriously, while this check never should. | ||
# | ||
# In general, we can't assume that the commits are signed off by author | ||
# pushing, so we settle for just checking that there is a signoff at all. | ||
SIGNED_OFF=$(git rev-list --no-merges --grep "^Signed-off-by: " "$RANGE") | ||
NOT_SIGNED_OFF=$(git rev-list --no-merges "$RANGE" | grep -Fxv "$SIGNED_OFF") | ||
if [ -n "$NOT_SIGNED_OFF" ] | ||
then | ||
echo >&2 "ERROR: The following commits do not have DCO signoff:" | ||
while read -r commit; do | ||
echo " $(git log --pretty=oneline --abbrev-commit -n 1 $commit)" | ||
done <<< "$NOT_SIGNED_OFF" | ||
exit 1 | ||
fi | ||
fi | ||
done | ||
|
||
exit 0 |
16 changes: 16 additions & 0 deletions
16
flytectl/boilerplate/flyte/precommit/hooks/prepare-commit-msg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# WARNING: THIS FILE IS MANAGED IN THE 'BOILERPLATE' REPO AND COPIED TO OTHER REPOSITORIES. | ||
# ONLY EDIT THIS FILE FROM WITHIN THE 'FLYTEORG/BOILERPLATE' REPOSITORY: | ||
# | ||
# TO OPT OUT OF UPDATES, SEE https://github.com/flyteorg/boilerplate/blob/master/Readme.rst | ||
# $ ln -s ../../support/hooks/prepare-commit-msg .git/hooks/prepare-commit-msg | ||
|
||
COMMIT_MESSAGE_FILE="$1" | ||
AUTHOR=$(git var GIT_AUTHOR_IDENT) | ||
SIGNOFF=$(echo $AUTHOR | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') | ||
|
||
# Check for DCO signoff message. If one doesn't exist, append one and then warn | ||
# the user that you did so. | ||
if ! $(grep -qs "^$SIGNOFF" "$COMMIT_MESSAGE_FILE") ; then | ||
echo "\n$SIGNOFF" >> "$COMMIT_MESSAGE_FILE" | ||
echo "Appended the following signoff to the end of the commit message:\n $SIGNOFF\n" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env bash | ||
|
||
# WARNING: THIS FILE IS MANAGED IN THE 'BOILERPLATE' REPO AND COPIED TO OTHER REPOSITORIES. | ||
# ONLY EDIT THIS FILE FROM WITHIN THE 'FLYTEORG/BOILERPLATE' REPOSITORY: | ||
# | ||
# TO OPT OUT OF UPDATES, SEE https://github.com/flyteorg/boilerplate/blob/master/Readme.rst | ||
|
||
set -e | ||
|
||
# Helper script for Automatically add DCO signoff with commit hooks | ||
# Taken from Envoy https://gitlab.cncf.ci/envoyproxy/envoy | ||
if [ ! "$PWD" == "$(git rev-parse --show-toplevel)" ]; then | ||
cat >&2 <<__EOF__ | ||
ERROR: this script must be run at the root of the envoy source tree | ||
__EOF__ | ||
exit 1 | ||
fi | ||
|
||
# Helper functions that calculate `abspath` and `relpath`. Taken from Mesos | ||
# commit 82b040a60561cf94dec3197ea88ae15e57bcaa97, which also carries the Apache | ||
# V2 license, and has deployed this code successfully for some time. | ||
abspath() { | ||
cd "$(dirname "${1}")" | ||
echo "${PWD}"/"$(basename "${1}")" | ||
cd "${OLDPWD}" | ||
} | ||
relpath() { | ||
local FROM TO UP | ||
FROM="$(abspath "${1%/}")" TO="$(abspath "${2%/}"/)" | ||
while test "${TO}" = "${TO#"${FROM}"/}" \ | ||
-a "${TO}" != "${FROM}"; do | ||
FROM="${FROM%/*}" UP="../${UP}" | ||
done | ||
TO="${UP%/}${TO#${FROM}}" | ||
echo "${TO:-.}" | ||
} | ||
|
||
# Try to find the `.git` directory, even if it's not in Flyte project root (as | ||
# it wouldn't be if, say, this were in a submodule). The "blessed" but fairly | ||
# new way to do this is to use `--git-common-dir`. | ||
DOT_GIT_DIR=$(git rev-parse --git-common-dir) | ||
if test ! -d "${DOT_GIT_DIR}"; then | ||
# If `--git-common-dir` is not available, fall back to older way of doing it. | ||
DOT_GIT_DIR=$(git rev-parse --git-dir) | ||
fi | ||
|
||
mkdir -p ${DOT_GIT_DIR}/hooks | ||
|
||
HOOKS_DIR="${DOT_GIT_DIR}/hooks" | ||
HOOKS_DIR_RELPATH=$(relpath "${HOOKS_DIR}" "${PWD}") | ||
|
||
if [ ! -e "${HOOKS_DIR}/prepare-commit-msg" ]; then | ||
echo "Installing hook 'prepare-commit-msg'" | ||
ln -s "${HOOKS_DIR_RELPATH}/boilerplate/flyte/precommit/hooks/prepare-commit-msg" "${HOOKS_DIR}/prepare-commit-msg" | ||
fi | ||
|
||
if [ ! -e "${HOOKS_DIR}/pre-push" ]; then | ||
echo "Installing hook 'pre-push'" | ||
ln -s "${HOOKS_DIR_RELPATH}/boilerplate/flyte/precommit/hooks/pre-push" "${HOOKS_DIR}/pre-push" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.