@@ -109,9 +109,8 @@ public function delegate()
109109 try {
110110 $ this ->getContext ();
111111 $ this ->checkPrerequisites ();
112- $ this ->info ( sprintf ( ' Create release %s. ' , $ this -> releaseTag ) );
112+ $ this ->getReleaseTag ( );
113113 $ this ->updateReadme ();
114- $ this ->checkPostConditions ();
115114 $ this ->createCommit ();
116115 } catch (Exception $ exception ) {
117116 $ this ->error ($ exception ->getMessage ());
@@ -132,7 +131,6 @@ protected function getContext()
132131 {
133132 $ this ->branch = $ this ->git ->getBranch ();
134133 $ this ->tag = $ this ->git ->getTag ();
135- $ this ->releaseTag = $ this ->semanticVersioning ->getNextReleaseTag ($ this ->tag , $ this ->releaseType );
136134 }
137135
138136 /**
@@ -157,6 +155,12 @@ protected function checkPrerequisites()
157155 }
158156 }
159157
158+ protected function getReleaseTag ()
159+ {
160+ $ this ->releaseTag = $ this ->semanticVersioning ->getNextReleaseTag ($ this ->tag , $ this ->releaseType );
161+ $ this ->info (sprintf ('Create release %s. ' , $ this ->releaseTag ));
162+ }
163+
160164 /**
161165 * @throws Exception
162166 *
@@ -173,29 +177,33 @@ protected function updateReadme()
173177
174178 $ readme = file ($ this ->readmeFile );
175179 $ readmeContent = '' ;
180+ $ readmeState = 0 ;
176181 foreach ($ readme as $ line ) {
177182 if (strpos ($ line , "Version $ this ->tag " ) === 0 ) {
178183 $ readmeContent .= str_replace ($ this ->tag , $ this ->releaseTag , $ line );
184+ $ readmeState += 1 ;
179185 } elseif (strpos ($ line , $ this ->tag ) === 0 ) {
180186 $ readmeContent .= str_replace ($ this ->tag , "$ changelog \n$ this ->tag " , $ line );
187+ $ readmeState += 2 ;
181188 } else {
182189 $ readmeContent .= $ line ;
183190 }
184191 }
185192 file_put_contents ($ this ->readmeFile , $ readmeContent );
186- }
187193
188- /**
189- * @throws Exception
190- *
191- * @return void
192- */
193- protected function checkPostConditions ()
194- {
195- if ($ this ->git ->hasCleanWorkingTree ()) {
196- throw new Exception (
197- 'Could not update README.md. The format has probably changed. '
198- );
194+ if ($ readmeState < 3 ) {
195+ if (!($ readmeState & 1 )) {
196+ $ errors [] = sprintf ("Missing note 'Version %s' of the last release below the title. " , $ this ->tag );
197+ }
198+ if (!($ readmeState & 2 )) {
199+ $ errors [] = sprintf ("Missing changelog entry '%s: ..' from the last release. " , $ this ->tag );
200+ }
201+ if (isset ($ errors )) {
202+ throw new Exception (sprintf (
203+ "Could not update README.md. The format has probably changed: \n%s " ,
204+ json_encode ($ errors , JSON_PRETTY_PRINT )
205+ ));
206+ }
199207 }
200208 }
201209
0 commit comments