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 a83897e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 65 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
108 changes: 43 additions & 65 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,69 +107,54 @@ 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
- name: Detect child workflows
id: detect-workflows
uses: actions/github-script@v7
id: wait-for-workflows
with:
script: |
const runIds = core.getInput('run-ids').split(',');
const checkInterval = 60000; // 1 minute
const maxAttempts = 60; // 60 minutes max wait
let completedRuns = 0;
let failedRuns = 0;
const identifiers = '${{ steps.trigger-workflows.outputs.result }}'.split(',');
const startTime = process.env.current_time;
let detectedRuns = [];
for (let attempt = 0; attempt < maxAttempts; attempt++) {
completedRuns = 0;
failedRuns = 0;
for (const runId of runIds) {
const { data: run } = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runId
for (const identifier of identifiers) {
const { data: runs } = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: process.env.ASSISTANT_WORKFLOW_ID,
created: `>${startTime}`
});
console.log(runs.workflow_runs);
const matchingRun = runs.workflow_runs.find(run => run.display_title.includes(identifier));
if (matchingRun) {
detectedRuns.push({
id: matchingRun.id,
html_url: matchingRun.html_url,
identifier: identifier
});
if (run.status === 'completed') {
completedRuns++;
if (run.conclusion !== 'success') {
failedRuns++;
}
}
}
if (completedRuns === runIds.length) {
break;
}
await new Promise(resolve => setTimeout(resolve, checkInterval));
}
if (failedRuns > 0) {
core.setFailed(`${failedRuns} workflows failed.`);
} else {
core.info('All workflows completed successfully.');
core.setOutput('detected_runs', JSON.stringify(detectedRuns));
console.log(detectedRuns);
env:
run-ids: ${{ steps.get-launched-runs.outputs.result }}
- name: Display detected workflow URLs
id: display-urls
run: |
detected_runs=${{ steps.detect-workflows.outputs.detected_runs }}
echo "Detected workflow runs:"
echo "${detected_runs}" | jq -c '.[]' | while read -r run; do
id=$(echo "${run}" | jq -r '.id')
url=$(echo "${run}" | jq -r '.html_url')
identifier=$(echo "${run}" | jq -r '.identifier')
echo "Run ID: ${id}, Identifier: ${identifier}, URL: ${url}"
done

0 comments on commit a83897e

Please sign in to comment.