<commit_before>#!/bin/bash

ROOT_DIR=/workspace
RESULTSDIR=$ROOT_DIR/results/misc-checks
OUTFILE=$RESULTSDIR/out
FAILFILE=$RESULTSDIR/fail
FORKSLUGFILE=$ROOT_DIR/user-config/fork-slug.txt

if ! stat $RESULTSDIR; then
  exit 0
fi

go get github.com/openconfig/models-ci/validators/misc-checks/...

# all-non-empty-files.txt
find $_MODEL_ROOT -name '*.yang' > $RESULTSDIR/all-non-empty-files.txt 2>> $OUTFILE

# pr-file-parse-log
# This output is used to check for both the version update as well as build
# reachability. The latter requirement requires the script to be generated by
# cmd_gen in a per-model manner.
# TODO(wenbli): Ideally we should do the version and reachability checks
# separately -- i.e. the version script should be fed all of the files; and a
# separate script lists the files that are reachable.
# This requires the check logic within post_results to be changed.
# I'm delaying this because it remains to be seen whether goyang can be
# refactored so we don't need do this inter-process communication via files.
if bash $RESULTSDIR/script.sh >> $OUTFILE 2>> $FAILFILE; then
  # Delete fail file if it's empty and the script passed.
  find $FAILFILE -size 0 -delete
fi
cat $RESULTSDIR/*.pr-file-parse-log > $RESULTSDIR/pr-file-parse-log 2>> $OUTFILE

# changed-files.txt
REPODIR=$RESULTSDIR/base_repo
if stat $FORKSLUGFILE; then
  # fork PR
  git clone "<EMAIL>:$_REPO_SLUG.git" $REPODIR
  cd $REPODIR
  REMOTENAME=gcb-ci-fork-remote-repo-qwertyqwerty
  git remote add $REMOTENAME $_HEAD_REPO_URL
  git fetch $REMOTENAME
  echo "PR is from a forked repo. Deduced remote head branch to be $_HEAD_REPO_URL:$BRANCH_NAME" | tee >> $OUTFILE
  git checkout $REMOTENAME/$BRANCH_NAME
  BASE_COMMIT=master
else
  # regular (non-fork) PR
  git clone -b $BRANCH_NAME "<EMAIL>:$_REPO_SLUG.git" $REPODIR
  cd $REPODIR
  BASE_COMMIT=$(git merge-base $COMMIT_SHA origin/master)
fi
git diff --name-only $BASE_COMMIT | grep -E '.*\.yang$' > $RESULTSDIR/changed-files.txt 2>> $OUTFILE<commit_msg>Use correct merge base<commit_after>#!/bin/bash

ROOT_DIR=/workspace
RESULTSDIR=$ROOT_DIR/results/misc-checks
OUTFILE=$RESULTSDIR/out
FAILFILE=$RESULTSDIR/fail
FORKSLUGFILE=$ROOT_DIR/user-config/fork-slug.txt

if ! stat $RESULTSDIR; then
  exit 0
fi

go get github.com/openconfig/models-ci/validators/misc-checks/...

# all-non-empty-files.txt
find $_MODEL_ROOT -name '*.yang' > $RESULTSDIR/all-non-empty-files.txt 2>> $OUTFILE

# pr-file-parse-log
# This output is used to check for both the version update as well as build
# reachability. The latter requirement requires the script to be generated by
# cmd_gen in a per-model manner.
# TODO(wenbli): Ideally we should do the version and reachability checks
# separately -- i.e. the version script should be fed all of the files; and a
# separate script lists the files that are reachable.
# This requires the check logic within post_results to be changed.
# I'm delaying this because it remains to be seen whether goyang can be
# refactored so we don't need do this inter-process communication via files.
if bash $RESULTSDIR/script.sh >> $OUTFILE 2>> $FAILFILE; then
  # Delete fail file if it's empty and the script passed.
  find $FAILFILE -size 0 -delete
fi
cat $RESULTSDIR/*.pr-file-parse-log > $RESULTSDIR/pr-file-parse-log 2>> $OUTFILE

# changed-files.txt
REPODIR=$RESULTSDIR/base_repo
if stat $FORKSLUGFILE; then
  # fork PR
  git clone "<EMAIL>:$_REPO_SLUG.git" $REPODIR
  cd $REPODIR
  REMOTENAME=gcb-ci-fork-remote-repo-long-name-to-avoid-conflict
  git remote add $REMOTENAME $_HEAD_REPO_URL
  git fetch $REMOTENAME
  echo "PR is from a forked repo. Deduced remote head branch to be $_HEAD_REPO_URL:$BRANCH_NAME" | tee >> $OUTFILE
  git checkout $REMOTENAME/$BRANCH_NAME
  BASE_COMMIT=$(git merge-base $REMOTENAME/$BRANCH_NAME origin/master)
else
  # regular (non-fork) PR
  git clone -b $BRANCH_NAME "<EMAIL>:$_REPO_SLUG.git" $REPODIR
  cd $REPODIR
  BASE_COMMIT=$(git merge-base $COMMIT_SHA origin/master)
fi
git diff --name-only $BASE_COMMIT | grep -E '.*\.yang$' > $RESULTSDIR/changed-files.txt 2>> $OUTFILE
{'fraction_non_alphanumeric': 0.10500490677134446, 'fraction_numerical': 0.002944062806673209, 'mean_word_length': 4.407161803713528, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '220991', 'n_tokens_mistral': 1476, 'n_tokens_neox': 1394, 'n_words': 445}