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 dfe6339
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 54 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
103 changes: 49 additions & 54 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,71 @@ 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
const identifiers = '${{ steps.trigger-workflows.outputs.result }}'.split(',');
const startTime = process.env.current_time;
const maxAttempts = 20; // Intentos máximos para detectar todos los runs
const checkInterval = 60000; // 1 minuto de espera entre intentos
let completedRuns = 0;
let failedRuns = 0;
let detectedRuns = [];
for (let attempt = 0; attempt < maxAttempts; attempt++) {
completedRuns = 0;
failedRuns = 0;
detectedRuns = []; // Reiniciar la lista de detectedRuns en cada intento
for (const runId of runIds) {
const { data: run } = await github.rest.actions.getWorkflowRun({
for (const identifier of identifiers) {
const { data: runs } = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runId
workflow_id: process.env.ASSISTANT_WORKFLOW_ID,
status: 'in_progress',
created: `>${startTime}`
});
if (run.status === 'completed') {
completedRuns++;
if (run.conclusion !== 'success') {
failedRuns++;
}
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 (completedRuns === runIds.length) {
break;
if (detectedRuns.length === identifiers.length) {
break; // Todos los runs han sido detectados, salir del bucle
}
// Esperar un minuto antes de volver a intentar
await new Promise(resolve => setTimeout(resolve, checkInterval));
}
if (failedRuns > 0) {
core.setFailed(`${failedRuns} workflows failed.`);
} else {
core.info('All workflows completed successfully.');
if (detectedRuns.length !== identifiers.length) {
core.setFailed('Not all workflow runs were detected within the allowed time.');
}
env:
run-ids: ${{ steps.get-launched-runs.outputs.result }}
core.setOutput('detected_runs', JSON.stringify(detectedRuns));
- 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 dfe6339

Please sign in to comment.