downloadIncludeFromWorkflowSpec downloads an include file from GitHub using workflowspec It first checks the cache, and only downloads if not cached
(spec string, cache *ImportCache)
| 346 | // downloadIncludeFromWorkflowSpec downloads an include file from GitHub using workflowspec |
| 347 | // It first checks the cache, and only downloads if not cached |
| 348 | func downloadIncludeFromWorkflowSpec(spec string, cache *ImportCache) (string, error) { |
| 349 | remoteLog.Printf("Downloading from workflowspec: %s", spec) |
| 350 | owner, repo, filePath, ref, err := parseWorkflowSpecParts(spec) |
| 351 | if err != nil { |
| 352 | return "", err |
| 353 | } |
| 354 | remoteLog.Printf("Parsed workflowspec: owner=%s, repo=%s, file=%s, ref=%s", owner, repo, filePath, ref) |
| 355 | |
| 356 | sha := resolveWorkflowSpecSHAForCache(owner, repo, ref, cache) |
| 357 | if cache != nil && sha != "" { |
| 358 | if cachedPath, found := cache.Get(owner, repo, filePath, sha); found { |
| 359 | remoteLog.Printf("Using cached import: %s/%s/%s@%s (SHA: %s)", owner, repo, filePath, ref, sha) |
| 360 | return cachedPath, nil |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | remoteLog.Printf("Fetching file from GitHub: %s/%s/%s@%s", owner, repo, filePath, ref) |
| 365 | content, err := downloadFileFromGitHub(owner, repo, filePath, ref) |
| 366 | if err != nil { |
| 367 | return "", fmt.Errorf("failed to download include from %s: %w", spec, err) |
| 368 | } |
| 369 | remoteLog.Printf("Successfully downloaded file: size=%d bytes", len(content)) |
| 370 | |
| 371 | if cache != nil && sha != "" { |
| 372 | cachedPath, err := cache.Set(owner, repo, filePath, sha, content) |
| 373 | if err != nil { |
| 374 | remoteLog.Printf("Failed to cache import: %v", err) |
| 375 | } else { |
| 376 | remoteLog.Printf("Successfully cached download at: %s", cachedPath) |
| 377 | return cachedPath, nil |
| 378 | } |
| 379 | } |
| 380 | return writeDownloadedIncludeToTempFile(content) |
| 381 | } |
| 382 | |
| 383 | func parseWorkflowSpecParts(spec string) (string, string, string, string, error) { |
| 384 | cleanSpec := spec |