@@ -28,14 +28,16 @@ import TEXT from './text';
2828
2929dotenv . config ( { path : ROOT_ENV_PATH } ) ;
3030
31- type BeforeCommitCommand = ( params : {
31+ type BeforeClientGenerationCommand = ( params : {
3232 releaseType : ReleaseType ;
33- tempGitDir : string ;
33+ dir : string ;
3434} ) => Promise < void > ;
3535
36- const BEFORE_RELEASE_COMMIT : { [ lang : string ] : BeforeCommitCommand } = {
37- javascript : async ( { releaseType, tempGitDir } ) => {
38- await run ( `yarn release:bump_non_gen ${ releaseType } ` , { cwd : tempGitDir } ) ;
36+ const BEFORE_CLIENT_GENERATION : {
37+ [ lang : string ] : BeforeClientGenerationCommand ;
38+ } = {
39+ javascript : async ( { releaseType, dir } ) => {
40+ await run ( `yarn release:bump ${ releaseType } ` , { cwd : dir } ) ;
3941 } ,
4042} ;
4143
@@ -73,6 +75,11 @@ export function getVersionsToRelease(issueBody: string): VersionsToRelease {
7375 return ;
7476 }
7577 const [ , lang , current , releaseType ] = result ;
78+ if ( ! [ 'major' , 'minor' , 'patch' , 'prerelease' ] . includes ( releaseType ) ) {
79+ throw new Error (
80+ `\`${ releaseType } \` is unknown release type. Allowed: major, minor, patch, prerelease`
81+ ) ;
82+ }
7683 versionsToRelease [ lang ] = {
7784 current,
7885 releaseType : releaseType as ReleaseType ,
@@ -127,6 +134,40 @@ async function configureGitHubAuthor(cwd?: string): Promise<void> {
127134 } ) ;
128135}
129136
137+ async function updateChangelog ( {
138+ lang,
139+ issueBody,
140+ current,
141+ next,
142+ dateStamp,
143+ willReleaseLibrary,
144+ } : {
145+ lang : string ;
146+ issueBody : string ;
147+ current : string ;
148+ next : string ;
149+ dateStamp : string ;
150+ willReleaseLibrary : boolean ;
151+ } ) : Promise < void > {
152+ const changelogPath = toAbsolutePath (
153+ `${ getLanguageFolder ( lang ) } /CHANGELOG.md`
154+ ) ;
155+ const existingContent = ( await exists ( changelogPath ) )
156+ ? ( await fsp . readFile ( changelogPath ) ) . toString ( )
157+ : '' ;
158+ const changelogHeader = willReleaseLibrary
159+ ? `## [v${ next } ](${ getGitHubUrl ( lang ) } /compare/v${ current } ...v${ next } )`
160+ : `## ${ dateStamp } ` ;
161+ const newChangelog = getMarkdownSection (
162+ getMarkdownSection ( issueBody , TEXT . changelogHeader ) ,
163+ `### ${ lang } `
164+ ) ;
165+ await fsp . writeFile (
166+ changelogPath ,
167+ [ changelogHeader , newChangelog , existingContent ] . join ( '\n\n' )
168+ ) ;
169+ }
170+
130171async function processRelease ( ) : Promise < void > {
131172 if ( ! process . env . GITHUB_TOKEN ) {
132173 throw new Error ( 'Environment variable `GITHUB_TOKEN` does not exist.' ) ;
@@ -151,11 +192,6 @@ async function processRelease(): Promise<void> {
151192
152193 await updateOpenApiTools ( versionsToRelease ) ;
153194
154- await configureGitHubAuthor ( ) ;
155-
156- // commit openapitools and changelogs
157- await run ( 'git add openapitools.json' ) ;
158-
159195 const langsToReleaseOrUpdate = [
160196 ...Object . keys ( versionsToRelease ) ,
161197 ...langsToUpdateRepo ,
@@ -165,32 +201,36 @@ async function processRelease(): Promise<void> {
165201 Boolean ( versionsToRelease [ lang ] ) ;
166202
167203 for ( const lang of langsToReleaseOrUpdate ) {
168- // prepare the submodule
204+ const { current, releaseType, dateStamp } = versionsToRelease [ lang ] ;
205+ /*
206+ About bumping versions of JS clients:
207+
208+ There are generated clients in JS repo, and non-generated clients like `algoliasearch`, `client-common`, etc.
209+ Now that the versions of generated clients are updated in `openapitools.json`,
210+ the generation output will have correct new versions.
211+
212+ However, we need to manually update versions of the non-generated (a.k.a. manually written) clients.
213+ In order to do that, we run `yarn release:bump <releaseType>` in this monorepo first.
214+ It will update the versions of the non-generated clients which exists in this monorepo.
215+ After that, we generate clients with new versions. And then, we copy all of them over to JS repository.
216+ */
217+ await BEFORE_CLIENT_GENERATION [ lang ] ?.( {
218+ releaseType,
219+ dir : toAbsolutePath ( getLanguageFolder ( lang ) ) ,
220+ } ) ;
221+
169222 console . log ( `Generating ${ lang } client(s)...` ) ;
170223 console . log ( await run ( `yarn cli generate ${ lang } ` ) ) ;
171224
172- const { current, releaseType, dateStamp } = versionsToRelease [ lang ] ;
173225 const next = semver . inc ( current , releaseType ) ;
174- // update changelog
175- const changelogPath = toAbsolutePath (
176- `${ getLanguageFolder ( lang ) } /CHANGELOG.md`
177- ) ;
178- const existingContent = ( await exists ( changelogPath ) )
179- ? ( await fsp . readFile ( changelogPath ) ) . toString ( )
180- : '' ;
181- const changelogHeader = willReleaseLibrary ( lang )
182- ? `## [v${ next } ](${ getGitHubUrl ( lang ) } /compare/v${ current } ...v${ next } )`
183- : `## ${ dateStamp } ` ;
184- const newChangelog = getMarkdownSection (
185- getMarkdownSection ( issueBody , TEXT . changelogHeader ) ,
186- `### ${ lang } `
187- ) ;
188- await fsp . writeFile (
189- changelogPath ,
190- [ changelogHeader , newChangelog , existingContent ] . join ( '\n\n' )
191- ) ;
192-
193- await run ( `git add ${ changelogPath } ` ) ;
226+ await updateChangelog ( {
227+ lang,
228+ issueBody,
229+ current,
230+ next : next ! ,
231+ dateStamp,
232+ willReleaseLibrary : willReleaseLibrary ( lang ) ,
233+ } ) ;
194234 }
195235
196236 // We push commits from submodules AFTER all the generations are done.
@@ -214,9 +254,6 @@ async function processRelease(): Promise<void> {
214254 const next = semver . inc ( current , releaseType ) ;
215255
216256 if ( willReleaseLibrary ( lang ) ) {
217- // TODO: most of generated clients already have the new versions in package.json
218- // how can I avoid double-bump versions???
219- await BEFORE_RELEASE_COMMIT [ lang ] ?.( { releaseType, tempGitDir } ) ;
220257 await execa ( 'git' , [ 'commit' , '-m' , `chore: release ${ next } ` ] , {
221258 cwd : tempGitDir ,
222259 } ) ;
@@ -233,6 +270,8 @@ async function processRelease(): Promise<void> {
233270 }
234271
235272 // Commit and push from the monorepo level.
273+ await configureGitHubAuthor ( ) ;
274+ await run ( `git add .` ) ;
236275 await execa ( 'git' , [ 'commit' , '-m' , `chore: release ${ getDateStamp ( ) } ` ] ) ;
237276 await run ( `git push` ) ;
238277
0 commit comments