Skip to content

Instantly share code, notes, and snippets.

@stipsan
Last active March 27, 2017 09:31
Show Gist options
  • Save stipsan/e69536d1a22c08e6e4feb4e14844face to your computer and use it in GitHub Desktop.
Save stipsan/e69536d1a22c08e6e4feb4e14844face to your computer and use it in GitHub Desktop.
Greenkeeper + yarn + travis ci = <3
#!/bin/bash
# Installation instructions for Travis CI, example repo using it in production: https://github.com/stipsan/uikit-react
# .travis.yml
# before_install: "bash <(curl -sL https://gist.github.com/stipsan/e69536d1a22c08e6e4feb4e14844face/raw/)"
echo "Should yarn.lock be regenerated?"
if [[ $TRAVIS_PULL_REQUEST_BRANCH != *"greenkeeper"* ]]; then
echo "Not a GreenKeeper Pull Request, aborting"
exit 0
fi
echo "Yes, cloning repo"
git clone "https://"$PUSH_TOKEN"@github.com/"$TRAVIS_REPO_SLUG".git" repo
cd repo
echo "Switching to branch $TRAVIS_PULL_REQUEST_BRANCH"
git checkout $TRAVIS_PULL_REQUEST_BRANCH
# See if commit message includes "update"
git log --name-status HEAD^..HEAD | grep "package\|yarn\|Merge" || cd .. && rm -rf repo && exit 0
echo "Updating lockfile"
yarn
echo "Commit and push yarn.lock"
git config --global user.email "$PUSH_EMAIL"
git config --global user.name "Travis CI"
git config --global push.default simple
git add yarn.lock
git commit -m "chore(yarn): update yarn.lock"
PUSH_STATUS=$(git push 2>&1)
if [[ $PUSH_STATUS == "Everything up-to-date" ]]; then
cd ..
rm -rf repo
exit 0
fi
echo "Pushed commit to trigger rebuild, this build will cancel"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment