mirror of
https://github.com/PlaneQuery/OpenAirframes.git
synced 2026-08-30 19:00:36 +02:00
feat: implement download and concatenate script for workflow artifacts
This commit is contained in:
@@ -38,7 +38,7 @@ def generate_date_chunks(start_date_str, end_date_str, chunk_days=15):
|
||||
return chunks
|
||||
|
||||
|
||||
def trigger_workflow(start_date, end_date, chunk_days=3, branch='main', dry_run=False):
|
||||
def trigger_workflow(start_date, end_date, chunk_days=1, branch='main', dry_run=False):
|
||||
"""Trigger the historical-adsb workflow via GitHub CLI."""
|
||||
cmd = [
|
||||
'gh', 'workflow', 'run', 'historical-adsb.yaml',
|
||||
@@ -50,18 +50,36 @@ def trigger_workflow(start_date, end_date, chunk_days=3, branch='main', dry_run=
|
||||
|
||||
if dry_run:
|
||||
print(f"[DRY RUN] Would run: {' '.join(cmd)}")
|
||||
return True
|
||||
return True, None
|
||||
|
||||
print(f"Triggering workflow: {start_date} to {end_date} (on {branch})")
|
||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||
|
||||
if result.returncode == 0:
|
||||
print(f"✓ Successfully triggered workflow for {start_date} to {end_date}")
|
||||
return True
|
||||
|
||||
# Get the run ID of the workflow we just triggered
|
||||
# Wait a moment for it to appear
|
||||
import time
|
||||
time.sleep(2)
|
||||
|
||||
# Get the most recent run (should be the one we just triggered)
|
||||
list_cmd = [
|
||||
'gh', 'run', 'list',
|
||||
'--workflow', 'historical-adsb.yaml',
|
||||
'--branch', branch,
|
||||
'--limit', '1',
|
||||
'--json', 'databaseId',
|
||||
'--jq', '.[0].databaseId'
|
||||
]
|
||||
list_result = subprocess.run(list_cmd, capture_output=True, text=True)
|
||||
run_id = list_result.stdout.strip() if list_result.returncode == 0 else None
|
||||
|
||||
return True, run_id
|
||||
else:
|
||||
print(f"✗ Failed to trigger workflow for {start_date} to {end_date}")
|
||||
print(f"Error: {result.stderr}")
|
||||
return False
|
||||
return False, None
|
||||
|
||||
|
||||
def main():
|
||||
@@ -81,8 +99,8 @@ def main():
|
||||
parser.add_argument(
|
||||
'--chunk-days',
|
||||
type=int,
|
||||
default=3,
|
||||
help='Days per job chunk within each workflow run (default: 3)'
|
||||
default=1,
|
||||
help='Days per job chunk within each workflow run (default: 1)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--workflow-chunk-days',
|
||||
@@ -139,18 +157,27 @@ def main():
|
||||
# Trigger workflows
|
||||
import time
|
||||
success_count = 0
|
||||
triggered_runs = []
|
||||
|
||||
for i, chunk in enumerate(chunks, 1):
|
||||
print(f"\n[{i}/{len(chunks)}] ", end='')
|
||||
|
||||
if trigger_workflow(
|
||||
success, run_id = trigger_workflow(
|
||||
chunk['start'],
|
||||
chunk['end'],
|
||||
chunk_days=args.chunk_days,
|
||||
branch=args.branch,
|
||||
dry_run=args.dry_run
|
||||
):
|
||||
)
|
||||
|
||||
if success:
|
||||
success_count += 1
|
||||
if run_id:
|
||||
triggered_runs.append({
|
||||
'run_id': run_id,
|
||||
'start': chunk['start'],
|
||||
'end': chunk['end']
|
||||
})
|
||||
|
||||
# Add delay between triggers (except for last one)
|
||||
if i < len(chunks) and not args.dry_run:
|
||||
@@ -158,6 +185,22 @@ def main():
|
||||
|
||||
print(f"\n\nSummary: {success_count}/{len(chunks)} workflows triggered successfully")
|
||||
|
||||
# Save triggered run IDs to a file
|
||||
if triggered_runs and not args.dry_run:
|
||||
import json
|
||||
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
|
||||
runs_file = f"./triggered_runs_{timestamp}.json"
|
||||
with open(runs_file, 'w') as f:
|
||||
json.dump({
|
||||
'start_date': args.start_date,
|
||||
'end_date': args.end_date,
|
||||
'branch': args.branch,
|
||||
'runs': triggered_runs
|
||||
}, f, indent=2)
|
||||
print(f"\nRun IDs saved to: {runs_file}")
|
||||
print(f"\nTo download and concatenate these artifacts, run:")
|
||||
print(f" python scripts/download_and_concat_runs.py {runs_file}")
|
||||
|
||||
if success_count < len(chunks):
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user