2019-07-18 07:51:47 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -x
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-03-15 12:24:37 +01:00
|
|
|
function print_flask_version ()
|
|
|
|
{
|
|
|
|
local flask_filename
|
|
|
|
flask_filename="$(find ./builds-flask -type f -name 'metamask-flask-chrome-*.zip' -exec basename {} .zip \;)"
|
|
|
|
|
|
|
|
local flask_build_filename_prefix
|
|
|
|
flask_build_filename_prefix='metamask-flask-chrome-'
|
|
|
|
local flask_build_filename_prefix_size
|
|
|
|
flask_build_filename_prefix_size="${#flask_build_filename_prefix}"
|
|
|
|
|
|
|
|
# Use substring parameter expansion to remove the filename prefix, leaving just the version
|
|
|
|
echo "${flask_filename:$flask_build_filename_prefix_size}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function publish_flask_tag ()
|
|
|
|
{
|
|
|
|
local flask_version="${1}"; shift
|
|
|
|
|
|
|
|
git config user.email "metamaskbot@users.noreply.github.com"
|
|
|
|
git config user.name "MetaMask Bot"
|
|
|
|
git tag -a "v${flask_version}" -m "Flask version ${flask_version}"
|
|
|
|
repo_slug="$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME"
|
|
|
|
git push "https://$GITHUB_TOKEN@github.com/$repo_slug" "v${flask_version}"
|
|
|
|
}
|
|
|
|
|
2019-07-18 07:51:47 +02:00
|
|
|
current_commit_msg=$(git show -s --format='%s' HEAD)
|
|
|
|
|
2019-09-11 16:44:36 +02:00
|
|
|
if [[ $current_commit_msg =~ Version[-[:space:]](v[[:digit:]]+.[[:digit:]]+.[[:digit:]]+) ]]
|
2019-07-18 07:51:47 +02:00
|
|
|
then
|
2019-09-11 16:44:36 +02:00
|
|
|
tag="${BASH_REMATCH[1]}"
|
2022-03-15 12:24:37 +01:00
|
|
|
flask_version="$(print_flask_version)"
|
2019-09-11 16:44:36 +02:00
|
|
|
|
2019-07-18 07:51:47 +02:00
|
|
|
install_github_cli
|
|
|
|
|
|
|
|
printf '%s\n' 'Creating GitHub Release'
|
|
|
|
release_body="$(awk -v version="${tag##v}" -f .circleci/scripts/show-changelog.awk CHANGELOG.md)"
|
2022-03-15 12:24:37 +01:00
|
|
|
hub release create \
|
|
|
|
--attach builds/metamask-chrome-*.zip \
|
|
|
|
--attach builds/metamask-firefox-*.zip \
|
|
|
|
--attach builds-flask/metamask-flask-chrome-*.zip \
|
|
|
|
--attach builds-flask/metamask-flask-firefox-*.zip \
|
|
|
|
--message "Version ${tag##v}" \
|
|
|
|
--message "$release_body" \
|
|
|
|
--commitish "$CIRCLE_SHA1" \
|
|
|
|
"$tag"
|
|
|
|
|
|
|
|
publish_flask_tag "${flask_version}"
|
2019-07-18 07:51:47 +02:00
|
|
|
else
|
2019-09-11 16:44:36 +02:00
|
|
|
printf '%s\n' 'Version not found in commit message; skipping GitHub Release'
|
2019-07-18 07:51:47 +02:00
|
|
|
exit 0
|
|
|
|
fi
|