1- // @ts -check
21// Dependencies are compiled using https://github.com/vercel/ncc
3- const core = require ( '@actions/core' ) ;
4- const github = require ( '@actions/github' ) ;
5- const axios = require ( 'axios' ) ;
6- const setCookieParser = require ( 'set-cookie-parser' ) ;
2+ import core from '@actions/core' ;
3+ import github from '@actions/github' ;
4+ import type { GitHub } from '@actions/github/lib/utils.js' ;
75
8- const calculateIterations = ( maxTimeoutSec , checkIntervalInMilliseconds ) =>
6+ const calculateIterations = ( maxTimeoutSec : number , checkIntervalInMilliseconds : number ) =>
97 Math . floor ( maxTimeoutSec / ( checkIntervalInMilliseconds / 1000 ) ) ;
108
11- const wait = ( ms ) => new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
9+ const wait = ( ms : number ) => new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
1210
11+ < < < << << Updated upstream :action . js
1312const waitForUrl = async ( {
1413 url,
1514 maxTimeout,
@@ -120,6 +119,9 @@ const getPassword = async ({ url, vercelPassword }) => {
120119
121120 return vercelJwtCookie . value ;
122121} ;
122+ = === ===
123+
124+ >>> >>> > Stashed changes:action . ts
123125
124126const waitForStatus = async ( {
125127 token,
@@ -129,8 +131,17 @@ const waitForStatus = async ({
129131 maxTimeout,
130132 allowInactive,
131133 checkIntervalInMilliseconds,
134+ } : {
135+ token : string ;
136+ owner : string ;
137+ repo : string ;
138+ deployment_id : number ;
139+ maxTimeout : number ;
140+ allowInactive : boolean ;
141+ checkIntervalInMilliseconds : number ;
132142} ) => {
133- const octokit = new github . getOctokit ( token ) ;
143+ // @ts -ignore
144+ const octokit : InstanceType < typeof GitHub > = new github . getOctokit ( token ) ;
134145 const iterations = calculateIterations (
135146 maxTimeout ,
136147 checkIntervalInMilliseconds
@@ -187,7 +198,7 @@ const waitForStatus = async ({
187198} ;
188199
189200class StatusError extends Error {
190- constructor ( message ) {
201+ constructor ( message : string ) {
191202 super ( message ) ;
192203 }
193204}
@@ -210,12 +221,22 @@ const waitForDeploymentToStart = async ({
210221 actorName = 'vercel[bot]' ,
211222 maxTimeout = 20 ,
212223 checkIntervalInMilliseconds = 2000 ,
224+ } : {
225+ octokit : ReturnType < typeof github . getOctokit > ;
226+ owner : string ;
227+ repo : string ;
228+ sha : string ;
229+ environment : string [ ] ;
230+ actorName : string ;
231+ maxTimeout : number ;
232+ checkIntervalInMilliseconds : number ;
213233} ) => {
214234 const iterations = calculateIterations (
215235 maxTimeout ,
216236 checkIntervalInMilliseconds
217237 ) ;
218238
239+ < < < << << Updated upstream :action . js
219240 for ( let i = 0 ; i < iterations ; i ++ ) {
220241 try {
221242 const deployments = await octokit . rest . repos . listDeployments ( {
@@ -224,15 +245,53 @@ const waitForDeploymentToStart = async ({
224245 sha,
225246 environment,
226247 } ) ;
248+ = === ===
249+ if ( Array . isArray ( environment ) ) {
250+ let arrayIndex = 0 ;
251+ const iterateArray = ( environment : string [ ] ) => {
252+ if ( arrayIndex < environment . length ) {
253+ const string = environment [ arrayIndex ] ;
254+ arrayIndex ++ ;
255+ return string ;
256+ }
257+ arrayIndex = 0 ;
258+ return environment [ arrayIndex ] ;
259+ } ;
260+ > >>> >>> Stashed changes:action . ts
227261
228262 const deployment =
229263 deployments . data . length > 0 &&
230264 deployments . data . find ( ( deployment ) => {
231265 return deployment . creator . login === actorName ;
232266 } ) ;
233267
268+ < < < << << Updated upstream :action . js
234269 if ( deployment ) {
235270 return deployment ;
271+ === === =
272+ const deployment = deployments . data . sort (
273+ // @ts -ignore
274+ ( a , b ) => new Date ( b . created_at ) - new Date ( a . created_at )
275+ ) [ 0 ] ;
276+
277+ if ( deployment ) {
278+ return deployment ;
279+ }
280+
281+ console . log (
282+ `Could not find any deployments for actor ${ actorName } & deployment ${ env } , retrying (attempt ${
283+ i + 1
284+ } / ${ iterations } )`
285+ ) ;
286+ } catch ( e ) {
287+ console . log (
288+ `Error while fetching deployments, retrying (attempt ${
289+ i + 1
290+ } / ${ iterations } )`
291+ ) ;
292+
293+ console . error ( e ) ;
294+ >>> > >>> Stashed changes :action . ts
236295 }
237296
238297 console . log (
@@ -250,14 +309,44 @@ const waitForDeploymentToStart = async ({
250309 console . error ( e )
251310 }
252311
312+ << < < < << Updated upstream :action . js
253313 await wait ( checkIntervalInMilliseconds ) ;
314+ === = ===
315+ const deployment =
316+ deployments . data . length > 0 &&
317+ deployments . data . find ( ( deployment ) => {
318+ return deployment . creator ?. login === actorName ;
319+ } ) ;
320+
321+ if ( deployment ) {
322+ return deployment ;
323+ }
324+
325+ console . log (
326+ `Could not find any deployments for actor ${ actorName } , retrying (attempt ${
327+ i + 1
328+ } / ${ iterations } )`
329+ ) ;
330+ } catch ( e ) {
331+ console . log (
332+ `Error while fetching deployments, retrying (attempt ${
333+ i + 1
334+ } / ${ iterations } )`
335+ ) ;
336+
337+ console . error ( e ) ;
338+ }
339+
340+ await wait ( checkIntervalInMilliseconds ) ;
341+ }
342+ >>> > >>> Stashed changes :action . ts
254343 }
255344
256345 return null ;
257346} ;
258347
259- async function getShaForPullRequest ( { octokit, owner, repo, number } ) {
260- const PR_NUMBER = github . context . payload . pull_request . number ;
348+ async function getShaForPullRequest ( { octokit, owner, repo, number } : { octokit : ReturnType < typeof github . getOctokit > ; owner : string ; repo : string ; number : number } ) {
349+ const PR_NUMBER = github . context . payload ? .pull_request ? .number
261350
262351 if ( ! PR_NUMBER ) {
263352 core . setFailed ( 'No pull request number was found' ) ;
@@ -282,7 +371,7 @@ async function getShaForPullRequest({ octokit, owner, repo, number }) {
282371 return prSHA ;
283372}
284373
285- const run = async ( ) => {
374+ export const run = async ( ) = > {
286375 try {
287376 // Inputs
288377 const GITHUB_TOKEN = core . getInput ( 'token' , { required : true } ) ;
@@ -355,7 +444,7 @@ const run = async () => {
355444 } ) ;
356445
357446 // Get target url
358- const targetUrl = status . target_url ;
447+ const targetUrl = status ? .target_url ;
359448
360449 if ( ! targetUrl ) {
361450 core . setFailed ( `no target_url found in the status check` ) ;
@@ -379,8 +468,6 @@ const run = async () => {
379468 path : PATH ,
380469 } ) ;
381470 } catch ( error ) {
382- core . setFailed ( error . message ) ;
471+ core . setFailed ( error instanceof Error ? error . message : 'Unknown error' ) ;
383472 }
384473} ;
385-
386- exports . run = run ;
0 commit comments