|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +BRANCH="update-modules" |
| 19 | + |
| 20 | +pushd $TRAVIS_BUILD_DIR |
| 21 | + |
| 22 | +#debug |
| 23 | +pwd |
| 24 | +ls |
| 25 | + |
| 26 | +# remove any update-modules branch |
| 27 | +git branch -D "${BRANCH}" 2>/dev/null |
| 28 | + |
| 29 | +git remote add upstream https://github.com/apache/mynewt-mcumgr-cli |
| 30 | +[[ $? -ne 0 ]] && exit 1 |
| 31 | + |
| 32 | +git fetch upstream |
| 33 | +[[ $? -ne 0 ]] && exit 1 |
| 34 | + |
| 35 | +# must be running on master to find modules that were updated! |
| 36 | +git reset --hard upstream/master |
| 37 | + |
| 38 | +is_mod=0 |
| 39 | +modules=() |
| 40 | +while read line; do |
| 41 | + if [[ "${line}" == "require (" ]]; then |
| 42 | + is_mod=1 |
| 43 | + elif [[ $is_mod -eq 1 && "${line}" == ")" ]]; then |
| 44 | + is_mod=0 |
| 45 | + break |
| 46 | + elif [[ $is_mod -eq 1 ]]; then |
| 47 | + module="$(echo ${line} | cut -d' ' -f1)" |
| 48 | + modules[${#modules[*]}]=$module |
| 49 | + fi |
| 50 | +done <go.mod |
| 51 | + |
| 52 | +pushd mcumgr |
| 53 | +for module in ${modules[*]}; do |
| 54 | + go get -v -u $module |
| 55 | +done |
| 56 | +popd |
| 57 | + |
| 58 | +git diff --quiet |
| 59 | +if [[ $? -eq 0 ]]; then |
| 60 | + echo "No changes detected." |
| 61 | + exit 0 |
| 62 | +fi |
| 63 | + |
| 64 | +# Check that still builds... |
| 65 | +pushd mcumgr |
| 66 | +go build -v |
| 67 | +[[ $? -ne 0 ]] && exit 1 |
| 68 | +popd |
| 69 | + |
| 70 | +git checkout -b "${BRANCH}" |
| 71 | +[[ $? -ne 0 ]] && exit 1 |
| 72 | + |
| 73 | +git commit -m "Update dependencies (automated)" go.mod go.sum |
| 74 | + |
| 75 | +# Add new repo that has a valid write permission token |
| 76 | +git remote add writable https://${GH_TOKEN}@github.com/apache-mynewt-bot/mynewt-mcumgr-cli.git |
| 77 | +git push writable ${BRANCH} --force |
| 78 | +[[ $? -ne 0 ]] && exit 1 |
| 79 | + |
| 80 | +# Create PR through GH API |
| 81 | +curl -H "Content-Type: application/json" \ |
| 82 | + -H "authToken: ${GH_TOKEN}" \ |
| 83 | + --data '{"title":"Update dependencies","body":"New dependencies found!","head":"apache-mynewt-bot:update-modules","base":"master"}' \ |
| 84 | + https://api.github.com/repos/apache/mynewt-mcumgr-cli/pulls |
0 commit comments