@@ -10,49 +10,109 @@ VERSION="$1"
10
10
USER=" $2 "
11
11
TOKEN=" $3 "
12
12
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
+
13
25
if [ -z " $VERSION " ];
14
26
then
15
27
echo " Missing version" >&2
28
+ usage
16
29
exit 1
17
30
fi
18
31
19
32
if [ -z " $USER " ];
20
33
then
21
34
echo " Missing github user" >&2
35
+ usage
22
36
exit 1
23
37
fi
24
38
25
39
if [ -z " $TOKEN " ];
26
40
then
27
41
echo " Missing github token" >&2
42
+ usage
28
43
exit 1
29
44
fi
30
45
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
+
31
86
cd /tmp
32
- mkdir -p php-ovh -bin
33
- cd php-ovh -bin
87
+ mkdir -p ${PROJECT_NAME} -bin
88
+ cd ${PROJECT_NAME} -bin
34
89
35
90
curl -sS https://getcomposer.org/installer | php
36
91
37
- echo ' {
92
+ # FIXME: this will require the release to already be uploaded on packagist.org
93
+ cat > composer.json << EOF
94
+ {
38
95
"name": "Example Application",
39
96
"description": "This is an example of OVH APIs wrapper usage",
40
97
"require": {
41
- "ovh/ovh": "2.x "
98
+ "ovh/ovh": "${VERSION} "
42
99
}
43
- }' > composer.json
100
+ }
101
+ EOF
44
102
45
103
php composer.phar install
46
104
47
- echo ' <?php
105
+ cat > script.php << EOF
106
+ <?php
48
107
require __DIR__ . "/vendor/autoload.php";
49
108
use \Ovh\Api;
50
109
51
110
// 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";
56
116
57
117
// Get servers list
58
118
$conn = new Api( $applicationKey ,
@@ -67,14 +127,17 @@ try {
67
127
68
128
} catch ( Exception $ex ) {
69
129
print_r( $ex ->getMessage() );
70
- }' > script.php
130
+ }
131
+ EOF
132
+
71
133
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 ' )
73
135
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
75
139
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
78
143
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