Skip to content

Commit

Permalink
Fix non-empty check for invalid changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Miller committed Aug 30, 2019
1 parent 66dbb0c commit 72b5318
Showing 1 changed file with 18 additions and 48 deletions.
66 changes: 18 additions & 48 deletions ci/build.sh
Original file line number Diff line number Diff line change
@@ -1,64 +1,38 @@
#!/bin/sh

if [ "$TRAVIS_PULL_REQUEST" == false ] && [ "$TRAVIS_BRANCH" != "master" ] && [ "$TRAVIS_EVENT_TYPE" == "push" ]; then
changes=`git diff master...$TRAVIS_BRANCH --name-only | grep -i "fluentd-sumologic.yaml.tmpl\|fluent-bit-overrides.yaml\|prometheus-overrides.yaml\|falco-overrides.yaml"`
if [ -n "$changes" ]; then
if git --no-pager show -s --format="%an" . | grep -v -q -i "travis"; then
echo "Aborting due to manual changes detected in the following generated files: $changes"
exit 1
fi
fi
fi

VERSION="${TRAVIS_TAG:-0.0.0}"
VERSION="${VERSION#v}"
: "${DOCKER_TAG:=sumologic/kubernetes-fluentd}"
: "${DOCKER_USERNAME:=sumodocker}"
DOCKER_TAGS="https://registry.hub.docker.com/v1/repositories/sumologic/kubernetes-fluentd/tags"

echo "Starting build process in: `pwd` with version tag: $VERSION"
set -e

for i in ./fluent-plugin* ; do
if [ -d "$i" ]; then
cd $i
PLUGIN_NAME=$(basename "$i")
# Strip "-alpha" suffix if it exists to avoid gem prerelease behavior
GEM_VERSION=${VERSION%"-alpha"}
echo "Building gem $PLUGIN_NAME version $GEM_VERSION in `pwd` ..."
sed -i.bak "s/0.0.0/$GEM_VERSION/g" ./$PLUGIN_NAME.gemspec
rm -f ./$PLUGIN_NAME.gemspec.bak

echo "Install bundler..."
bundle install

echo "Run unit tests..."
bundle exec rake

echo "Build gem $PLUGIN_NAME $GEM_VERSION..."
gem build $PLUGIN_NAME
mv *.gem ../deploy/docker/gems

cd ..
fi
done

echo "Building docker image with $DOCKER_TAG:local in `pwd`..."
cd ./deploy/docker
docker build . -f ./Dockerfile -t $DOCKER_TAG:local --no-cache
rm -f ./gems/*.gem
cd ../..

echo "Test docker image locally..."
ruby deploy/test/test_docker.rb
err_report() {
echo "Error on line $1"
}
trap 'err_report $LINENO' ERR

# Set up Github
if [ -n "$GITHUB_TOKEN" ]; then
git config --global user.email "travis@travis-ci.org"
git config --global user.name "Travis CI"
git remote add origin-repo https://${GITHUB_TOKEN}@github.com/SumoLogic/sumologic-kubernetes-collection.git > /dev/null 2>&1
git fetch origin-repo
git checkout $TRAVIS_BRANCH
fi

# Check for invalid changes to overrides yaml files
if [ -n "$GITHUB_TOKEN" ] && [ "$TRAVIS_PULL_REQUEST" == false ] && [ "$TRAVIS_BRANCH" != "master" ] && [ "$TRAVIS_EVENT_TYPE" == "push" ]; then
changes=`git diff origin-repo/master..$TRAVIS_BRANCH --name-only | grep -i "fluentd-sumologic.yaml.tmpl\|fluent-bit-overrides.yaml\|prometheus-overrides.yaml\|falco-overrides.yaml"`
if [ -n "$changes" ]; then
if git --no-pager show -s --format="%an" . | grep -v -q -i "travis"; then
echo "Aborting due to manual changes detected in the following generated files: $changes"
exit 1
fi
fi
fi

# Check for changes that require re-generating overrides yaml files
if [ "$TRAVIS_BRANCH" != "master" ] && [ "$TRAVIS_EVENT_TYPE" == "push" ] && [ -n "$GITHUB_TOKEN" ]; then
echo "Generating yaml from helm chart..."
echo "# This file is auto-generated." > deploy/kubernetes/fluentd-sumologic.yaml.tmpl
Expand All @@ -72,8 +46,6 @@ if [ "$TRAVIS_BRANCH" != "master" ] && [ "$TRAVIS_EVENT_TYPE" == "push" ] && [ -

if [[ $(git diff deploy/kubernetes/fluentd-sumologic.yaml.tmpl) ]]; then
echo "Detected changes in 'fluentd-sumologic.yaml.tmpl', committing the updated version to $TRAVIS_BRANCH..."
git fetch origin-repo
git checkout $TRAVIS_BRANCH
git add deploy/kubernetes/fluentd-sumologic.yaml.tmpl
git commit -m "Generate new 'fluentd-sumologic.yaml.tmpl'"
git push --quiet origin-repo "$TRAVIS_BRANCH"
Expand Down Expand Up @@ -120,8 +92,6 @@ if [ "$TRAVIS_BRANCH" != "master" ] && [ "$TRAVIS_EVENT_TYPE" == "push" ] && [ -

if [ "$(git diff deploy/helm/fluent-bit-overrides.yaml)" ] || [ "$(git diff deploy/helm/prometheus-overrides.yaml)" ] || [ "$(git diff deploy/helm/falco-overrides.yaml)" ]; then
echo "Detected changes in 'fluent-bit-overrides.yaml', 'prometheus-overrides.yaml' or 'falco-overrides.yaml', committing the updated version to $TRAVIS_BRANCH..."
git fetch origin-repo
git checkout $TRAVIS_BRANCH
git add deploy/helm/*-overrides.yaml
git commit -m "Generate new overrides yaml file(s)."
git push --quiet origin-repo "$TRAVIS_BRANCH"
Expand Down

0 comments on commit 72b5318

Please sign in to comment.