Skip to content

Commit

Permalink
Merge pull request #6 from yulii/feature/auto-update
Browse files Browse the repository at this point in the history
Create auto update pull request
  • Loading branch information
yulii committed Aug 14, 2017
2 parents da99778 + d6346d3 commit 7ec5103
Show file tree
Hide file tree
Showing 2 changed files with 237 additions and 28 deletions.
55 changes: 55 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,58 @@ jobs:
command: |
yarn run coverage
cat coverage/lcov.info | "$(npm bin)/coveralls"
update:
docker:
- image: circleci/node:7.10
steps:
- run:
name: Checkout code
command: git clone -b master --depth 1 https://${FORK_REPO_TOKEN}@github.com/yulii-bot/hubot-scripts.git .
- run:
name: Syncing fork
command: |
git remote add upstream https://github.com/yulii/hubot-scripts.git
git fetch upstream
git checkout master
git merge upstream/master
- run:
name: Update dependencies
command: yarn upgrade
- run:
name: Commit auto update file
command: |
test -z "$(git status -s yarn.lock 2> /dev/null)" && echo 'No update.' && exit 0
BRANCH="update-$(sha1sum yarn.lock | cut -d' ' -f1)"
test -n "$(git ls-remote origin ${BRANCH} 2> /dev/null)" && echo 'Already committed.' && exit 0
git config --local user.email 'yuliinfo+bot@gmail.com'
git config --local user.name 'yulii-bot'
git add yarn.lock
git commit -m 'Bundle update'
git branch -M ${BRANCH}
git push origin ${BRANCH}
- run:
name: Send auto update pull request
command: |
BRANCH="update-$(sha1sum yarn.lock | cut -d' ' -f1)"
test -z "$(git ls-remote origin ${BRANCH} 2> /dev/null)" && echo "Update branch not found." && exit 0
git fetch origin ${BRANCH}
test -z "$(git diff upstream/master...FETCH_HEAD)" && echo "No changes." && exit 0
curl -H "Authorization: token ${FORK_REPO_TOKEN}" \
-X POST -H "Content-Type: application/json" \
-d "{ \"title\": \"Yarn upgrade\", \"body\": \"Auto update pull request!\", \"head\": \"yulii-bot:${BRANCH}\", \"base\": \"master\" }" \
"https://api.github.com/repos/yulii/hubot-scripts/pulls" \
| tee /tmp/create-pull-request.log.json
test -n "$(cat /tmp/create-pull-request.log.json | jq -r 'select(.errors == null)')"
workflows:
version: 2
build_and_update:
jobs:
- build
- update:
requires:
- build
filters:
branches:
only: master
Loading

0 comments on commit 7ec5103

Please sign in to comment.