From b3ff843d1ccf452c8778cfb0fdaa2478bed442b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Correa=20Rodr=C3=ADguez?= Date: Wed, 4 Sep 2024 12:27:47 +0200 Subject: [PATCH] Tier waits child runs --- .../workflows/Test_installation_assistant.yml | 3 + .../Test_installation_assistant_tier.yml | 73 ++++++++----------- 2 files changed, 34 insertions(+), 42 deletions(-) diff --git a/.github/workflows/Test_installation_assistant.yml b/.github/workflows/Test_installation_assistant.yml index 3eceaa0..cb65b03 100644 --- a/.github/workflows/Test_installation_assistant.yml +++ b/.github/workflows/Test_installation_assistant.yml @@ -81,6 +81,9 @@ jobs: runs-on: ubuntu-latest steps: + - name: Finish + run: exit 0 + - name: Checkout code uses: actions/checkout@v4 diff --git a/.github/workflows/Test_installation_assistant_tier.yml b/.github/workflows/Test_installation_assistant_tier.yml index a5f3c1e..932a32c 100644 --- a/.github/workflows/Test_installation_assistant_tier.yml +++ b/.github/workflows/Test_installation_assistant_tier.yml @@ -83,17 +83,9 @@ jobs: echo "systems=${SELECTED_SYSTEMS[@]}" >> $GITHUB_ENV - - name: Get initial workflow runs - id: get-initial-runs - uses: actions/github-script@v7 - with: - script: | - const { data } = await github.rest.actions.listWorkflowRunsForRepo({ - owner: context.repo.owner, - repo: context.repo.repo, - status: 'in_progress' - }); - return data.workflow_runs.map(run => run.id).join(','); + - name: Get current time + id: get-current-time + run: echo "current_time=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV - name: Trigger system-specific workflows asynchronously id: trigger-workflows @@ -103,7 +95,8 @@ jobs: const workflowId = process.env.ASSISTANT_WORKFLOW_ID; const systems = process.env.systems.split(" "); - const promises = systems.map(system => { + const promises = systems.map((system, index) => { + const identifier = `${system}-${Date.now()}`; return github.rest.actions.createWorkflowDispatch({ owner: context.repo.owner, repo: context.repo.repo, @@ -114,35 +107,26 @@ jobs: AUTOMATION_REFERENCE: '${{ inputs.AUTOMATION_REFERENCE }}', SYSTEM: system, VERBOSITY: '${{ inputs.VERBOSITY }}', - DESTROY: '${{ inputs.DESTROY }}' + DESTROY: '${{ inputs.DESTROY }}', + IDENTIFIER: identifier } - }); + }).then(() => identifier); }); - - await Promise.all(promises); - - name: Get launched workflow runs - id: get-launched-runs - uses: actions/github-script@v7 - with: - script: | - const initialRunIds = '${{ steps.get-initial-runs.outputs.result }}'.split(','); - const { data: runs } = await github.rest.actions.listWorkflowRunsForRepo({ - owner: context.repo.owner, - repo: context.repo.repo, - status: 'in_progress' - }); - const newRuns = runs.filter(run => !initialRunIds.includes(run.id.toString())); - return newRuns.map(run => run.id).join(','); + const identifiers = await Promise.all(promises); + return identifiers.join(','); - name: Wait for child workflows to complete - uses: actions/github-script@v7 id: wait-for-workflows + uses: actions/github-script@v7 with: script: | - const runIds = core.getInput('run-ids').split(','); - const checkInterval = 60000; // 1 minute - const maxAttempts = 60; // 60 minutes max wait + const identifiers = '${{ steps.trigger-workflows.outputs.result }}'.split(','); + const checkInterval = 60000; // ms = 1 minute + const maxAttempts = 15; // 15 min max wait time + const workflowId = process.env.ASSISTANT_WORKFLOW_ID; + const actorName = 'github-actions[bot]'; + const startTime = process.env.current_time; let completedRuns = 0; let failedRuns = 0; @@ -151,22 +135,29 @@ jobs: completedRuns = 0; failedRuns = 0; - for (const runId of runIds) { - const { data: run } = await github.rest.actions.getWorkflowRun({ + const { data: runs } = await github.rest.actions.listWorkflowRuns({ owner: context.repo.owner, repo: context.repo.repo, - run_id: runId + workflow_id: workflowId, + created: `>${startTime}`, + status: 'completed', + actor: actorName }); + + // const filteredRuns = runs.workflow_runs.filter(run => run.actor.login === actor); - if (run.status === 'completed') { + console.log(runs.workflow_runs); + for (const identifier of identifiers) { + const matchingRun = filteredRuns.find(run => run.display_title.includes(identifier)); + if (matchingRun) { completedRuns++; - if (run.conclusion !== 'success') { + if (matchingRun.conclusion !== 'success') { failedRuns++; } } } - if (completedRuns === runIds.length) { + if (completedRuns === identifiers.length) { break; } @@ -177,6 +168,4 @@ jobs: core.setFailed(`${failedRuns} workflows failed.`); } else { core.info('All workflows completed successfully.'); - - env: - run-ids: ${{ steps.get-launched-runs.outputs.result }} \ No newline at end of file + } \ No newline at end of file