Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Travis CI to support PR push #262

Merged
merged 1 commit into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ before_install:
- sudo apt install snapd
- sudo snap install helm --classic
script: bash ci/build.sh
branches:
only:
- master
14 changes: 7 additions & 7 deletions ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ if [ -n "$GITHUB_TOKEN" ]; then
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
git checkout $TRAVIS_PULL_REQUEST_BRANCH
fi

# Check for invalid changes to generated yaml files (non-Tag builds)
if [ -n "$GITHUB_TOKEN" ] && [ -z "$TRAVIS_TAG" ] && [ "$TRAVIS_PULL_REQUEST" == false ] && [ "$TRAVIS_BRANCH" != "master" ] && [ "$TRAVIS_EVENT_TYPE" == "push" ]; then
if [ -n "$GITHUB_TOKEN" ] && [ "$TRAVIS_EVENT_TYPE" == "pull_request" ]; then
# Check most recent commit author. If non-Travis, check for changes made to generated files
recent_author=`git log origin-repo/master..HEAD --format="%an" | grep -m1 ""`
if echo $recent_author | grep -v -q -i "travis"; then
Expand Down Expand Up @@ -70,7 +70,7 @@ echo "Test docker image locally..."
ruby deploy/test/test_docker.rb

# Check for changes that require re-generating overrides yaml files
if [ "$TRAVIS_BRANCH" != "master" ] && [ "$TRAVIS_EVENT_TYPE" == "push" ] && [ -n "$GITHUB_TOKEN" ]; then
if [ -n "$GITHUB_TOKEN" ] && [ "$TRAVIS_EVENT_TYPE" == "pull_request" ]; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, @samjsong , PRs submitted from outside repos like #264 won't have $GITHUB_TOKEN . So this will require some more thought.

echo "Generating yaml from helm chart..."
echo "# This file is auto-generated." > deploy/kubernetes/fluentd-sumologic.yaml.tmpl
sudo helm init --client-only
Expand All @@ -82,10 +82,10 @@ if [ "$TRAVIS_BRANCH" != "master" ] && [ "$TRAVIS_EVENT_TYPE" == "push" ] && [ -
eval 'sudo helm template deploy/helm/sumologic $with_files --namespace "\$NAMESPACE" --name collection --set dryRun=true >> deploy/kubernetes/fluentd-sumologic.yaml.tmpl --set sumologic.endpoint="bogus" --set sumologic.accessId="bogus" --set sumologic.accessKey="bogus"'

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..."
echo "Detected changes in 'fluentd-sumologic.yaml.tmpl', committing the updated version to $TRAVIS_PULL_REQUEST_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"
git push --quiet origin-repo "$TRAVIS_PULL_REQUEST_BRANCH"
else
echo "No changes in 'fluentd-sumologic.yaml.tmpl'."
fi
Expand Down Expand Up @@ -124,10 +124,10 @@ if [ "$TRAVIS_BRANCH" != "master" ] && [ "$TRAVIS_EVENT_TYPE" == "push" ] && [ -
sed -n "$falco_start,$ p" deploy/helm/sumologic/values.yaml | sed 's/ //' >> deploy/helm/falco-overrides.yaml

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..."
echo "Detected changes in 'fluent-bit-overrides.yaml', 'prometheus-overrides.yaml' or 'falco-overrides.yaml', committing the updated version to $TRAVIS_PULL_REQUEST_BRANCH..."
git add deploy/helm/*-overrides.yaml
git commit -m "Generate new overrides yaml file(s)."
git push --quiet origin-repo "$TRAVIS_BRANCH"
git push --quiet origin-repo "$TRAVIS_PULL_REQUEST_BRANCH"
else
echo "No changes in the generated overrides files."
fi
Expand Down