88
99// Copyright (c) JFrog Ltd. (2025)
1010Object.defineProperty(exports, "__esModule", ({ value: true }));
11- exports.GITHUB_STATUS_SKIPPED = exports. GITHUB_STATUS_TIMED_OUT = exports.GITHUB_STATUS_CANCELLED = exports.GITHUB_STATUS_FAILURE = exports.GITHUB_STATUS_SUCCESS = exports.FLY_CLI_SETUP_OUTPUT_PATH = exports.FLY_CLI_PATH = exports.STATE_FLY_PACKAGE_MANAGERS = exports.STATE_FLY_ACCESS_TOKEN = exports.STATE_FLY_URL = exports.INPUT_GITHUB_TOKEN = exports.INPUT_IGNORE_PACKAGE_MANAGERS = exports.INPUT_URL = void 0;
11+ exports.GITHUB_STATUS_TIMED_OUT = exports.GITHUB_STATUS_CANCELLED = exports.GITHUB_STATUS_FAILURE = exports.GITHUB_STATUS_SUCCESS = exports.ENV_FLY_ACTION_CONFIGURED = exports.STATE_FLY_PACKAGE_MANAGERS = exports.STATE_FLY_ACCESS_TOKEN = exports.STATE_FLY_URL = exports.INPUT_GITHUB_TOKEN = exports.INPUT_IGNORE_PACKAGE_MANAGERS = exports.INPUT_URL = void 0;
1212exports.INPUT_URL = "url";
1313exports.INPUT_IGNORE_PACKAGE_MANAGERS = "ignore";
1414exports.INPUT_GITHUB_TOKEN = "github_token";
1515exports.STATE_FLY_URL = "fly-url";
1616exports.STATE_FLY_ACCESS_TOKEN = "fly-access-token";
1717exports.STATE_FLY_PACKAGE_MANAGERS = "fly-package-managers";
18- exports.FLY_CLI_PATH = "fly-cli-path";
19- exports.FLY_CLI_SETUP_OUTPUT_PATH = "fly-cli-setup-output-path ";
18+ // Environment variable to track if action has already run in this job
19+ exports.ENV_FLY_ACTION_CONFIGURED = "FLY_ACTION_CONFIGURED ";
2020// GitHub step/job conclusion statuses
2121exports.GITHUB_STATUS_SUCCESS = "success";
2222exports.GITHUB_STATUS_FAILURE = "failure";
2323exports.GITHUB_STATUS_CANCELLED = "cancelled";
2424exports.GITHUB_STATUS_TIMED_OUT = "timed_out";
25- exports.GITHUB_STATUS_SKIPPED = "skipped";
2625
2726
2827/***/ }),
@@ -236,9 +235,16 @@ function analyzeJobSteps(steps) {
236235 return constants_1.GITHUB_STATUS_SUCCESS;
237236}
238237/**
239- * Determines workflow status by checking if any main steps failed
238+ * Determines job status by checking if any main steps failed.
240239 * When post actions run, all main steps have completed but post steps are still pending.
241- * We only examine main steps to determine if the workflow succeeded up to this point.
240+ * We only examine main steps to determine if the job succeeded up to this point.
241+ *
242+ * Job identification strategy:
243+ * 1. Match GITHUB_JOB against the API job name (works when no custom name: attribute).
244+ * 2. Fallback: find the single in_progress job (our job is always in_progress while
245+ * its post steps run; completed jobs have finished all post steps).
246+ * 3. If multiple jobs are in_progress (parallel execution), we check ALL of them
247+ * for failures — conservative approach when we can't pinpoint our exact job.
242248 */
243249async function determineJobStatus() {
244250 try {
@@ -259,12 +265,43 @@ async function determineJobStatus() {
259265 jobs.jobs.forEach((job) => {
260266 core.info(` - Job: ${job.name}, Status: ${job.status}, Conclusion: ${job.conclusion}, Steps: ${job.steps?.length || 0}`);
261267 });
262- // Find the current job (case-insensitive comparison)
263- const currentJob = jobs.jobs.find((job) => job.name.toLowerCase() === env.jobName.toLowerCase());
268+ // Find the current job:
269+ // 1. Primary: match GITHUB_JOB (yaml key) against job name.
270+ // Works when the job has no custom `name:` attribute.
271+ // 2. Fallback: find the job that is still in_progress.
272+ // When our post step runs, our job is always in_progress (post steps
273+ // are part of the job). Completed jobs have already finished all their
274+ // post steps. This handles the case where a custom `name:` attribute
275+ // makes GITHUB_JOB (yaml key) differ from the API name (display name).
276+ let currentJob;
277+ // Try name match first (works when no custom name: attribute)
278+ currentJob = jobs.jobs.find((job) => job.name.toLowerCase() === env.jobName.toLowerCase());
264279 if (currentJob) {
265- core.info(`✓ Found current job: ${currentJob.name}`);
266- core.info(` Status: ${currentJob.status}, Conclusion: ${currentJob.conclusion || "null"}`);
267- core.info(` Steps count: ${currentJob.steps?.length || 0}`);
280+ core.info(`✓ Found current job by name: ${currentJob.name}`);
281+ }
282+ // Fallback: match by in_progress status
283+ if (!currentJob) {
284+ const inProgressJobs = jobs.jobs.filter((job) => job.status === "in_progress");
285+ if (inProgressJobs.length === 1) {
286+ currentJob = inProgressJobs[0];
287+ core.info(`✓ Found current job by in_progress status: ${currentJob.name}`);
288+ }
289+ else if (inProgressJobs.length > 1) {
290+ // Multiple jobs running concurrently — check all for failures
291+ core.info(`Found ${inProgressJobs.length} in_progress jobs, analyzing all for failures`);
292+ for (const job of inProgressJobs) {
293+ if (job.steps && job.steps.length > 0) {
294+ const result = analyzeJobSteps(job.steps);
295+ if (result === constants_1.GITHUB_STATUS_FAILURE) {
296+ return constants_1.GITHUB_STATUS_FAILURE;
297+ }
298+ }
299+ }
300+ return constants_1.GITHUB_STATUS_SUCCESS;
301+ }
302+ }
303+ if (currentJob) {
304+ core.info(` Status: ${currentJob.status}, Conclusion: ${currentJob.conclusion || "null"}, Steps: ${currentJob.steps?.length || 0}`);
268305 // Check individual step statuses
269306 if (currentJob.steps && currentJob.steps.length > 0) {
270307 return analyzeJobSteps(currentJob.steps);
@@ -307,17 +344,17 @@ async function determineJobStatus() {
307344 }
308345}
309346async function runPost() {
310- core.info("🏁 Notifying Fly that CI job has ended...");
311- const flyUrl = core.getState(constants_1.STATE_FLY_URL); // Corrected constant
312- const accessToken = core.getState(constants_1.STATE_FLY_ACCESS_TOKEN); // Corrected constant
347+ const flyUrl = core.getState(constants_1.STATE_FLY_URL);
348+ const accessToken = core.getState(constants_1.STATE_FLY_ACCESS_TOKEN);
313349 if (!flyUrl) {
314- core.info("No Fly URL found in state, skipping CI end notification"); // Changed from debug to info
350+ core.info("No Fly URL found in state, skipping CI end notification");
315351 return;
316352 }
317353 if (!accessToken) {
318- core.info("No access token found in state, skipping CI end notification"); // Changed from debug to info
354+ core.info("No access token found in state, skipping CI end notification");
319355 return;
320356 }
357+ core.info("🏁 Notifying Fly that CI job has ended...");
321358 const packageManagersState = core.getState(constants_1.STATE_FLY_PACKAGE_MANAGERS);
322359 let packageManagers = [];
323360 if (packageManagersState) {
0 commit comments