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 b3ff843
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 42 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
73 changes: 31 additions & 42 deletions .github/workflows/Test_installation_assistant_tier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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 }}
}

0 comments on commit b3ff843

Please sign in to comment.