Skip to content

Commit 1753296

Browse files
authored
Merge pull request #45 from ovh/jt-script
script: update release script
2 parents c3c860e + 79ee4e4 commit 1753296

File tree

2 files changed

+80
-17
lines changed

2 files changed

+80
-17
lines changed

scripts/bump-version.sh

100644100755
File mode changed.

scripts/release_binary.sh

Lines changed: 80 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,109 @@ VERSION="$1"
1010
USER="$2"
1111
TOKEN="$3"
1212

13+
function usage() {
14+
echo "Usage: $0 <version> <githubUser> <githubToken>"
15+
echo "Hint: "
16+
echo " - Make sure there is outstanding changes in the current directory"
17+
echo " - Make sure the requested version does not exist yet"
18+
echo " - You may visit https://help.github.com/articles/creating-an-access-token-for-command-line-use/ to generate your Github Token"
19+
}
20+
21+
#
22+
# Validate input
23+
#
24+
1325
if [ -z "$VERSION" ];
1426
then
1527
echo "Missing version" >&2
28+
usage
1629
exit 1
1730
fi
1831

1932
if [ -z "$USER" ];
2033
then
2134
echo "Missing github user" >&2
35+
usage
2236
exit 1
2337
fi
2438

2539
if [ -z "$TOKEN" ];
2640
then
2741
echo "Missing github token" >&2
42+
usage
2843
exit 1
2944
fi
3045

46+
#
47+
# Validate repository
48+
#
49+
50+
if [ -n "$(git status --porcelain)" ]
51+
then
52+
echo "Working repository is not clean. Please commit or stage any pending changes." >&2
53+
usage
54+
exit 1
55+
fi
56+
57+
CURRENTTAG=$(git describe --tag --exact-match 2>/dev/null || echo "")
58+
if [ "${CURRENTTAG}" != "${VERSION}" ]
59+
then
60+
if [ -n "${CURRENTTAG}" ]
61+
then
62+
echo "The current commit is already tagged with ${CURRENTTAG} which is not the requested release ${VERSION}" >&2
63+
usage
64+
exit 1
65+
fi
66+
67+
if git rev-parse refs/tags/${VERSION} &>/dev/null
68+
then
69+
echo "The requested version ${VERSION} already exists" >&2
70+
usage
71+
exit 1
72+
fi
73+
fi
74+
75+
#
76+
# Release
77+
#
78+
79+
PROJECT_NAME=$(git remote -v | grep 'github.*push' | awk '{split($2, a, "/"); split(a[2], b, "."); print b[1]}')
80+
echo "Releasing ${PROJECT_NAME} version ${VERSION}..."
81+
82+
git tag -m "Releasing ${PROJECT_NAME} version ${VERSION}" "${VERSION}"
83+
git push --tags
84+
git push
85+
3186
cd /tmp
32-
mkdir -p php-ovh-bin
33-
cd php-ovh-bin
87+
mkdir -p ${PROJECT_NAME}-bin
88+
cd ${PROJECT_NAME}-bin
3489

3590
curl -sS https://getcomposer.org/installer | php
3691

37-
echo '{
92+
# FIXME: this will require the release to already be uploaded on packagist.org
93+
cat > composer.json << EOF
94+
{
3895
"name": "Example Application",
3996
"description": "This is an example of OVH APIs wrapper usage",
4097
"require": {
41-
"ovh/ovh": "2.x"
98+
"ovh/ovh": "${VERSION}"
4299
}
43-
}' > composer.json
100+
}
101+
EOF
44102

45103
php composer.phar install
46104

47-
echo '<?php
105+
cat > script.php << EOF
106+
<?php
48107
require __DIR__ . "/vendor/autoload.php";
49108
use \Ovh\Api;
50109
51110
// Informations about your application
52-
$applicationKey = "your_app_key";
53-
$applicationSecret = "your_app_secret";
54-
$consumer_key = "your_consumer_key";
55-
$endpoint = 'ovh-eu';
111+
// You may create new credentials on https://api.ovh.com/createToken/index.cgi
112+
$applicationKey = "your_app_key";
113+
$applicationSecret = "your_app_secret";
114+
$consumer_key = "your_consumer_key";
115+
$endpoint = "ovh-eu";
56116
57117
// Get servers list
58118
$conn = new Api( $applicationKey,
@@ -67,14 +127,17 @@ try {
67127
68128
} catch ( Exception $ex ) {
69129
print_r( $ex->getMessage() );
70-
}' > script.php
130+
}
131+
EOF
132+
71133

72-
zip -r php-ovh-$VERSION-with-dependencies.zip .
134+
ID=$(curl https://api.github.com/repos/ovh/${PROJECT_NAME}/releases/tags/v${VERSION} -u "${USER}:${TOKEN}" | jq -r '.id')
73135

74-
ID=$(curl https://api.github.com/repos/ovh/php-ovh/releases/tags/v$VERSION -u $USER:$TOKEN | jq -r '.id')
136+
zip -r ${PROJECT_NAME}-${VERSION}-with-dependencies.zip .
137+
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}"
138+
rm ${PROJECT_NAME}-${VERSION}-with-dependencies.zip
75139

76-
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
77-
rm php-ovh-$VERSION-with-dependencies.zip
140+
tar -czf ${PROJECT_NAME}-${VERSION}-with-dependencies.tar.gz .
141+
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}"
142+
rm -f ${PROJECT_NAME}-${VERSION}-with-dependencies.tar.gz
78143

79-
tar -czf php-ovh-$VERSION-with-dependencies.tar.gz .
80-
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

0 commit comments

Comments
 (0)