From 6af32201297ce5cf5b9a76a3e1c54bf0762a96b6 Mon Sep 17 00:00:00 2001 From: auricom <27022259+auricom@users.noreply.github.com> Date: Wed, 4 Dec 2024 09:34:48 +0100 Subject: [PATCH] ci: fix notifications --- .github/workflows/build-applications.yaml | 73 ++++++++++++++++------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build-applications.yaml b/.github/workflows/build-applications.yaml index 4b1dab1..aaf7042 100644 --- a/.github/workflows/build-applications.yaml +++ b/.github/workflows/build-applications.yaml @@ -436,36 +436,63 @@ jobs: with: script: | const branch = context.ref.replace('refs/heads/', ''); - const runs = await github.rest.actions.listWorkflowRuns({ - owner: context.repo.owner, - repo: context.repo.repo, - workflow_id: 'nightlies-scheduled.yaml', - branch: branch, - status: 'completed', - per_page: 1 - }); - return runs.data.workflow_runs[0].id; + try { + const runs = await github.rest.actions.listWorkflowRuns({ + owner: context.repo.owner, + repo: context.repo.repo, + workflow_id: 'nightlies-scheduled.yaml', + branch: branch, + status: 'completed', + per_page: 1 + }); + + if (!runs.data.workflow_runs.length) { + console.log('No previous workflow runs found'); + return ''; + } + return runs.data.workflow_runs[0].id; + } catch (error) { + console.error('Error fetching workflow runs:', error); + return ''; + } - name: Check specific matrix job id: check-matrix - if: steps.get-previous-run.outputs.result + if: steps.get-previous-run.outputs.result != '' uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7 with: script: | const run_id = ${{ steps.get-previous-run.outputs.result }}; - const jobs = await github.rest.actions.listJobsForWorkflowRun({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: run_id - }); - - const specificJob = jobs.data.jobs.find(job => - job.name === 'Build Images / Merge ${{ matrix.app.name }} ${{ matrix.app.channel }}' - ); - - const wasSuccessful = specificJob && specificJob.conclusion === 'success'; - console.log(`The specific matrix job was ${wasSuccessful ? 'successful' : 'not successful'}`); - core.setOutput('was-successful', wasSuccessful); + try { + const jobs = await github.rest.actions.listJobsForWorkflowRun({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: run_id + }); + + const expectedJobName = `Build Images / Merge ${context.payload.inputs.app_name} ${context.payload.inputs.channel}`; + console.log('Looking for job with name:', expectedJobName); + + console.log('Available jobs:'); + jobs.data.jobs.forEach(job => { + console.log(`- ${job.name} (${job.conclusion})`); + }); + + const specificJob = jobs.data.jobs.find(job => job.name === expectedJobName); + + if (!specificJob) { + console.log('Job not found!'); + core.setOutput('was-successful', false); + return; + } + + const wasSuccessful = specificJob.conclusion === 'success'; + console.log(`Found job. Conclusion: ${specificJob.conclusion}`); + core.setOutput('was-successful', wasSuccessful); + } catch (error) { + console.error('Error checking job status:', error); + core.setOutput('was-successful', false); + } # - name: Notify Slack # if: inputs.sendNotifications == 'true' && ((steps.check-matrix.outputs.was-successful && env.app_status != 'true') || (!steps.check-matrix.outputs.was-successful && env.app_status == 'true'))