@@ -5,20 +5,26 @@ import dotenv from 'dotenv';
5
5
import execa from 'execa' ;
6
6
7
7
import openapitools from '../../openapitools.json' ;
8
- import { toAbsolutePath , run , exists , getGitHubUrl } from '../common' ;
8
+ import {
9
+ ROOT_ENV_PATH ,
10
+ toAbsolutePath ,
11
+ run ,
12
+ exists ,
13
+ getGitHubUrl ,
14
+ } from '../common' ;
9
15
import { getLanguageFolder } from '../config' ;
10
16
11
17
import {
12
18
RELEASED_TAG ,
13
19
OWNER ,
14
20
REPO ,
15
21
getMarkdownSection ,
16
- getTargetBranch ,
17
22
getGitAuthor ,
23
+ getTargetBranch ,
18
24
} from './common' ;
19
25
import TEXT from './text' ;
20
26
21
- dotenv . config ( ) ;
27
+ dotenv . config ( { path : ROOT_ENV_PATH } ) ;
22
28
23
29
if ( ! process . env . GITHUB_TOKEN ) {
24
30
throw new Error ( 'Environment variable `GITHUB_TOKEN` does not exist.' ) ;
@@ -42,11 +48,18 @@ type VersionsToRelease = {
42
48
[ lang : string ] : {
43
49
current : string ;
44
50
next : string ;
51
+ dateStamp : string ;
45
52
} ;
46
53
} ;
47
54
55
+ function getDateStamp ( ) : string {
56
+ return new Date ( ) . toISOString ( ) . split ( 'T' ) [ 0 ] ;
57
+ }
58
+
48
59
function getVersionsToRelease ( issueBody : string ) : VersionsToRelease {
49
60
const versionsToRelease : VersionsToRelease = { } ;
61
+ const dateStamp = getDateStamp ( ) ;
62
+
50
63
getMarkdownSection ( issueBody , TEXT . versionChangeHeader )
51
64
. split ( '\n' )
52
65
. forEach ( ( line ) => {
@@ -58,6 +71,7 @@ function getVersionsToRelease(issueBody: string): VersionsToRelease {
58
71
versionsToRelease [ lang ] = {
59
72
current,
60
73
next,
74
+ dateStamp,
61
75
} ;
62
76
} ) ;
63
77
@@ -129,17 +143,10 @@ async function processRelease(): Promise<void> {
129
143
130
144
for ( const lang of langsToReleaseOrUpdate ) {
131
145
// prepare the submodule
132
- const clientPath = toAbsolutePath ( getLanguageFolder ( lang ) ) ;
133
- const targetBranch = getTargetBranch ( lang ) ;
134
- await run ( `git checkout ${ targetBranch } ` , { cwd : clientPath } ) ;
135
- await run ( `git pull origin ${ targetBranch } ` , { cwd : clientPath } ) ;
136
-
137
146
console . log ( `Generating ${ lang } client(s)...` ) ;
138
147
console . log ( await run ( `yarn cli generate ${ lang } ` ) ) ;
139
148
140
- const dateStamp = new Date ( ) . toISOString ( ) . split ( 'T' ) [ 0 ] ;
141
- const currentVersion = versionsToRelease [ lang ] . current ;
142
- const nextVersion = versionsToRelease [ lang ] . next ;
149
+ const { current, next, dateStamp } = versionsToRelease [ lang ] ;
143
150
144
151
// update changelog
145
152
const changelogPath = toAbsolutePath (
@@ -149,9 +156,7 @@ async function processRelease(): Promise<void> {
149
156
? ( await fsp . readFile ( changelogPath ) ) . toString ( )
150
157
: '' ;
151
158
const changelogHeader = willReleaseLibrary ( lang )
152
- ? `## [v${ nextVersion } ](${ getGitHubUrl (
153
- lang
154
- ) } /compare/v${ currentVersion } ...v${ nextVersion } )`
159
+ ? `## [v${ next } ](${ getGitHubUrl ( lang ) } /compare/v${ current } ...v${ next } )`
155
160
: `## ${ dateStamp } ` ;
156
161
const newChangelog = getMarkdownSection (
157
162
getMarkdownSection ( issueBody , TEXT . changelogHeader ) ,
@@ -162,22 +167,7 @@ async function processRelease(): Promise<void> {
162
167
[ changelogHeader , newChangelog , existingContent ] . join ( '\n\n' )
163
168
) ;
164
169
165
- // commit changelog and the generated client
166
- await configureGitHubAuthor ( clientPath ) ;
167
- await run ( `git add .` , { cwd : clientPath } ) ;
168
- if ( willReleaseLibrary ( lang ) ) {
169
- await execa ( 'git' , [ 'commit' , '-m' , `chore: release ${ nextVersion } ` ] , {
170
- cwd : clientPath ,
171
- } ) ;
172
- await execa ( 'git' , [ 'tag' , `v${ nextVersion } ` ] , { cwd : clientPath } ) ;
173
- } else {
174
- await execa ( 'git' , [ 'commit' , '-m' , `chore: update repo ${ dateStamp } ` ] , {
175
- cwd : clientPath ,
176
- } ) ;
177
- }
178
-
179
- // add the new reference of the submodule in the monorepo
180
- await run ( `git add ${ getLanguageFolder ( lang ) } ` ) ;
170
+ await run ( `git add ${ changelogPath } ` ) ;
181
171
}
182
172
183
173
// We push commits from submodules AFTER all the generations are done.
@@ -186,14 +176,37 @@ async function processRelease(): Promise<void> {
186
176
const clientPath = toAbsolutePath ( getLanguageFolder ( lang ) ) ;
187
177
const targetBranch = getTargetBranch ( lang ) ;
188
178
189
- await run ( `git push origin ${ targetBranch } ` , { cwd : clientPath } ) ;
179
+ const gitHubUrl = getGitHubUrl ( lang , { token : process . env . GITHUB_TOKEN } ) ;
180
+ const tempGitDir = `${ process . env . RUNNER_TEMP } /${ lang } ` ;
181
+ await run ( `rm -rf ${ tempGitDir } ` ) ;
182
+ await run (
183
+ `git clone --depth 1 --branch ${ targetBranch } ${ gitHubUrl } ${ tempGitDir } `
184
+ ) ;
185
+
186
+ await run ( `cp -r ${ clientPath } / ${ tempGitDir } ` ) ;
187
+ await configureGitHubAuthor ( tempGitDir ) ;
188
+ await run ( `git add .` , { cwd : tempGitDir } ) ;
189
+
190
+ const { next, dateStamp } = versionsToRelease [ lang ] ;
191
+
190
192
if ( willReleaseLibrary ( lang ) ) {
191
- await run ( 'git push --tags' , { cwd : clientPath } ) ;
193
+ await execa ( 'git' , [ 'commit' , '-m' , `chore: release ${ next } ` ] , {
194
+ cwd : tempGitDir ,
195
+ } ) ;
196
+ if ( process . env . VERSION_TAG_ON_RELEASE === 'true' ) {
197
+ await execa ( 'git' , [ 'tag' , `v${ next } ` ] , { cwd : tempGitDir } ) ;
198
+ await run ( `git push --tags` , { cwd : tempGitDir } ) ;
199
+ }
200
+ } else {
201
+ await execa ( 'git' , [ 'commit' , '-m' , `chore: update repo ${ dateStamp } ` ] , {
202
+ cwd : tempGitDir ,
203
+ } ) ;
192
204
}
205
+ await run ( `git push` , { cwd : tempGitDir } ) ;
193
206
}
194
207
195
208
// Commit and push from the monorepo level.
196
- await execa ( 'git' , [ 'commit' , '-m' , TEXT . commitMessage ] ) ;
209
+ await execa ( 'git' , [ 'commit' , '-m' , `chore: release ${ getDateStamp ( ) } ` ] ) ;
197
210
await run ( `git push` ) ;
198
211
199
212
// remove old `released` tag
0 commit comments