From 79ee4e421ade64d7ec8abe44d7b5282d77e1f2ea Mon Sep 17 00:00:00 2001 From: Jean-Tiare Le Bigot Date: Thu, 7 Jul 2016 11:07:01 +0200 Subject: [PATCH] script: update release script Signed-off-by: Jean-Tiare Le Bigot --- scripts/bump-version.sh | 0 scripts/release_binary.sh | 97 ++++++++++++++++++++++++++++++++------- 2 files changed, 80 insertions(+), 17 deletions(-) mode change 100644 => 100755 scripts/bump-version.sh diff --git a/scripts/bump-version.sh b/scripts/bump-version.sh old mode 100644 new mode 100755 diff --git a/scripts/release_binary.sh b/scripts/release_binary.sh index d03f673..d2a6699 100755 --- a/scripts/release_binary.sh +++ b/scripts/release_binary.sh @@ -10,49 +10,109 @@ VERSION="$1" USER="$2" TOKEN="$3" +function usage() { + echo "Usage: $0 " + echo "Hint: " + echo " - Make sure there is outstanding changes in the current directory" + echo " - Make sure the requested version does not exist yet" + echo " - You may visit https://help.github.com/articles/creating-an-access-token-for-command-line-use/ to generate your Github Token" +} + +# +# Validate input +# + if [ -z "$VERSION" ]; then echo "Missing version" >&2 + usage exit 1 fi if [ -z "$USER" ]; then echo "Missing github user" >&2 + usage exit 1 fi if [ -z "$TOKEN" ]; then echo "Missing github token" >&2 + usage exit 1 fi +# +# Validate repository +# + +if [ -n "$(git status --porcelain)" ] +then + echo "Working repository is not clean. Please commit or stage any pending changes." >&2 + usage + exit 1 +fi + +CURRENTTAG=$(git describe --tag --exact-match 2>/dev/null || echo "") +if [ "${CURRENTTAG}" != "${VERSION}" ] +then + if [ -n "${CURRENTTAG}" ] + then + echo "The current commit is already tagged with ${CURRENTTAG} which is not the requested release ${VERSION}" >&2 + usage + exit 1 + fi + + if git rev-parse refs/tags/${VERSION} &>/dev/null + then + echo "The requested version ${VERSION} already exists" >&2 + usage + exit 1 + fi +fi + +# +# Release +# + +PROJECT_NAME=$(git remote -v | grep 'github.*push' | awk '{split($2, a, "/"); split(a[2], b, "."); print b[1]}') +echo "Releasing ${PROJECT_NAME} version ${VERSION}..." + +git tag -m "Releasing ${PROJECT_NAME} version ${VERSION}" "${VERSION}" +git push --tags +git push + cd /tmp -mkdir -p php-ovh-bin -cd php-ovh-bin +mkdir -p ${PROJECT_NAME}-bin +cd ${PROJECT_NAME}-bin curl -sS https://getcomposer.org/installer | php -echo '{ +# FIXME: this will require the release to already be uploaded on packagist.org +cat > composer.json << EOF +{ "name": "Example Application", "description": "This is an example of OVH APIs wrapper usage", "require": { - "ovh/ovh": "2.x" + "ovh/ovh": "${VERSION}" } -}' > composer.json +} +EOF php composer.phar install -echo ' script.php << EOF +getMessage() ); -}' > script.php +} +EOF -zip -r php-ovh-$VERSION-with-dependencies.zip . -ID=$(curl https://api.github.com/repos/ovh/php-ovh/releases/tags/v$VERSION -u $USER:$TOKEN | jq -r '.id') +ID=$(curl https://api.github.com/repos/ovh/${PROJECT_NAME}/releases/tags/v${VERSION} -u "${USER}:${TOKEN}" | jq -r '.id') -curl -X POST -d @php-ovh-$VERSION-with-dependencies.zip -H "Content-Type: application/zip" https://uploads.github.com/repos/ovh/php-ovh/releases/$ID/assets?name=php-ovh-$VERSION-with-dependencies.zip -i -u $USER:$TOKEN -rm php-ovh-$VERSION-with-dependencies.zip +zip -r ${PROJECT_NAME}-${VERSION}-with-dependencies.zip . +curl -X POST -d @${PROJECT_NAME}-${VERSION}-with-dependencies.zip -H "Content-Type: application/zip" "https://uploads.github.com/repos/ovh/${PROJECT_NAME}/releases/${ID}/assets?name=${PROJECT_NAME}-${VERSION}-with-dependencies.zip" -i -u "${USER}:${TOKEN}" +rm ${PROJECT_NAME}-${VERSION}-with-dependencies.zip + +tar -czf ${PROJECT_NAME}-${VERSION}-with-dependencies.tar.gz . +curl -X POST -d @${PROJECT_NAME}-${VERSION}-with-dependencies.tar.gz -H "Content-Type: application/gzip" "https://uploads.github.com/repos/ovh/${PROJECT_NAME}/releases/${ID}/assets?name=${PROJECT_NAME}-${VERSION}-with-dependencies.tar.gz" -i -u "${USER}:${TOKEN}" +rm -f ${PROJECT_NAME}-${VERSION}-with-dependencies.tar.gz -tar -czf php-ovh-$VERSION-with-dependencies.tar.gz . -curl -X POST -d @php-ovh-$VERSION-with-dependencies.tar.gz -H "Content-Type: application/zip" https://uploads.github.com/repos/ovh/php-ovh/releases/$ID/assets?name=php-ovh-$VERSION-with-dependencies.tar.gz -i -u $USER:$TOKEN