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

[CI] Support reproduceable build for git clone (#6562) #7963

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion Makefile.work
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ $(shell CONFIGURED_ARCH=$(CONFIGURED_ARCH) MULTIARCH_QEMU_ENVIRON=$(MULTIARCH_QE
$(shell BUILD_SLAVE=y scripts/prepare_docker_buildinfo.sh $(SLAVE_BASE_IMAGE) $(SLAVE_DIR)/Dockerfile $(CONFIGURED_ARCH) "" $(BLDENV))

# Add the versions in the tag, if the version change, need to rebuild the slave
SLAVE_BASE_TAG = $(shell cat $(SLAVE_DIR)/Dockerfile $(SLAVE_DIR)/buildinfo/versions/versions-* | sha1sum | awk '{print substr($$1,0,11);}')
SLAVE_BASE_TAG = $(shell cat $(SLAVE_DIR)/Dockerfile $(SLAVE_DIR)/buildinfo/versions/versions-* src/sonic-build-hooks/hooks/* | sha1sum | awk '{print substr($$1,0,11);}')
SLAVE_TAG = $(shell cat $(SLAVE_DIR)/Dockerfile.user $(SLAVE_DIR)/Dockerfile $(SLAVE_DIR)/buildinfo/versions/versions-* | sha1sum | awk '{print substr($$1,0,11);}')

OVERLAY_MODULE_CHECK := \
Expand Down
76 changes: 76 additions & 0 deletions src/sonic-build-hooks/hooks/git
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash

parse_config(){
. /usr/local/share/buildinfo/scripts/buildinfo_base.sh
REAL_COMMAND=$(get_command git)

version_file=$VERSION_PATH/versions-git
new_version_file=$BUILD_VERSION_PATH/versions-git

MODE_CLONE=0
# parse input parameters
for i in "$@"
liushilongbuaa marked this conversation as resolved.
Show resolved Hide resolved
do
if [[ $i == "clone" ]];then
MODE_CLONE=1
fi
done
}

get_clone_path(){
# get paremater of clone path
while (( "$#" )); do
case $1 in
-b|--branch|--reference|--reference-if-able|-c|--config|--origin|-u|--upload-pack|-j|--jobs|--depth|--dissociate)
shift 2
;;
clone|-l|--local|--no-hardlinks|-s|--shared|--dissociate|-q|--quiet|-v|--verbose|--progress|--server-option=*|--bare|--sparse|--filter=*|--template=*|--mirror|--reference|--shallow-*|--no-tags|--recurse-submodules*|--remote-submodules|--no-remote-submodules|--separate-git-dir*)
shift 1
;;
*)
if [[ $URL == "" ]];then
liushilongbuaa marked this conversation as resolved.
Show resolved Hide resolved
URL=$1
else
clone_PATH=$1
fi
shift 1
;;
esac
done

# if not specific clone path, get default clone path
[ -z $clone_PATH ] && clone_PATH=`echo $URL | rev | awk -F/ '{print$1}' | rev | awk -F. '{print$1}'`
liushilongbuaa marked this conversation as resolved.
Show resolved Hide resolved
}

main(){
parse_config "$@"

# execute git.
$REAL_COMMAND "$@"
result=$?

# if sub command is not "clone", exit
if [[ $MODE_CLONE != 1 ]];then
exit $result
fi

get_clone_path "$@"
pushd $clone_PATH &> /dev/null
commit_latest=`$REAL_COMMAND log -n 1 | head -n 1| awk '{print$2}'`
liushilongbuaa marked this conversation as resolved.
Show resolved Hide resolved
[ -f $version_file ] && commit=`grep $URL $version_file | awk -F, '{print$2}'`
liushilongbuaa marked this conversation as resolved.
Show resolved Hide resolved

# control version or record version file
if [[ $ENABLE_VERSION_CONTROL_GIT == "y" ]];then
# control version
[ ! -z $commit ] && $REAL_COMMAND reset --hard $commit &> /dev/null
else
# record version file
echo "$URL==$commit_latest" >> $new_version_file
liushilongbuaa marked this conversation as resolved.
Show resolved Hide resolved
sort $new_version_file -o $new_version_file -u &> /dev/null
fi
popd &> /dev/null

exit $result
}

main "$@"