@@ -111,6 +111,36 @@ jobs:
111111 script : |
112112 const packages = process.env.PACKAGES.split("\n").map(packageName => packageName.trim()).filter(Boolean);
113113
114+ const sleep = (delayMs) =>
115+ new Promise((resolve) => setTimeout(resolve, delayMs));
116+
117+ async function getPackageForOrganizationWithRetry(
118+ packagePayload,
119+ maxAttempts = 6,
120+ delayMs = 5000,
121+ ) {
122+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
123+ try {
124+ return await github.rest.packages.getPackageForOrganization(
125+ packagePayload
126+ );
127+ } catch (error) {
128+ if (error.status !== 404 || attempt === maxAttempts) {
129+ throw error;
130+ }
131+
132+ core.info(
133+ [
134+ `Package "${packagePayload.package_name}" is not visible yet`,
135+ `(attempt ${attempt}/${maxAttempts}).`,
136+ `Retrying in ${delayMs} ms.`,
137+ ].join(" ")
138+ );
139+ await sleep(delayMs);
140+ }
141+ }
142+ }
143+
114144 for(const packageName of packages) {
115145 const packagePayload = {
116146 package_type: 'container',
@@ -119,7 +149,7 @@ jobs:
119149 };
120150
121151 // Ensure that package exists
122- const packageExists = await github.rest.packages.getPackageForOrganization (packagePayload);
152+ const packageExists = await getPackageForOrganizationWithRetry (packagePayload);
123153 if (!packageExists) {
124154 return core.setFailed(`Package "${packageName}" does not exist`);
125155 }
@@ -207,6 +237,65 @@ jobs:
207237
208238 const packages = process.env.PACKAGES.split("\n").map(packageName => packageName.trim()).filter(Boolean);
209239
240+ const sleep = (delayMs) =>
241+ new Promise((resolve) => setTimeout(resolve, delayMs));
242+
243+ async function getPackageForOrganizationWithRetry(
244+ packagePayload,
245+ maxAttempts = 6,
246+ delayMs = 5000,
247+ ) {
248+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
249+ try {
250+ return await github.rest.packages.getPackageForOrganization(
251+ packagePayload
252+ );
253+ } catch (error) {
254+ if (error.status !== 404 || attempt === maxAttempts) {
255+ throw error;
256+ }
257+
258+ core.info(
259+ [
260+ `Package "${packagePayload.package_name}" is not visible yet`,
261+ `(attempt ${attempt}/${maxAttempts}).`,
262+ `Retrying in ${delayMs} ms.`,
263+ ].join(" ")
264+ );
265+ await sleep(delayMs);
266+ }
267+ }
268+ }
269+
270+ async function getPackageVersionsForOrganizationWithRetry(
271+ packagePayload,
272+ maxAttempts = 6,
273+ delayMs = 5000,
274+ ) {
275+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
276+ try {
277+ return await github.paginate(
278+ github.rest.packages
279+ .getAllPackageVersionsForPackageOwnedByOrg
280+ .endpoint.merge(packagePayload)
281+ );
282+ } catch (error) {
283+ if (error.status !== 404 || attempt === maxAttempts) {
284+ throw error;
285+ }
286+
287+ core.info(
288+ [
289+ `Package versions for "${packagePayload.package_name}"`,
290+ `are not visible yet (attempt ${attempt}/${maxAttempts}).`,
291+ `Retrying in ${delayMs} ms.`,
292+ ].join(" ")
293+ );
294+ await sleep(delayMs);
295+ }
296+ }
297+ }
298+
210299 for(const packageName of packages) {
211300 const packagePayload = {
212301 package_type: 'container',
@@ -215,12 +304,10 @@ jobs:
215304 };
216305
217306 // Ensure that package still exists
218- const packageExists = await github.rest.packages.getPackageForOrganization (packagePayload);
307+ const packageExists = await getPackageForOrganizationWithRetry (packagePayload);
219308 assert(packageExists, `Package "${packageName}" does not exist`);
220309
221- const packageVersions = await github.paginate(
222- github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg.endpoint.merge(packagePayload)
223- );
310+ const packageVersions = await getPackageVersionsForOrganizationWithRetry(packagePayload);
224311
225312 const packageVersionExists = packageVersions.some(
226313 (packageVersion) => packageVersion.metadata.container.tags.some(
0 commit comments