10
10
use Yii ;
11
11
use yii \base \Exception ;
12
12
use yii \console \Controller ;
13
+ use yii \helpers \ArrayHelper ;
13
14
14
15
/**
15
16
* ReleaseController is there to help preparing releases
@@ -25,49 +26,54 @@ class ReleaseController extends Controller
25
26
* Usage:
26
27
*
27
28
* ```
28
- * ./build/build release/prepare 2.0.0-beta
29
+ * ./build/build release/prepare framework 2.0.0-beta
30
+ * ./build/build release/prepare redis 2.0.0-beta
29
31
* ```
30
32
*
31
33
*/
32
- public function actionPrepare ($ version )
34
+ public function actionPrepare (array $ what , $ version )
33
35
{
34
- $ this ->resortChangelogs ($ version );
35
- $ this ->mergeChangelogs ($ version );
36
- $ this ->closeChangelogs ($ version );
37
- $ this ->composerSetStability ($ version );
38
- $ this ->updateYiiVersion ($ version );
36
+ $ this ->resortChangelogs ($ what , $ version );
37
+ $ this ->closeChangelogs ($ what , $ version );
38
+ $ this ->composerSetStability ($ what , $ version );
39
+ if (in_array ('framework ' , $ what )) {
40
+ $ this ->updateYiiVersion ($ version );
41
+ }
39
42
}
40
43
41
44
/**
42
45
* Usage:
43
46
*
44
47
* ```
45
- * ./build/build release/done 2.0.0-dev 2.0.0-rc
48
+ * ./build/build release/done framework 2.0.0-dev 2.0.0-rc
49
+ * ./build/build release/done redis 2.0.0-dev 2.0.0-rc
46
50
* ```
47
51
*/
48
- public function actionDone ($ devVersion , $ nextVersion )
52
+ public function actionDone (array $ what , $ devVersion , $ nextVersion )
49
53
{
50
- $ this ->openChangelogs ($ nextVersion );
51
- $ this ->composerSetStability ('dev ' );
52
- $ this ->updateYiiVersion ($ devVersion );
54
+ $ this ->openChangelogs ($ what , $ nextVersion );
55
+ $ this ->composerSetStability ($ what , 'dev ' );
56
+ if (in_array ('framework ' , $ what )) {
57
+ $ this ->updateYiiVersion ($ devVersion );
58
+ }
53
59
}
54
60
55
- protected function closeChangelogs ($ version )
61
+ protected function closeChangelogs ($ what , $ version )
56
62
{
57
63
$ v = str_replace ('\\- ' , '[ \\- ] ' , preg_quote ($ version , '/ ' ));
58
64
$ headline = $ version . ' ' . date ('F d, Y ' );
59
65
$ this ->sed (
60
66
'/ ' .$ v .' under development\n(-+?)\n/ ' ,
61
67
$ headline . "\n" . str_repeat ('- ' , strlen ($ headline )) . "\n" ,
62
- $ this ->getChangelogs ()
68
+ $ this ->getChangelogs ($ what )
63
69
);
64
70
}
65
71
66
- protected function openChangelogs ($ version )
72
+ protected function openChangelogs ($ what , $ version )
67
73
{
68
74
$ headline = "\n$ version under development \n" ;
69
75
$ headline .= str_repeat ('- ' , strlen ($ headline ) - 2 ) . "\n\n" ;
70
- foreach ($ this ->getChangelogs () as $ file ) {
76
+ foreach ($ this ->getChangelogs ($ what ) as $ file ) {
71
77
$ lines = explode ("\n" , file_get_contents ($ file ));
72
78
$ hl = [
73
79
array_shift ($ lines ),
@@ -79,41 +85,16 @@ protected function openChangelogs($version)
79
85
}
80
86
}
81
87
82
- protected function resortChangelogs ($ version )
88
+ protected function resortChangelogs ($ what , $ version )
83
89
{
84
- foreach ($ this ->getChangelogs () as $ file ) {
90
+ foreach ($ this ->getChangelogs ($ what ) as $ file ) {
85
91
// split the file into relevant parts
86
92
list ($ start , $ changelog , $ end ) = $ this ->splitChangelog ($ file , $ version );
87
93
$ changelog = $ this ->resortChangelog ($ changelog );
88
94
file_put_contents ($ file , implode ("\n" , array_merge ($ start , $ changelog , $ end )));
89
95
}
90
96
}
91
97
92
- protected function mergeChangelogs ($ version )
93
- {
94
- $ file = $ this ->getFrameworkChangelog ();
95
- // split the file into relevant parts
96
- list ($ start , $ changelog , $ end ) = $ this ->splitChangelog ($ file , $ version );
97
-
98
- $ changelog = $ this ->resortChangelog ($ changelog );
99
-
100
- $ changelog [] = '' ;
101
- $ extensions = $ this ->getExtensionChangelogs ();
102
- asort ($ extensions );
103
- foreach ($ extensions as $ changelogFile ) {
104
- if (!preg_match ('~extensions/([a-z]+)/CHANGELOG \\.md~ ' , $ changelogFile , $ m )) {
105
- throw new Exception ("Illegal extension changelog file: " . $ changelogFile );
106
- }
107
- list ( , $ extensionChangelog , ) = $ this ->splitChangelog ($ changelogFile , $ version );
108
- $ name = $ m [1 ];
109
- $ ucname = ucfirst ($ name );
110
- $ changelog [] = "### $ ucname Extension (yii2- $ name) " ;
111
- $ changelog = array_merge ($ changelog , $ extensionChangelog );
112
- }
113
-
114
- file_put_contents ($ file , implode ("\n" , array_merge ($ start , $ changelog , $ end )));
115
- }
116
-
117
98
/**
118
99
* Extract changelog content for a specific version
119
100
*/
@@ -150,28 +131,69 @@ protected function resortChangelog($changelog)
150
131
foreach ($ changelog as $ i => $ line ) {
151
132
$ changelog [$ i ] = rtrim ($ line );
152
133
}
134
+ $ changelog = array_filter ($ changelog );
135
+
136
+ $ i = 0 ;
137
+ ArrayHelper::multisort ($ changelog , function ($ line ) use (&$ i ) {
138
+ if (preg_match ('/^- (Chg|Enh|Bug)( #\d+(, #\d+)*)?: .+$/ ' , $ line , $ m )) {
139
+ $ o = ['Bug ' => 'C ' , 'Enh ' => 'D ' , 'Chg ' => 'E ' ];
140
+ print_r ($ m );
141
+ return $ o [$ m [1 ]] . ' ' . (!empty ($ m [2 ]) ? $ m [2 ] : 'AAAA ' . $ i ++);
142
+ }
143
+ return 'B ' . $ i ++;
144
+ }, SORT_ASC , SORT_NATURAL );
145
+
146
+ // re-add leading and trailing lines
147
+ array_unshift ($ changelog , '' );
148
+ $ changelog [] = '' ;
149
+ $ changelog [] = '' ;
153
150
154
- // TODO sorting
155
151
return $ changelog ;
156
152
}
157
153
158
- protected function getChangelogs ()
154
+ protected function getChangelogs ($ what )
159
155
{
160
- return array_merge ([$ this ->getFrameworkChangelog ()], $ this ->getExtensionChangelogs ());
156
+ $ changelogs = [];
157
+ if (in_array ('framework ' , $ what )) {
158
+ $ changelogs [] = $ this ->getFrameworkChangelog ();
159
+ }
160
+
161
+ return array_merge ($ changelogs , $ this ->getExtensionChangelogs ($ what ));
161
162
}
162
163
163
164
protected function getFrameworkChangelog ()
164
165
{
165
166
return YII2_PATH . '/CHANGELOG.md ' ;
166
167
}
167
168
168
- protected function getExtensionChangelogs ()
169
+ protected function getExtensionChangelogs ($ what )
169
170
{
170
- return glob (dirname (YII2_PATH ) . '/extensions/*/CHANGELOG.md ' );
171
+ return array_filter (glob (dirname (YII2_PATH ) . '/extensions/*/CHANGELOG.md ' ), function ($ elem ) use ($ what ) {
172
+ foreach ($ what as $ ext ) {
173
+ if (strpos ($ elem , "extensions/ $ ext/CHANGELOG.md " ) !== false ) {
174
+ return true ;
175
+ }
176
+ }
177
+ return false ;
178
+ });
171
179
}
172
180
173
- protected function composerSetStability ($ version )
181
+ protected function composerSetStability ($ what , $ version )
174
182
{
183
+ $ apps = [];
184
+ if (in_array ('app-advanced ' , $ what )) {
185
+ $ apps [] = dirname (YII2_PATH ) . '/apps/advanced/composer.json ' ;
186
+ }
187
+ if (in_array ('app-basic ' , $ what )) {
188
+ $ apps [] = dirname (YII2_PATH ) . '/apps/basic/composer.json ' ;
189
+ }
190
+ if (in_array ('app-benchmark ' , $ what )) {
191
+ $ apps [] = dirname (YII2_PATH ) . '/apps/benchmark/composer.json ' ;
192
+ }
193
+ if (empty ($ apps )) {
194
+ return ;
195
+ }
196
+
175
197
$ stability = 'stable ' ;
176
198
if (strpos ($ version , 'alpha ' ) !== false ) {
177
199
$ stability = 'alpha ' ;
@@ -186,11 +208,7 @@ protected function composerSetStability($version)
186
208
$ this ->sed (
187
209
'/"minimum-stability": "(.+?)",/ ' ,
188
210
'"minimum-stability": " ' . $ stability . '", ' ,
189
- [
190
- dirname (YII2_PATH ) . '/apps/advanced/composer.json ' ,
191
- dirname (YII2_PATH ) . '/apps/basic/composer.json ' ,
192
- dirname (YII2_PATH ) . '/apps/benchmark/composer.json ' ,
193
- ]
211
+ $ apps
194
212
);
195
213
}
196
214
0 commit comments