Skip to content

Commit

Permalink
drop! add ref time and display perf file
Browse files Browse the repository at this point in the history
we also disable sparse checkout for 'in'
  • Loading branch information
o-orand committed Sep 14, 2023
1 parent 2fbd4ec commit 23a62a6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
56 changes: 30 additions & 26 deletions assets/check
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ log() {
local level=$1
local message=$2
local logfile=$3
local ref_time=$4


echo "$(date +'%Y-%m-%d-%H-%M-%S.%N') - $level - $message " >> $logfile
echo "$(date +'%Y-%m-%d-%H-%M-%S.%N') - echo "t + $(( $(date +'%s') - $ref_time))" - $level - $message " >> $logfile
}
set -e

exec 3>&1 # make stdout available as fd 3 for the result
exec 1>&2 # redirect all output to stderr for logging
TIMESTAMP_CMD="date +'%Y-%m-%d-%H-%M-%S.%N'"
TIMESTAMP=$(date +'%Y-%m-%d-%H-%M-%S')
export REF_TIME=$(date +'%s')
export PERFLOG_FILE=/tmp/perf-log-$TIMESTAMP.log
START_TIMESTAMP=$(date +'%Y-%m-%d-%H-%M-%S.%N')

#ls -A1t /tmp/perf-log- | tail -n +11 | xargs rm
log "INFO" "Starting check" $PERFLOG_FILE
log "INFO" "Starting check" $PERFLOG_FILE $REF_TIME
source $(dirname $0)/common.sh
echo ""
# for jq
Expand Down Expand Up @@ -48,7 +50,7 @@ sparse_checkout=$(jq -r '(.source.sparse_checkout // false)' <<< "$payload")
sparse_paths=`echo "$paths" | tr "\n\r" " "`
reverse=false

log "INFO" "Patch to disable sparse_checkout" $PERFLOG_FILE
log "INFO" "Patch to disable sparse_checkout" $PERFLOG_FILE $REF_TIME
sparse_checkout="false"

configure_git_global "${git_config_payload}"
Expand All @@ -65,14 +67,14 @@ fi
# We're just checking for commits; we don't ever need to fetch LFS files here!
export GIT_LFS_SKIP_SMUDGE=1

log "DEBUG" "before destination check" $PERFLOG_FILE
log "DEBUG" "before destination check" $PERFLOG_FILE $REF_TIME
if [ -d $destination ]; then
cd $destination
log "DEBUG" "before git fetch" $PERFLOG_FILE
log "DEBUG" "before git fetch" $PERFLOG_FILE $REF_TIME
git fetch $tagflag -f
log "DEBUG" "before git reset" $PERFLOG_FILE
log "DEBUG" "before git reset" $PERFLOG_FILE $REF_TIME
git reset --hard FETCH_HEAD
log "DEBUG" "after git reset" $PERFLOG_FILE
log "DEBUG" "after git reset" $PERFLOG_FILE $REF_TIME
else
branchflag=""
if [ -n "$branch" ]; then
Expand All @@ -88,18 +90,18 @@ else
git sparse-checkout set $sparse_paths
git checkout $branch
else
log "DEBUG" "before git clone" $PERFLOG_FILE
log "DEBUG" "before git clone" $PERFLOG_FILE $REF_TIME
git clone --single-branch $uri $branchflag $destination $tagflag
log "DEBUG" "after git clone" $PERFLOG_FILE
log "DEBUG" "after git clone" $PERFLOG_FILE $REF_TIME
cd $destination
fi
fi

log "DEBUG" "before ref" $PERFLOG_FILE
log "DEBUG" "before ref" $PERFLOG_FILE $REF_TIME
if [ -n "$ref" ] && git cat-file -e "$ref"; then
log "DEBUG" "before git rev-list --max-parents=0" $PERFLOG_FILE
log "DEBUG" "before git rev-list --max-parents=0" $PERFLOG_FILE $REF_TIME
init_commit=$(git rev-list --max-parents=0 HEAD | tail -n 1)
log "DEBUG" "after git rev-list --max-parents=0" $PERFLOG_FILE
log "DEBUG" "after git rev-list --max-parents=0" $PERFLOG_FILE $REF_TIME
if [ "${ref}" = "${init_commit}" ]; then
reverse=true
log_range="HEAD"
Expand All @@ -112,14 +114,14 @@ else
ref=""
fi

log "DEBUG" "before paths_search" $PERFLOG_FILE
log "DEBUG" "before paths_search" $PERFLOG_FILE $REF_TIME
if [ "$paths" = "." ] && [ -z "$ignore_paths" ]; then
paths_search=""
else
paths_search=`echo "-- $paths $ignore_paths" | tr "\n\r" " "`
fi

log "DEBUG" "before filter_whitelist" $PERFLOG_FILE
log "DEBUG" "before filter_whitelist" $PERFLOG_FILE $REF_TIME
list_command="git rev-list --all --first-parent $log_range $paths_search"
if [ `echo $filter_whitelist | jq -r '. | length'` -gt 0 ]
then
Expand All @@ -130,7 +132,7 @@ then
list_command+=" --grep=\"$wli\""
done
fi
log "DEBUG" "before filter_blacklist" $PERFLOG_FILE
log "DEBUG" "before filter_blacklist" $PERFLOG_FILE $REF_TIME
if [ `echo $filter_blacklist | jq -r '. | length'` -gt 0 ]
then
list_command+=" | git rev-list --stdin --date-order --invert-grep --first-parent --no-walk=unsorted "
Expand All @@ -156,29 +158,29 @@ lines_including_and_after() {
}

get_commit(){
log "DEBUG" "start get_commit" $PERFLOG_FILE
log "DEBUG" "start get_commit" $PERFLOG_FILE $REF_TIME
for tag in $*; do
commit=$(git rev-list -n 1 $tag)
jq -n '{ref: $tag, commit: $commit}' --arg tag $tag --arg commit $commit
done
log "DEBUG" "end get_commit" $PERFLOG_FILE
log "DEBUG" "end get_commit" $PERFLOG_FILE $REF_TIME
}

log "DEBUG" "before log_range" $PERFLOG_FILE
log "DEBUG" "before log_range" $PERFLOG_FILE $REF_TIME
#if no range is selected just grab the last commit that fits the filter
if [ -z "$log_range" ]
then
list_command+="| git rev-list --stdin --date-order --no-walk=unsorted -$version_depth --reverse"
fi

log "DEBUG" "before reverse check" $PERFLOG_FILE
log "DEBUG" "before reverse check" $PERFLOG_FILE $REF_TIME
if [ "$reverse" == "true" ]
then
list_command+="| git rev-list --stdin --date-order --first-parent --no-walk=unsorted --reverse"
fi

if [ -n "$tag_filter" ]; then
log "DEBUG" "start use tag_filter" $PERFLOG_FILE
log "DEBUG" "start use tag_filter" $PERFLOG_FILE $REF_TIME
{
if [ -n "$ref" ] && [ -n "$branch" ]; then
tags=$(git tag --list "$tag_filter" --sort=creatordate --contains $ref --merged $branch)
Expand All @@ -195,10 +197,10 @@ if [ -n "$tag_filter" ]; then
get_commit $tag
fi
} | jq -s "map(.)" >&3
log "DEBUG" "end tag filter" $PERFLOG_FILE
log "DEBUG" "end tag filter" $PERFLOG_FILE $REF_TIME

elif [ -n "$tag_regex" ]; then
log "DEBUG" "start use tag_regex" $PERFLOG_FILE
log "DEBUG" "start use tag_regex" $PERFLOG_FILE $REF_TIME

{
if [ -n "$ref" ] && [ -n "$branch" ]; then
Expand All @@ -216,14 +218,16 @@ elif [ -n "$tag_regex" ]; then
get_commit $tag
fi
} | jq -s "map(.)" >&3
log "DEBUG" "end - use tag_regex" $PERFLOG_FILE
log "DEBUG" "end - use tag_regex" $PERFLOG_FILE $REF_TIME
else
{
set -f
eval "$list_command"
set +f
} | jq -R '.' | jq -s "map({ref: .})" >&3
log "DEBUG" "Starting check" $PERFLOG_FILE
log "DEBUG" "Starting check" $PERFLOG_FILE $REF_TIME
fi

log "INFO" "End check" $PERFLOG_FILE
log "INFO" "End check" $PERFLOG_FILE $REF_TIME

cat $PERFLOG_FILE
1 change: 1 addition & 0 deletions assets/in
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ sparse_checkout=$(jq -r '(.source.sparse_checkout // false)' <<< "$payload")
paths="$(jq -r '(.source.paths // ["."])[]' <<< "$payload")" # those "'s are important

sparse_paths=`echo "$paths" | tr "\n\r" " "`
sparse_checkout=false

# If params not defined, get it from source
if [ -z "$fetch_tags" ] || [ "$fetch_tags" == "null" ] ; then
Expand Down

0 comments on commit 23a62a6

Please sign in to comment.