2019-07-18 07:51:47 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -u
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
if [[ "${CI:-}" != 'true' ]]
|
|
|
|
then
|
|
|
|
printf '%s\n' 'CI environment variable must be set to true'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "${CIRCLECI:-}" != 'true' ]]
|
|
|
|
then
|
|
|
|
printf '%s\n' 'CIRCLECI environment variable must be set to true'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "${GITHUB_TOKEN:-}" ]]
|
|
|
|
then
|
|
|
|
printf '%s\n' 'GITHUB_TOKEN environment variable must be set'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
function install_github_cli ()
|
|
|
|
{
|
|
|
|
printf '%s\n' 'Installing hub CLI'
|
|
|
|
pushd "$(mktemp -d)"
|
|
|
|
curl -sSL 'https://github.com/github/hub/releases/download/v2.11.2/hub-linux-amd64-2.11.2.tgz' | tar xz
|
|
|
|
PATH="$PATH:$PWD/hub-linux-amd64-2.11.2/bin"
|
|
|
|
popd
|
|
|
|
}
|
|
|
|
|
|
|
|
version="${CIRCLE_BRANCH/Version-v/}"
|
2019-09-11 16:44:36 +02:00
|
|
|
base_branch='master'
|
2019-07-18 07:51:47 +02:00
|
|
|
|
|
|
|
if [[ -n "${CI_PULL_REQUEST:-}" ]]
|
|
|
|
then
|
|
|
|
printf '%s\n' 'CI_PULL_REQUEST is set, pull request already exists for this build'
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
install_github_cli
|
|
|
|
|
|
|
|
printf '%s\n' "Creating a Pull Request for $version on GitHub"
|
|
|
|
|
|
|
|
if ! hub pull-request \
|
2020-10-20 18:15:53 +02:00
|
|
|
--draft \
|
2019-07-18 07:51:47 +02:00
|
|
|
--message "${CIRCLE_BRANCH/-/ } RC" --message ':package: :rocket:' \
|
|
|
|
--base "$CIRCLE_PROJECT_USERNAME:$base_branch" \
|
|
|
|
--head "$CIRCLE_PROJECT_USERNAME:$CIRCLE_BRANCH";
|
|
|
|
then
|
|
|
|
printf '%s\n' 'Pull Request already exists'
|
|
|
|
fi
|