-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.php
162 lines (138 loc) · 4.83 KB
/
deploy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
define('SEMANTIC_VERSION_REGEX', '/^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/');
function increaseVersion($version, $mode) {
preg_match(SEMANTIC_VERSION_REGEX, $version, $versionComponents);
unset($versionComponents[0]);
switch ($mode) {
case 'patch':
$versionComponents[3]++;
break;
case 'minor':
$versionComponents[2]++;
$versionComponents[3] = 0;
break;
case 'major':
$versionComponents[1]++;
$versionComponents[2] = 0;
$versionComponents[3] = 0;
break;
}
return implode('.', $versionComponents);
}
function getComposerMetadata() {
$composerMetadata = json_decode(file_get_contents('composer.json'));
$composerMetadata->version = isset($composerMetadata->version) ? $composerMetadata->version : '0.0.0';
return $composerMetadata;
}
function getGithubCurl() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Release Script for ' . get('repository'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, get('username') . ':' . get('password'));
return $ch;
}
task('release:askPasswort', function(){
$password = askHiddenResponse('Passwort for ' . get('username') . ':');
set('password', $password);
});
task('release:increaseVersionPatch', function () {
$composerMetadata = getComposerMetadata();
$composerMetadata->version = increaseVersion($composerMetadata->version, 'patch');
set('version', $composerMetadata->version);
file_put_contents('composer.json', json_encode($composerMetadata, JSON_PRETTY_PRINT));
});
task('release:increaseVersionMinor', function () {
$composerMetadata = getComposerMetadata();
$composerMetadata->version = increaseVersion($composerMetadata->version, 'minor');
set('version', $composerMetadata->version);
file_put_contents('composer.json', json_encode($composerMetadata, JSON_PRETTY_PRINT));
});
task('release:increaseVersionMajor', function () {
$composerMetadata = getComposerMetadata();
$composerMetadata->version = increaseVersion($composerMetadata->version, 'major');
set('version', $composerMetadata->version);
file_put_contents('composer.json', json_encode($composerMetadata, JSON_PRETTY_PRINT));
});
task('release:fetchVersion', function () {
$composerMetadata = getComposerMetadata();
set('version', $composerMetadata->version);
});
task('release:commitComposer', function () {
// writeln('Update and commit version in composer.json');
runLocally('git add composer.json');
runLocally('git commit -m "' . get('version') . '"');
});
task('release:tagRelease', function () {
// writeln('tag current state with provided version number');
runLocally('git tag "' . get('version') . '"');
});
task('release:pushTags', function () {
// writeln('push tags to github');
runLocally('git push origin master');
runLocally('git push origin --tags');
});
task('release:removeCurrentTagFromRemote', function () {
runLocally('git tag -d "' . get('version') . '"');
runLocally('git push origin :refs/tags/' . get('version'));
});
task('release:createGithubRelease', function() {
$ch = getGithubCurl();
$release = array(
'tag_name' => get('version'),
'name' => 'Release: ' . get('version')
);
$uri = 'https://api.github.com/repos/' . get('repository') . '/releases';
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($release));
curl_setopt($ch, CURLOPT_POST, 1);
$release = json_decode(curl_exec($ch));
$releaseId = $release->id;
set('releaseId', $releaseId);
});
task('release:destroyGithubRelease', function() {
$ch = getGithubCurl();
$uri = 'https://api.github.com/repos/' . get('repository') . '/releases/tags/' . get('version');
curl_setopt($ch, CURLOPT_URL, $uri);
$release = json_decode(curl_exec($ch));
$releaseId = $release->id;
$uri = 'https://api.github.com/repos/' . get('repository') . '/releases/' . $releaseId;
$ch = getGithubCurl();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_exec($ch);
});
set('username', 'mneuhaus');
set('repository', 'mia3/koseki');
task('release:patch', [
'release:askPasswort',
'release:increaseVersionPatch',
'release:commitComposer',
'release:tagRelease',
'release:pushTags',
'release:createGithubRelease'
]);
task('release:minor', [
'release:askPasswort',
'release:increaseVersionMinor',
'release:commitComposer',
'release:tagRelease',
'release:pushTags',
'release:createGithubRelease'
]);
task('release:major', [
'release:askPasswort',
'release:increaseVersionMajor',
'release:commitComposer',
'release:tagRelease',
'release:pushTags',
'release:createGithubRelease'
]);
task('release:replaceCurrent', [
'release:askPasswort',
'release:fetchVersion',
'release:destroyGithubRelease',
'release:removeCurrentTagFromRemote',
'release:tagRelease',
'release:pushTags',
'release:createGithubRelease'
]);