1- import {
2- paths ,
3- parseConfig ,
4- isTag ,
5- unmatchedPatterns ,
6- uploadUrl ,
7- } from "./util" ;
8- import { release , upload , GitHubReleaser } from "./github" ;
9- import { getOctokit } from "@actions/github" ;
10- import * as core from "@actions/core" ;
11- import axios , { isAxiosError } from "axios" ;
1+ import { setFailed , setOutput , error , info } from '@actions/core' ;
2+ import { getOctokit } from '@actions/github' ;
3+ import { GitHubReleaser , release , upload } from './github' ;
4+ import { isTag , parseConfig , paths , unmatchedPatterns , uploadUrl } from './util' ;
5+ import axios , { isAxiosError } from 'axios' ;
126
13- import { env } from " process" ;
7+ import { env } from ' process' ;
148
159async function run ( ) {
1610 try {
1711 await validateSubscription ( ) ;
1812 const config = parseConfig ( env ) ;
19- if (
20- ! config . input_tag_name &&
21- ! isTag ( config . github_ref ) &&
22- ! config . input_draft
23- ) {
13+ if ( ! config . input_tag_name && ! isTag ( config . github_ref ) && ! config . input_draft ) {
2414 throw new Error ( `⚠️ GitHub Releases requires a tag` ) ;
2515 }
2616 if ( config . input_files ) {
@@ -46,9 +36,7 @@ async function run() {
4636 //new oktokit(
4737 throttle : {
4838 onRateLimit : ( retryAfter , options ) => {
49- console . warn (
50- `Request quota exhausted for request ${ options . method } ${ options . url } ` ,
51- ) ;
39+ console . warn ( `Request quota exhausted for request ${ options . method } ${ options . url } ` ) ;
5240 if ( options . request . retryCount === 0 ) {
5341 // only retries once
5442 console . log ( `Retrying after ${ retryAfter } seconds!` ) ;
@@ -57,9 +45,7 @@ async function run() {
5745 } ,
5846 onAbuseLimit : ( retryAfter , options ) => {
5947 // does not retry, only logs a warning
60- console . warn (
61- `Abuse detected for request ${ options . method } ${ options . url } ` ,
62- ) ;
48+ console . warn ( `Abuse detected for request ${ options . method } ${ options . url } ` ) ;
6349 } ,
6450 } ,
6551 } ) ;
@@ -69,46 +55,40 @@ async function run() {
6955 const files = paths ( config . input_files ) ;
7056 if ( files . length == 0 ) {
7157 if ( config . input_fail_on_unmatched_files ) {
72- throw new Error (
73- `⚠️ ${ config . input_files } does not include a valid file.` ,
74- ) ;
58+ throw new Error ( `⚠️ ${ config . input_files } does not include a valid file.` ) ;
7559 } else {
76- console . warn (
77- `🤔 ${ config . input_files } does not include a valid file.` ,
78- ) ;
60+ console . warn ( `🤔 ${ config . input_files } does not include a valid file.` ) ;
7961 }
8062 }
8163 const currentAssets = rel . assets ;
8264
8365 const uploadFile = async ( path ) => {
84- const json = await upload (
85- config ,
86- gh ,
87- uploadUrl ( rel . upload_url ) ,
88- path ,
89- currentAssets ,
90- ) ;
91- delete json . uploader ;
66+ const json = await upload ( config , gh , uploadUrl ( rel . upload_url ) , path , currentAssets ) ;
67+ if ( json ) {
68+ delete json . uploader ;
69+ }
9270 return json ;
9371 } ;
9472
95- let assets ;
73+ let results : ( any | null ) [ ] ;
9674 if ( ! config . input_preserve_order ) {
97- assets = await Promise . all ( files . map ( uploadFile ) ) ;
75+ results = await Promise . all ( files . map ( uploadFile ) ) ;
9876 } else {
99- assets = [ ] ;
77+ results = [ ] ;
10078 for ( const path of files ) {
101- assets . push ( await uploadFile ( path ) ) ;
79+ results . push ( await uploadFile ( path ) ) ;
10280 }
10381 }
104- core . setOutput ( "assets" , assets ) ;
82+
83+ const assets = results . filter ( Boolean ) ;
84+ setOutput ( 'assets' , assets ) ;
10585 }
10686 console . log ( `🎉 Release ready at ${ rel . html_url } ` ) ;
107- core . setOutput ( " url" , rel . html_url ) ;
108- core . setOutput ( "id" , rel . id . toString ( ) ) ;
109- core . setOutput ( " upload_url" , rel . upload_url ) ;
87+ setOutput ( ' url' , rel . html_url ) ;
88+ setOutput ( 'id' , rel . id . toString ( ) ) ;
89+ setOutput ( ' upload_url' , rel . upload_url ) ;
11090 } catch ( error ) {
111- core . setFailed ( error . message ) ;
91+ setFailed ( error . message ) ;
11292 }
11393}
11494
@@ -119,14 +99,12 @@ async function validateSubscription(): Promise<void> {
11999
120100 try {
121101 await axios . get ( API_URL , { timeout : 3000 } ) ;
122- } catch ( error ) {
123- if ( isAxiosError ( error ) && error . response ?. status === 403 ) {
124- core . error (
125- "Subscription is not valid. Reach out to [email protected] " , 126- ) ;
102+ } catch ( err ) {
103+ if ( isAxiosError ( err ) && err . response ?. status === 403 ) {
104+ error ( 'Subscription is not valid. Reach out to [email protected] ' ) ; 127105 process . exit ( 1 ) ;
128106 } else {
129- core . info ( " Timeout or API not reachable. Continuing to next step." ) ;
107+ info ( ' Timeout or API not reachable. Continuing to next step.' ) ;
130108 }
131109 }
132110}
0 commit comments