Skip to content

Commit

Permalink
Create helper function with translators-to-check logic
Browse files Browse the repository at this point in the history
And create script to use that for linting as well
dstillman committed Jan 30, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 541ea68 commit d594dcf
Showing 4 changed files with 41 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .ci/checkDeletedTxt.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source "$SCRIPT_DIR/helper.sh"
. "$SCRIPT_DIR/helper.sh"
cd "$SCRIPT_DIR"

MASTER="master"
@@ -25,7 +25,7 @@ main() {
deletions+=($(git diff-index --diff-filter=D --name-only --find-renames $MASTER|grep -v '\.ci'|grep 'js$'))
if (( ${#deletions[@]} > 0 ));then
for f in "${deletions[@]}";do
local id=$(git show $MASTER:"$f"|grepTranslatorId)
local id=$(git show $MASTER:"$f" | grep_translator_id)
if ! grep -qF "$id" '../deleted.txt';then
echo "${color_notok}not ok${color_reset} - $id ($f) should be added to deleted.txt"
(( failed += 1))
31 changes: 29 additions & 2 deletions .ci/helper.sh
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ if [[ -t 1 && "$(tput colors)" -gt 0 ]]; then
export color_reset=$'\e[0m'
fi

grepTranslatorId () {
get_translator_id() {
if [[ -n "$1" ]];then
grep -r '"translatorID"' "$@" | sed -e 's/[" ,]//g' -e 's/^.*://g'
else
@@ -18,4 +18,31 @@ grepTranslatorId () {
fi
}

# vim: ft=sh
get_translators_to_check() {
# If a PR branch has no conflicts with the master then git
# creates a custom merge commit where it merges PR into master.
# Travis-CI tests on that commit instead of the HEAD of the PR branch.
#
# Thus below we first determine if HEAD is a merge commit by checking how
# many parents the current HEAD has. If number of parents > 1, then it's a merge commit
# in which case we need to diff translator names between HEAD^2 and PR split commit from master.
# The above will generally only be the case in CI or if using a custom PR pulling script which
# pulls the merge PR commit instead of just the PR branch.
#
# If the HEAD commit is not a merge then we diff HEAD with PR split commit from master. This is the case
# when running from a local development PR branch
#
# The branching point hash retrieval logic is based on https://stackoverflow.com/a/12185115/3199106

TRANSLATORS_TO_CHECK=""

# Gets parent commits. Either one or two hashes
local parent_commits=($(git show --no-patch --format="%P" HEAD))
# Size of $parent_commits array
local num_parent_commits=${#parent_commits[@]}
if [ $num_parent_commits -gt 1 ]; then
TRANSLATORS_TO_CHECK=$(git diff HEAD^2 $(git rev-list "$(git rev-list --first-parent ^master HEAD^2 | tail -n1)^^!") --name-only | grep -e "^[^/]*.js$")
else
TRANSLATORS_TO_CHECK=$(git diff $(git rev-list "$(git rev-list --first-parent ^master HEAD | tail -n1)^^!") --name-only | grep -e "^[^/]*.js$")
fi
}
9 changes: 9 additions & 0 deletions .ci/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail

dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

. "$dir/helper.sh"

get_translators_to_check
npm run lint -- "$TRANSLATORS_TO_CHECK"
28 changes: 1 addition & 27 deletions .ci/pull-request-check/check-pull-request.sh
Original file line number Diff line number Diff line change
@@ -7,33 +7,7 @@ fi
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOT_DIR="$( dirname "$DIR" )"

TRANSLATORS_TO_CHECK=""
get_translators_to_check() {
# If a PR branch has no conflicts with the master then git
# creates a custom merge commit where it merges PR into master.
# Travis-CI tests on that commit instead of the HEAD of the PR branch.
#
# Thus below we first determine if HEAD is a merge commit by checking how
# many parents the current HEAD has. If number of parents > 1, then its a merge commit
# in which case we need to diff translator names between HEAD^2 and PR split commit from master.
# The above will generally only be the case on Travis-CI or if using a custom PR pulling script which
# pulls the merge PR commit instead of just the PR branch.
#
# If the HEAD commit is not a merge then we diff HEAD with PR split commit from master. This is the case
# when running from a local development PR branch
#
# The branching point hash retrieval logic is based on https://stackoverflow.com/a/12185115/3199106

# Gets parent commits. Either one or two hashes
PARENT_COMMITS=($(git show --no-patch --format="%P" HEAD))
# Size of $PARENT_COMMITS array
NUM_PARENT_COMMITS=${#PARENT_COMMITS[@]}
if [ $NUM_PARENT_COMMITS -gt 1 ]; then
TRANSLATORS_TO_CHECK=$(git diff HEAD^2 $(git rev-list "$(git rev-list --first-parent ^master HEAD^2 | tail -n1)^^!") --name-only | grep -e "^[^/]*.js$")
else
TRANSLATORS_TO_CHECK=$(git diff $(git rev-list "$(git rev-list --first-parent ^master HEAD | tail -n1)^^!") --name-only | grep -e "^[^/]*.js$")
fi
}
. "$ROOT_DIR/helper.sh"

# Build connector
mkdir -p connectors

0 comments on commit d594dcf

Please sign in to comment.