Skip to content

Commit

Permalink
Tier waits child runs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcr01 committed Sep 4, 2024
1 parent c745143 commit 9cde886
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/Test_installation_assistant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Finish
run: exit 0

- name: Checkout code
uses: actions/checkout@v4

Expand Down
69 changes: 26 additions & 43 deletions .github/workflows/Test_installation_assistant_tier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,6 @@ 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: Trigger system-specific workflows asynchronously
id: trigger-workflows
uses: actions/github-script@v7
Expand All @@ -103,7 +91,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,
Expand All @@ -114,35 +103,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);
console.log(identifiers);
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; // 1 minuto
const maxAttempts = 60; // 60 minutos de espera máxima
const workflowId = process.env.ASSISTANT_WORKFLOW_ID;
const actor = 'github-actions[bot]';
let completedRuns = 0;
let failedRuns = 0;
Expand All @@ -151,22 +131,27 @@ 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,
status: 'completed'
});
const filteredRuns = runs.workflow_runs.filter(run => run.actor.login === actor);
if (run.status === 'completed') {
console.log(filteredRuns)
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;
}
Expand All @@ -177,6 +162,4 @@ jobs:
core.setFailed(`${failedRuns} workflows failed.`);
} else {
core.info('All workflows completed successfully.');
env:
run-ids: ${{ steps.get-launched-runs.outputs.result }}
}

0 comments on commit 9cde886

Please sign in to comment.