@@ -20,48 +20,52 @@ interface ArtifactInfo {
20
20
kind : 'artifact' ;
21
21
filename : string ;
22
22
buildTag : string ;
23
- published : Promise < void > ;
23
+ publish : ( c : Context ) => Promise < void > ;
24
24
}
25
25
26
26
const artifact =
27
- ( filename : string , buildTag : string ) =>
28
- async ( { publish } : Context ) : Promise < ArtifactInfo > => {
27
+ ( filename : string , buildTag : string ) => async ( ) : Promise < ArtifactInfo > => {
29
28
return {
30
29
kind : 'artifact' ,
31
30
filename,
32
31
buildTag,
33
- published : publish (
34
- filename ,
35
- await fs . readFile ( runfiles . resolveWorkspaceRelative ( buildTag ) )
36
- ) ,
32
+ publish : async ( { publish } : Context ) =>
33
+ publish (
34
+ filename ,
35
+ await fs . readFile (
36
+ runfiles . resolveWorkspaceRelative ( buildTag )
37
+ )
38
+ ) ,
37
39
} ;
38
40
} ;
39
41
40
42
interface NpmPackageInfo {
41
43
kind : 'npm_publication' ;
42
44
package_name : string ;
43
45
buildTag : string ;
44
- published : Promise < void > ;
46
+ publish : ( c : Context ) => Promise < void > ;
45
47
}
46
48
47
49
const npmPackage =
48
50
( packageName : string , buildTag : string ) =>
49
- async ( { exec } : Context ) : Promise < NpmPackageInfo > => {
50
- if ( ! ( 'NPM_TOKEN' in process . env ) )
51
- throw new Error (
52
- "Missing NPM_TOKEN. We won't be able to publish any NPM packages."
53
- ) ;
51
+ async ( ) : Promise < NpmPackageInfo > => {
54
52
return {
55
53
buildTag,
56
54
kind : 'npm_publication' ,
57
55
package_name : packageName ,
58
- published : exec ( runfiles . resolveWorkspaceRelative ( buildTag ) ) ,
56
+ async publish ( { exec } : Context ) {
57
+ if ( ! ( 'NPM_TOKEN' in process . env ) )
58
+ throw new Error (
59
+ "Missing NPM_TOKEN. We won't be able to publish any NPM packages."
60
+ ) ;
61
+ exec ( runfiles . resolveWorkspaceRelative ( buildTag ) ) ;
62
+ } ,
59
63
} ;
60
64
} ;
61
65
62
- interface ReleaseProps < T > {
66
+ interface ReleaseProps {
63
67
dryRun : boolean ;
64
- releaseNotes : ( items : T [ ] ) => string ;
68
+ releaseNotes : ( items : ( ArtifactInfo | NpmPackageInfo ) [ ] ) => string ;
65
69
createRelease ( data : { body : string } ) : Promise < { release_id : number } > ;
66
70
uploadReleaseAsset ( data : {
67
71
release_id : number ;
@@ -71,30 +75,29 @@ interface ReleaseProps<T> {
71
75
}
72
76
73
77
const release =
74
- < T extends { published : Promise < void > } > (
75
- ...fns : ( ( c : Context ) => Promise < T > ) [ ]
76
- ) =>
78
+ ( ...fns : ( ( ) => Promise < ArtifactInfo | NpmPackageInfo > ) [ ] ) =>
77
79
async ( {
78
80
dryRun,
79
81
createRelease,
80
82
releaseNotes,
81
83
uploadReleaseAsset,
82
- } : ReleaseProps < T > ) => {
83
- let set_release_id : ( ( release_id : number ) => void ) | undefined ;
84
- const release_id = new Promise < number > ( ok => ( set_release_id = ok ) ) ;
85
-
86
- const publish : Context [ 'publish' ] = dryRun
87
- ? async ( filename : string , content : Buffer ) => {
88
- if ( ! filename ) throw new Error ( 'Empty filename.' ) ;
89
- if ( content . length == 0 )
90
- throw new Error ( `Empty content for ${ filename } ` ) ;
91
- }
92
- : async ( file : string , content : Buffer ) =>
93
- uploadReleaseAsset ( {
94
- release_id : await release_id ,
95
- name : file ,
96
- data : content ,
97
- } ) ;
84
+ } : ReleaseProps ) => {
85
+ const logInfo = await Promise . all ( fns . map ( f => f ( ) ) ) ;
86
+
87
+ const { release_id } = await createRelease ( {
88
+ body : releaseNotes ( logInfo ) ,
89
+ } ) ;
90
+
91
+ const publish : Context [ 'publish' ] = async (
92
+ file : string ,
93
+ content : Buffer
94
+ ) =>
95
+ uploadReleaseAsset ( {
96
+ release_id,
97
+ name : file ,
98
+ data : content ,
99
+ } ) ;
100
+
98
101
const exec : Context [ 'exec' ] = dryRun
99
102
? async ( filename : string ) => {
100
103
if ( filename == '' )
@@ -103,17 +106,9 @@ const release =
103
106
: async ( filename : string ) =>
104
107
void ( await promisify ( child_process . execFile ) ( filename ) ) ;
105
108
106
- const logInfo = await Promise . all ( fns . map ( f => f ( { publish, exec } ) ) ) ;
107
-
108
- const { release_id : concreteReleaseId } = await createRelease ( {
109
- body : releaseNotes ( logInfo ) ,
110
- } ) ;
111
-
112
- if ( ! set_release_id ) throw new Error ( ) ;
113
-
114
- set_release_id ( concreteReleaseId ) ;
115
-
116
- await Promise . all ( logInfo . map ( itm => itm . published ) ) ;
109
+ await Promise . all (
110
+ logInfo . map ( ( { publish : p } ) => p ( { publish, exec } ) )
111
+ ) ;
117
112
} ;
118
113
119
114
export const program = Program . name ( 'release' )
@@ -130,17 +125,17 @@ export const program = Program.name('release')
130
125
? getOctokit ( process . env [ 'GITHUB_TOKEN' ] ! )
131
126
: undefined ;
132
127
133
- const releaser = release < NpmPackageInfo | ArtifactInfo > (
128
+ const releaser = release (
134
129
artifact (
135
130
'recursive_vassals.zip' ,
136
- 'project/ck3/recursive-vassals/mod_zip.zip'
131
+ '// project/ck3/recursive-vassals/mod_zip.zip'
137
132
) ,
138
133
artifact (
139
134
'recursive_vassals.patch' ,
140
135
'//project/ck3/recursive-vassals/mod.patch'
141
136
) ,
142
- artifact ( 'svgshot.tar.gz' , 'ts/cmd/svgshot/svgshot.tgz' ) ,
143
- npmPackage ( 'svgshot' , 'ts/cmd/svgshot/npm_pkg.publish.sh' )
137
+ artifact ( 'svgshot.tar.gz' , '// ts/cmd/svgshot/svgshot.tgz' ) ,
138
+ npmPackage ( 'svgshot' , '// ts/cmd/svgshot/npm_pkg.publish.sh' )
144
139
) ;
145
140
146
141
releaser ( {
@@ -160,57 +155,68 @@ export const program = Program.name('release')
160
155
if ( ! data ) throw new Error ( 'data is empty' ) ;
161
156
} ,
162
157
163
- createRelease : Github
164
- ? async ( { body } ) => ( {
165
- release_id : (
166
- await Github . rest . repos . createRelease ( {
167
- // could probably use a spread operator here
168
- // but i also think that would be uglier...
169
- owner : context . repo . owner ,
170
- repo : context . repo . repo ,
171
-
172
- tag_name : syntheticVersion ,
173
-
174
- body,
175
-
176
- generate_release_notes : true ,
177
-
178
- name : syntheticVersion ,
179
-
180
- target_commitish : context . ref ,
181
- } )
182
- ) . data . id ,
183
- } )
184
- : async ( { body } ) => {
185
- if ( body === '' )
186
- throw new Error ( 'Release body is empty.' ) ;
187
- return { release_id : 0 } ;
188
- } ,
158
+ createRelease :
159
+ Github !== undefined
160
+ ? async ( { body } ) => ( {
161
+ release_id : (
162
+ await Github . rest . repos . createRelease ( {
163
+ // could probably use a spread operator here
164
+ // but i also think that would be uglier...
165
+ owner : context . repo . owner ,
166
+ repo : context . repo . repo ,
167
+
168
+ tag_name : syntheticVersion ,
169
+
170
+ body,
171
+
172
+ generate_release_notes : true ,
173
+
174
+ name : syntheticVersion ,
175
+
176
+ target_commitish : context . ref ,
177
+ } )
178
+ ) . data . id ,
179
+ } )
180
+ : async ( { body } ) => {
181
+ if ( body === '' )
182
+ throw new Error ( `Release body is empty.` ) ;
183
+ return { release_id : 0 } ;
184
+ } ,
189
185
dryRun : dryRun ,
190
186
releaseNotes : ( notes : ( NpmPackageInfo | ArtifactInfo ) [ ] ) => {
191
187
const artifacts : ArtifactInfo [ ] = [ ] ;
192
188
const npmPackages : NpmPackageInfo [ ] = [ ] ;
193
189
194
190
for ( const note of notes ) {
195
- if ( note . kind === 'artifact' ) artifacts . push ( note ) ;
196
- if ( note . kind === 'npm_publication' ) npmPackages . push ( note ) ;
197
- throw new Error ( ) ;
191
+ if ( note . kind === 'artifact' ) {
192
+ artifacts . push ( note ) ;
193
+ continue ;
194
+ }
195
+ if ( note . kind === 'npm_publication' ) {
196
+ npmPackages . push ( note ) ;
197
+ continue ;
198
+ }
199
+ throw new Error ( `Unknown kind ${ ( note as any ) . kind } ` ) ;
198
200
}
199
201
200
202
return `${
201
203
artifacts . length
202
- ? `This release contains the following artifacts:\n ${ artifacts . map (
203
- artifact =>
204
- ` - ${ artifact . buildTag } → ${ artifact . filename } `
205
- ) } `
204
+ ? `This release contains the following artifacts:\n ${ artifacts
205
+ . map (
206
+ artifact =>
207
+ ` - ${ artifact . buildTag } → ${ artifact . filename } `
208
+ )
209
+ . join ( '\n' ) } `
206
210
: ''
207
211
}
208
212
${
209
213
npmPackages . length
210
- ? `This release contains the following NPM packages:\n: ${ npmPackages . map (
211
- pkg =>
212
- ` - ${ pkg . buildTag } → [${ pkg . package_name } ](https://npmjs.com/package/svgshot)`
213
- ) } `
214
+ ? `This release contains the following NPM packages:\n ${ npmPackages
215
+ . map (
216
+ pkg =>
217
+ ` - ${ pkg . buildTag } → [${ pkg . package_name } ](https://npmjs.com/package/svgshot)`
218
+ )
219
+ . join ( '\n' ) } `
214
220
: ''
215
221
}
216
222
` ;
0 commit comments