mirror of
https://github.com/keymanapp/keyman.git
synced 2026-10-08 15:07:33 +00:00
Merge pull request #2603 from keymanapp/chore/ci/is-build-required
chore(ci): is build required?
This commit is contained in:
commit
60a36182e5
2 changed files with 140 additions and 0 deletions
17
resources/build/build-triggers.sh
Normal file
17
resources/build/build-triggers.sh
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# This file maps specific paths to build triggers
|
||||
#
|
||||
|
||||
# the base folder for each pattern does not need to be included, nor oem folders
|
||||
# e.g. android='common/predictive-text|common/lexical-model-types'
|
||||
# will expand into android='^(android|(oem/[^/]+/android)|common/predictive-text|common/lexical-model-types)'
|
||||
|
||||
watch_android='web|common/predictive-text|common/lexical-model-types'
|
||||
watch_ios='web|common/predictive-text|common/lexical-model-types'
|
||||
watch_linux='common/engine'
|
||||
watch_mac='common/engine'
|
||||
watch_web='common/predictive-text|common/lexical-model-types'
|
||||
|
||||
# Windows currently builds Developer and Desktop, so we need everything from common,developer,web
|
||||
watch_windows='common|developer|web'
|
||||
123
resources/build/is-build-required.sh
Executable file
123
resources/build/is-build-required.sh
Executable file
|
|
@ -0,0 +1,123 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Determine if we need to do a build based on rules in
|
||||
# build-triggers.sh, rather than calculating changes in
|
||||
# TeamCity. If a build is not needed, then cancel the
|
||||
# build in TeamCity
|
||||
#
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
## START STANDARD BUILD SCRIPT INCLUDE
|
||||
# adjust relative paths as necessary
|
||||
THIS_SCRIPT="$(greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null || readlink -f "${BASH_SOURCE[0]}")"
|
||||
. "$(dirname "$THIS_SCRIPT")/build-utils.sh"
|
||||
## END STANDARD BUILD SCRIPT INCLUDE
|
||||
|
||||
. "$(dirname "$THIS_SCRIPT")/build-triggers.sh"
|
||||
|
||||
#
|
||||
# Parameter test
|
||||
#
|
||||
|
||||
invalid=false
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
if [ ! -z "${TEAMCITY_PLATFORM}" ]; then
|
||||
platform="$TEAMCITY_PLATFORM"
|
||||
else
|
||||
echo "Either TEAMCITY_PLATFORM env var must be set, or must pass as first parameter"
|
||||
invalid=true
|
||||
fi
|
||||
else
|
||||
platform="$1"
|
||||
fi
|
||||
|
||||
if [ $# -lt 2 ]; then
|
||||
if [ ! -z "${TEAMCITY_PR_NUMBER-}" ]; then
|
||||
PRNUM="$TEAMCITY_PR_NUMBER"
|
||||
else
|
||||
echo "Either TEAMCITY_PR_NUMBER env var must be set, or must pass as second parameter"
|
||||
invalid=true
|
||||
fi
|
||||
else
|
||||
PRNUM="$2"
|
||||
fi
|
||||
|
||||
if [[ ! "$platform" =~ android|ios|linux|mac|web|windows ]]; then
|
||||
echo "Invalid platform $platform"
|
||||
invalid=true
|
||||
fi
|
||||
|
||||
if [[ $invalid == true ]]; then
|
||||
echo "Usage: $(basename "$THIS_SCRIPT") [platform [prnum]]"
|
||||
echo "platform can be one of:"
|
||||
echo " android"
|
||||
echo " ios"
|
||||
echo " linux"
|
||||
echo " mac"
|
||||
echo " web"
|
||||
echo " windows (includes Desktop + Developer)"
|
||||
echo "If not passed, then platform is read from env TEAMCITY_PLATFORM,"
|
||||
echo "and PRNUM is read from env TEAMCITY_PR_NUMBER"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#
|
||||
# Following is not an error; this script can run against master/beta/stable
|
||||
# branches as well as pull requests
|
||||
#
|
||||
|
||||
if [[ ! "$PRNUM" =~ ^[[:digit:]]+$ ]]; then
|
||||
echo "Branch spec $PRNUM is not a pull request number; not stopping build."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
#
|
||||
# Make sure our local index is up to date with origin
|
||||
#
|
||||
|
||||
pushd "$KEYMAN_ROOT" > /dev/null
|
||||
|
||||
git fetch origin
|
||||
|
||||
#
|
||||
# Find the base and head of the pull request from GitHub
|
||||
#
|
||||
|
||||
prinfo=`curl -s -H "User-Agent: @keymanapp" https://api.github.com/repos/keymanapp/keyman/pulls/$PRNUM`
|
||||
prbase=`echo ${prinfo} | sed -E 's/.+"base".+"ref":"([^"]+)".+/\1/'`
|
||||
prhead=`echo ${prinfo} | sed -E 's/.+"head".+"ref":"([^"]+)".+"base".+"ref":.+/\1/'`
|
||||
|
||||
# echo "Base of $PRNUM ($prhead) is $prbase"
|
||||
|
||||
#
|
||||
# Then get a list of changed files between BASE of the branch and the branch itself
|
||||
# We work from origin so we don't need the branches checked out ourselves
|
||||
#
|
||||
|
||||
prfiles=`git diff "origin/$prbase"..."origin/$prhead" --name-only`
|
||||
|
||||
# Which platform are we watching?
|
||||
eval watch='$'watch_$platform
|
||||
# Add common patterns to the watch list
|
||||
watch="^($platform|(oem/[^/]+/$platform)|resources|$watch)"
|
||||
|
||||
# echo "watch=$watch"
|
||||
|
||||
# Scan the files found
|
||||
while IFS= read -r line; do
|
||||
# echo "... $line"
|
||||
if [[ "$line" =~ $watch ]]; then
|
||||
echo "Platform $platform is impacted by changes found in PR #$PRNUM. Continuing build."
|
||||
exit 0
|
||||
fi
|
||||
done <<< "$prfiles"
|
||||
|
||||
popd >/dev/null
|
||||
|
||||
# Exit 1 will fail the build, but we override the failure with the buildStatus text!
|
||||
echo "Platform $platform is not impacted by the changes found in PR #$PRNUM. Skipping build."
|
||||
echo "##teamcity[buildStatus status='SUCCESS' text='Platform $platform is not impacted by the changes found in PR #$PRNUM. Skipping build.']"
|
||||
exit 1
|
||||
Loading…
Add table
Reference in a new issue