1- const core = require ( ' @actions/core' ) ;
2- const github = require ( ' @actions/github' ) ;
1+ import * as core from " @actions/core" ;
2+ import * as github from " @actions/github" ;
33
44const perPage = 100 ; // Maximum allowed by GitHub API
55
@@ -9,8 +9,8 @@ async function fetchArtifacts(octokit, repository, name) {
99
1010 while ( true ) {
1111 const response = await octokit . rest . actions . listArtifactsForRepo ( {
12- owner : repository . split ( '/' ) [ 0 ] ,
13- repo : repository . split ( '/' ) [ 1 ] ,
12+ owner : repository . split ( "/" ) [ 0 ] ,
13+ repo : repository . split ( "/" ) [ 1 ] ,
1414 name,
1515 per_page : perPage ,
1616 page,
@@ -31,18 +31,31 @@ async function fetchArtifacts(octokit, repository, name) {
3131}
3232
3333function getPrNumber ( ) {
34- if ( github . context . eventName === ' pull_request' ) {
34+ if ( github . context . eventName === " pull_request" ) {
3535 return github . context . payload . pull_request . number ;
3636 }
3737 return undefined ;
3838}
3939
4040async function run ( ) {
4141 try {
42- const token = core . getInput ( 'github-token' ) ;
43- const repository = core . getInput ( 'repository' ) ;
44- const name = core . getInput ( 'name' ) ;
45- const reSign = core . getInput ( 're-sign' ) ;
42+ const token = core . getInput ( "github_token" ) || process . env . GITHUB_TOKEN ;
43+
44+ if ( ! token ) {
45+ throw new Error ( "GitHub token is required" ) ;
46+ }
47+
48+ const repository = core . getInput ( "repository" ) ;
49+ if ( ! repository ) {
50+ throw new Error ( "Repository is required" ) ;
51+ }
52+
53+ const name = core . getInput ( "name" ) ;
54+ if ( ! name ) {
55+ throw new Error ( "Artifact name is required" ) ;
56+ }
57+
58+ const reSign = core . getInput ( "re_sign" ) ;
4659 const prNumber = getPrNumber ( ) ;
4760
4861 const octokit = github . getOctokit ( token ) ;
@@ -61,20 +74,20 @@ async function run() {
6174 for ( const artifact of artifacts ) {
6275 console . log (
6376 `- ID: ${ artifact . id } , Name: ${ artifact . name } , Size: ${ formatSize (
64- artifact . size_in_bytes ,
65- ) } , Expires at: ${ artifact . expires_at } `,
77+ artifact . size_in_bytes
78+ ) } , Expires at: ${ artifact . expires_at } `
6679 ) ;
6780 }
6881
69- const firstArtifact = artifacts . find ( artifact => ! artifact . expired ) ;
82+ const firstArtifact = artifacts . find ( ( artifact ) => ! artifact . expired ) ;
7083 console . log ( `First artifact: ${ JSON . stringify ( firstArtifact , null , 2 ) } ` ) ;
7184
7285 const url = formatDownloadUrl (
7386 repository ,
7487 firstArtifact . workflow_run . id ,
75- firstArtifact . id ,
88+ firstArtifact . id
7689 ) ;
77- console . log ( ' Stable download URL:' , url ) ;
90+ console . log ( " Stable download URL:" , url ) ;
7891
7992 let artifactName = name ;
8093 // There are artifacts from PR but the base artifact is gone, recreate with the original name
@@ -84,12 +97,12 @@ async function run() {
8497 } else if ( prNumber && reSign ) {
8598 artifactName = `${ name } -${ prNumber } ` ;
8699 }
87- core . setOutput ( ' artifact-name' , artifactName ) ;
88- core . setOutput ( ' artifact-id' , firstArtifact . id ) ;
89- core . setOutput ( ' artifact-url' , url ) ;
100+ core . setOutput ( " artifact-name" , artifactName ) ;
101+ core . setOutput ( " artifact-id" , firstArtifact . id ) ;
102+ core . setOutput ( " artifact-url" , url ) ;
90103 core . setOutput (
91- ' artifact-ids' ,
92- artifactsByPrNumber . map ( artifact => artifact . id ) . join ( ' ' ) ,
104+ " artifact-ids" ,
105+ artifactsByPrNumber . map ( ( artifact ) => artifact . id ) . join ( " " )
93106 ) ;
94107 } catch ( error ) {
95108 core . setFailed ( `Action failed with error: ${ error . message } ` ) ;
0 commit comments