Skip to content

Commit

Permalink
Update release script. Non-interactively make draft release (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgilmour authored May 15, 2020
1 parent 752c666 commit e5559a5
Showing 1 changed file with 43 additions and 54 deletions.
97 changes: 43 additions & 54 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
#!/bin/bash
set -e

IS_PRERELEASE=true

if [[ ! $- == *i* ]]
then
echo "Warning: this is an interactive script"
if [[ $# != 1 ]]; then
echo "Missing parameter for version number"
exit 1
fi
VERSION="$1"

if [[ -z $CIRCLE_CI_TOKEN ]]
then
if [[ -z $CIRCLE_CI_TOKEN ]]; then
echo "Please provide a CircleCI API token in \$CIRCLE_CI_TOKEN"
exit 1
fi

if [[ -z $GITHUB_TOKEN ]]
then
if [[ -z $GITHUB_TOKEN ]]; then
echo "Please provide a Github personal access token in \$GITHUB_TOKEN"
exit 1
fi

if [[ -z $GOPATH ]]
then
if [[ -z $GOPATH ]]; then
echo "Please install Golang"
exit 1
fi

if ! [[ -f "$GOPATH/bin/hub" ]]
then
if ! [[ -f "$GOPATH/bin/hub" ]]; then
echo "Installing required tool Github 'hub'"
go get github.com/github/hub
fi
Expand All @@ -36,52 +31,48 @@ echo "Note: Make sure that you can sign commits on this machine with your GPG ke
echo "https://help.github.com/articles/signing-commits/"
echo ""

read -p "Creating a release off \"$(git symbolic-ref --short HEAD)\", is this correct? [Y/n] " Y
if ! [[ -z $Y || $Y == "y" || $Y == "Y" ]]
then
exit 0
if [[ $(git symbolic-ref --short HEAD) != "master" ]]; then
echo "Release should be created from master branch"
exit 1
fi

read -p "Enter release version (eg v1.2.3 or test-myfeature) " VERSION
if [[ -z $VERSION ]]
then
if [[ -z $VERSION ]]; then
echo "Please enter a version"
exit 1
elif [[ -n $(git ls-remote --tags origin $VERSION) ]]
then
Y=
read -p "The tag $VERSION already exists, continue with release using this tag? [Y/n] " Y
if ! [[ -z $Y || $Y == "y" || $Y == "Y" ]]
then
exit 0
fi
else
read -p "Press enter to edit git tag description " Y
git tag -s $VERSION
git push origin $VERSION
elif [[ -n $(git ls-remote --tags origin "$VERSION") ]]; then
echo "The tag $VERSION already exists"
exit 1
fi

echo "Waiting on CircleCI build..."

# Start a build job on CircleCI
BUILD_NUM=$(curl -s -X POST --header "Content-Type: application/json" -d '{
"tag": "'$VERSION'",
"build_parameters": {
"BUILD_ALL_NGINX_VERSIONS": "1"
}
BUILD_REPLY=$(curl -s -X POST --header "Content-Type: application/json" -d '{
"revision": "'"$(git rev-parse HEAD)"'"
}
' https://circleci.com/api/v1.1/project/github/DataDog/dd-opentracing-cpp?circle-token=${CIRCLE_CI_TOKEN} | jq '.build_num')
' "https://circleci.com/api/v1.1/project/github/DataDog/dd-opentracing-cpp?circle-token=${CIRCLE_CI_TOKEN}")

BUILD_NUM=$(jq '.build_num' <<< "$BUILD_REPLY")

# Wait for CircleCI build job to finish
while : ; do
BUILD_RESULT=$(curl -s https://circleci.com/api/v1.1/project/github/DataDog/dd-opentracing-cpp/${BUILD_NUM}?circle-token=${CIRCLE_CI_TOKEN})
STATUS=$(echo $BUILD_RESULT | jq -r '.status')
while :; do
BUILD_RESULT=$(curl -s "https://circleci.com/api/v1.1/project/github/DataDog/dd-opentracing-cpp/${BUILD_NUM}?circle-token=${CIRCLE_CI_TOKEN}")
STATUS=$(jq -r '.status' <<<"$BUILD_RESULT")

case $STATUS in
canceled|infrastructure_fail|timedout|not_run|failed|no_tests) echo "Failed with status: ${STATUS}" && exit 1 ;;
fixed|success) break ;;
retried|running|queued|scheduled|not_running) ;; # Sleep and try again.
*) echo "Unknown status: ${STATUS}" && exit 1 ;;
canceled | infrastructure_fail | timedout | not_run | failed | no_tests)
echo "Failed with status: ${STATUS}"
exit 1
;;
fixed | success)
break
;;
retried | running | queued | scheduled | not_running) ;;
# Sleep and try again.
*)
echo "Unknown status: ${STATUS}"
exit 1
;;
esac

echo "Waiting on CI, current status: ${STATUS}"
Expand All @@ -90,16 +81,15 @@ done

# Download artifacts
echo "Build status \"$STATUS\", downloading artifacts..."
ARTIFACT_URLS=$(curl -s https://circleci.com/api/v1.1/project/github/DataDog/dd-opentracing-cpp/${BUILD_NUM}/artifacts?circle-token=${CIRCLE_CI_TOKEN} | jq -r '.[] | .url')
ARTIFACT_URLS=$(curl -s "https://circleci.com/api/v1.1/project/github/DataDog/dd-opentracing-cpp/${BUILD_NUM}/artifacts?circle-token=${CIRCLE_CI_TOKEN}" | jq -r '.[] | .url')

rm -rf .bin
mkdir .bin
cd .bin
echo "${ARTIFACT_URLS}" | while read ARTIFACT_URL
do
echo "Downloading artifact: ${ARTIFACT_URL}"
curl -s -O ${ARTIFACT_URL}
done
while read ARTIFACT_URL; do
echo "Downloading artifact: ${ARTIFACT_URL}"
curl -s -O "${ARTIFACT_URL}"
done <<<"$ARTIFACT_URLS"

# Process and sign artifacts
gzip libdd_opentracing_plugin.so
Expand All @@ -115,10 +105,9 @@ for f in ./*; do
done

# Create a github release
PRERELEASE=$([ $IS_PRERELEASE = true ] && echo "-p" || echo "")
$GOPATH/bin/hub release create $PRERELEASE \
"$GOPATH/bin/hub" release create --draft \
"${assets[@]}" \
-m "Release $VERSION" $VERSION
-m "Release $VERSION" "$VERSION"
cd ..
rm -rf .bin

Expand Down

0 comments on commit e5559a5

Please sign in to comment.