Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CONTRIB: Add checking script before push #10203

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions buildlib/pr/codestyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,13 @@ jobs:

- bash: |
set -eE
source ./buildlib/tools/codestyle.sh

BASE_SOURCEVERSION=$(git rev-parse HEAD^)
range="$BASE_SOURCEVERSION..$(Build.SourceVersion)"
ok=1
for sha1 in `git log $range --format="%h"`
do
title=`git log -1 --format="%s" $sha1`
if echo $title | grep -qP '^Merge |^[0-9A-Z/_\-]*: \w'
then
echo "Good commit title: '$title'"
else
echo "Bad commit title: '$title'"
ok=0
fi
done
if [ $ok -ne 1 ]

codestyle_check_commit_title "$range"
if [[ $? -ne 0 ]]
then
url="https://github.com/openucx/ucx/wiki/Guidance-for-contributors#general-guidelines"
echo "##vso[task.logissue type=error]Bad commit title(s), see $url for more info."
Expand Down Expand Up @@ -85,8 +77,7 @@ jobs:
retryCountOnTaskFailure: 5

- bash: |
python3 -m venv /tmp/codespell_env
source /tmp/codespell_env/bin/activate
pip3 install codespell
codespell
set -eE
source ./buildlib/tools/codestyle.sh
codestyle_check_spell
displayName: codespell test
31 changes: 31 additions & 0 deletions buildlib/tools/codestyle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
#
# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# See file LICENSE for terms.
#

codestyle_check_commit_title() {
local range="$1"
local err=0

for sha1 in `git log "$range" --format="%h"`
do
title=`git log -1 --format="%s" $sha1`
if echo $title | grep -qP '^Merge |^[0-9A-Z/_\-]*: \w'
then
echo "Good commit title: '$title'"
else
echo "Bad commit title: '$title'"
err=1
fi
done

return $err
}

codestyle_check_spell() {
python3 -m venv /tmp/codespell_env
source /tmp/codespell_env/bin/activate
pip3 install codespell
codespell "$@"
}
65 changes: 65 additions & 0 deletions buildlib/tools/git_ready.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash
#
# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# See file LICENSE for terms.
#

source ./buildlib/tools/codestyle.sh

git_commit() {
if ! git diff-index --quiet HEAD; then
git add -p
# returns 1 if cached index is not empty
git diff --cached --exit-code || git commit -m "$title"
git reset --hard
fi
}

ucx=https://github.com/openucx/ucx.git
upstream=$(git remote -v | grep -P "[\t ]${ucx}[\t ].*fetch" | cut -f 1 | head -n 1)
base=$(git merge-base "$upstream"/master HEAD)

if ! git diff-index --quiet HEAD; then
echo "error: tree not clean"
exit 1
fi

codestyle_check_commit_title "$base"..HEAD
if [[ $? -ne 0 ]]
then
echo "error: fix commit title"
exit 1
fi

# Indent
module load dev/llvm-ucx || :
git clang-format --diff "$base" HEAD | patch -p1
module unload dev/llvm-ucx || :

git_commit

# Codespell
codestyle_check_spell --write-changes || :

git_commit

# Pushing
if [ "${1-}" = "--push" ]
then

opt="${2-}"
remote="${opt%%/*}"
branch="${opt#*/}"

if [ "$remote" = "$opt" ] || [ -z "$remote" ] || [ -z "$branch" ]
then
echo "error: specify push location with '--push <remote>/<branch_name>'"
exit 1
fi

cmd="git push $remote HEAD:refs/heads/$branch"
echo "$cmd"
echo "<enter> or <ctrl-c> to abort"
read -r
$cmd
fi
Loading