|
| 1 | +#!/bin/bash |
| 2 | +USERNAME=${CIRCLE_PROJECT_USERNAME} |
| 3 | +REPONAME=${CIRCLE_PROJECT_REPONAME} |
| 4 | +GIT_USERNAME="patternfly-build" |
| 5 | +REPO="github.com:${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}.git" |
| 6 | +echo "Preparing release environment..." |
| 7 | +git config user.email "patternfly-build@redhat.com" |
| 8 | +git config user.name ${GIT_USERNAME} |
| 9 | +git config credential.helper store |
| 10 | +echo "https://${GIT_USERNAME}:${GH_TOKEN}@${REPO}" > ~/.git-credentials |
| 11 | +echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc |
| 12 | + |
| 13 | +echo "Doing a release..." |
| 14 | +# Lerna is complicated. Commands: https://github.com/lerna/lerna/tree/master/commands |
| 15 | +# Identify packages that have been updated since the previous tagged release |
| 16 | +# Update their versions and changelogs according to angular commit guidelines |
| 17 | +# https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit |
| 18 | + |
| 19 | +# Grab the log before lerna makes a commit |
| 20 | +LOG=$(git log --format="%s" -1 | grep -Poe "#\d+") |
| 21 | +PR_NUM=${LOG:1} |
| 22 | + |
| 23 | +yarn run lerna publish --conventional-commits --create-release=github --yes | tee lerna-output.txt |
| 24 | + |
| 25 | +if grep -i "Successfully published" lerna-output.txt; # Leave a Github comment |
| 26 | +then |
| 27 | + if [ -n "${PR_NUM}" ] |
| 28 | + then |
| 29 | + # Use Issues api instead of PR api because |
| 30 | + # PR api requires comments be made on specific files of specific commits |
| 31 | + GITHUB_PR_COMMENTS="https://api.github.com/repos/${USERNAME}/${REPONAME}/issues/${PR_NUM}/comments" |
| 32 | + COMMENT=$(git log --author="patternfly-build" -1 --pretty=%B | tail -n +2 | python -c 'import json,sys; print(json.dumps(sys.stdin.read()))' | cut -d '"' -f 2) |
| 33 | + JSON="{\"body\":\"Your changes have been released in: ${COMMENT}Thanks for your contribution! :tada:\"}" |
| 34 | + echo "Adding github PR comment ${GITHUB_PR_COMMENTS} ${JSON}" |
| 35 | + curl -H "Authorization: token ${GH_PR_TOKEN}" --request POST "${GITHUB_PR_COMMENTS}" --data "${JSON}" |
| 36 | + fi |
| 37 | +else |
| 38 | + echo "Failed lerna publish" |
| 39 | + exit 1 |
| 40 | +fi |
0 commit comments