@@ -208,45 +208,63 @@ export const release = async (
208
208
try {
209
209
// you can't get a an existing draft by tag
210
210
// so we must find one in the list of all releases
211
+ let _release : Release | undefined = undefined ;
211
212
if ( config . input_draft ) {
212
213
for await ( const response of releaser . allReleases ( {
213
214
owner,
214
215
repo,
215
216
} ) ) {
216
- let release = response . data . find ( ( release ) => release . tag_name === tag ) ;
217
- if ( release ) {
218
- return release ;
219
- }
217
+ _release = response . data . find ( ( release ) => release . tag_name === tag ) ;
220
218
}
219
+ } else {
220
+ _release = (
221
+ await releaser . getReleaseByTag ( {
222
+ owner,
223
+ repo,
224
+ tag,
225
+ } )
226
+ ) . data ;
221
227
}
222
- let existingRelease = await releaser . getReleaseByTag ( {
223
- owner,
224
- repo,
225
- tag,
226
- } ) ;
228
+ if ( _release === null || _release === undefined ) {
229
+ return await createRelease (
230
+ tag ,
231
+ config ,
232
+ releaser ,
233
+ owner ,
234
+ repo ,
235
+ discussion_category_name ,
236
+ generate_release_notes ,
237
+ maxRetries
238
+ ) ;
239
+ }
240
+
241
+ let existingRelease : Release = _release ! ;
242
+ console . log (
243
+ `Found release ${ existingRelease . name } (with id=${ existingRelease . id } )`
244
+ ) ;
227
245
228
- const release_id = existingRelease . data . id ;
246
+ const release_id = existingRelease . id ;
229
247
let target_commitish : string ;
230
248
if (
231
249
config . input_target_commitish &&
232
- config . input_target_commitish !== existingRelease . data . target_commitish
250
+ config . input_target_commitish !== existingRelease . target_commitish
233
251
) {
234
252
console . log (
235
- `Updating commit from "${ existingRelease . data . target_commitish } " to "${ config . input_target_commitish } "`
253
+ `Updating commit from "${ existingRelease . target_commitish } " to "${ config . input_target_commitish } "`
236
254
) ;
237
255
target_commitish = config . input_target_commitish ;
238
256
} else {
239
- target_commitish = existingRelease . data . target_commitish ;
257
+ target_commitish = existingRelease . target_commitish ;
240
258
}
241
259
242
260
const tag_name = tag ;
243
- const name = config . input_name || existingRelease . data . name || tag ;
261
+ const name = config . input_name || existingRelease . name || tag ;
244
262
// revisit: support a new body-concat-strategy input for accumulating
245
263
// body parts as a release gets updated. some users will likely want this while
246
264
// others won't previously this was duplicating content for most which
247
265
// no one wants
248
266
const workflowBody = releaseBody ( config ) || "" ;
249
- const existingReleaseBody = existingRelease . data . body || "" ;
267
+ const existingReleaseBody = existingRelease . body || "" ;
250
268
let body : string ;
251
269
if ( config . input_append_body && workflowBody && existingReleaseBody ) {
252
270
body = existingReleaseBody + "\n" + workflowBody ;
@@ -257,11 +275,11 @@ export const release = async (
257
275
const draft =
258
276
config . input_draft !== undefined
259
277
? config . input_draft
260
- : existingRelease . data . draft ;
278
+ : existingRelease . draft ;
261
279
const prerelease =
262
280
config . input_prerelease !== undefined
263
281
? config . input_prerelease
264
- : existingRelease . data . prerelease ;
282
+ : existingRelease . prerelease ;
265
283
266
284
const make_latest = config . input_make_latest ;
267
285
@@ -288,58 +306,80 @@ export const release = async (
288
306
throw error ;
289
307
}
290
308
291
- const tag_name = tag ;
292
- const name = config . input_name || tag ;
293
- const body = releaseBody ( config ) ;
294
- const draft = config . input_draft ;
295
- const prerelease = config . input_prerelease ;
296
- const target_commitish = config . input_target_commitish ;
297
- const make_latest = config . input_make_latest ;
298
- let commitMessage : string = "" ;
299
- if ( target_commitish ) {
300
- commitMessage = ` using commit "${ target_commitish } "` ;
301
- }
302
- console . log (
303
- `👩🏭 Creating new GitHub release for tag ${ tag_name } ${ commitMessage } ...`
309
+ return await createRelease (
310
+ tag ,
311
+ config ,
312
+ releaser ,
313
+ owner ,
314
+ repo ,
315
+ discussion_category_name ,
316
+ generate_release_notes ,
317
+ maxRetries
304
318
) ;
305
- try {
306
- let release = await releaser . createRelease ( {
307
- owner,
308
- repo,
309
- tag_name,
310
- name,
311
- body,
312
- draft,
313
- prerelease,
314
- target_commitish,
315
- discussion_category_name,
316
- generate_release_notes,
317
- make_latest,
318
- } ) ;
319
- return release . data ;
320
- } catch ( error ) {
321
- // presume a race with competing matrix runs
322
- console . log ( `⚠️ GitHub release failed with status: ${ error . status } ` ) ;
323
- console . log ( `${ JSON . stringify ( error . response . data ) } ` ) ;
319
+ }
320
+ } ;
324
321
325
- switch ( error . status ) {
326
- case 403 :
327
- console . log (
328
- "Skip retry — your GitHub token/PAT does not have the required permission to create a release"
329
- ) ;
330
- throw error ;
322
+ async function createRelease (
323
+ tag : string ,
324
+ config : Config ,
325
+ releaser : Releaser ,
326
+ owner : string ,
327
+ repo : string ,
328
+ discussion_category_name : string | undefined ,
329
+ generate_release_notes : boolean | undefined ,
330
+ maxRetries : number
331
+ ) {
332
+ const tag_name = tag ;
333
+ const name = config . input_name || tag ;
334
+ const body = releaseBody ( config ) ;
335
+ const draft = config . input_draft ;
336
+ const prerelease = config . input_prerelease ;
337
+ const target_commitish = config . input_target_commitish ;
338
+ const make_latest = config . input_make_latest ;
339
+ let commitMessage : string = "" ;
340
+ if ( target_commitish ) {
341
+ commitMessage = ` using commit "${ target_commitish } "` ;
342
+ }
343
+ console . log (
344
+ `👩🏭 Creating new GitHub release for tag ${ tag_name } ${ commitMessage } ...`
345
+ ) ;
346
+ try {
347
+ let release = await releaser . createRelease ( {
348
+ owner,
349
+ repo,
350
+ tag_name,
351
+ name,
352
+ body,
353
+ draft,
354
+ prerelease,
355
+ target_commitish,
356
+ discussion_category_name,
357
+ generate_release_notes,
358
+ make_latest,
359
+ } ) ;
360
+ return release . data ;
361
+ } catch ( error ) {
362
+ // presume a race with competing matrix runs
363
+ console . log ( `⚠️ GitHub release failed with status: ${ error . status } ` ) ;
364
+ console . log ( `${ JSON . stringify ( error . response . data ) } ` ) ;
331
365
332
- case 404 :
333
- console . log ( "Skip retry - discussion category mismatch" ) ;
334
- throw error ;
366
+ switch ( error . status ) {
367
+ case 403 :
368
+ console . log (
369
+ "Skip retry — your GitHub token/PAT does not have the required permission to create a release"
370
+ ) ;
371
+ throw error ;
335
372
336
- case 422 :
337
- console . log ( "Skip retry - validation failed" ) ;
338
- throw error ;
339
- }
373
+ case 404 :
374
+ console . log ( "Skip retry - discussion category mismatch" ) ;
375
+ throw error ;
340
376
341
- console . log ( `retrying... (${ maxRetries - 1 } retries remaining)` ) ;
342
- return release ( config , releaser , maxRetries - 1 ) ;
377
+ case 422 :
378
+ console . log ( "Skip retry - validation failed" ) ;
379
+ throw error ;
343
380
}
381
+
382
+ console . log ( `retrying... (${ maxRetries - 1 } retries remaining)` ) ;
383
+ return release ( config , releaser , maxRetries - 1 ) ;
344
384
}
345
- } ;
385
+ }
0 commit comments