@@ -265,6 +265,8 @@ func ExecuteAtmosVendorInternal(
265
265
return fmt .Errorf ("either 'spec.sources' or 'spec.imports' (or both) must be defined in the vendor config file '%s'" , vendorConfigFileName )
266
266
}
267
267
268
+ var tempDir string
269
+
268
270
// Process imports and return all sources from all the imports and from `vendor.yaml`
269
271
sources , _ , err := processVendorImports (
270
272
atmosConfig ,
@@ -314,6 +316,16 @@ func ExecuteAtmosVendorInternal(
314
316
)
315
317
}
316
318
319
+ tempDir , err = os .MkdirTemp ("" , "atmos_vendor_" )
320
+ if err != nil {
321
+ return fmt .Errorf ("failed to create temp directory: %w" , err )
322
+ }
323
+ defer func () {
324
+ if err := os .RemoveAll (tempDir ); err != nil {
325
+ u .LogWarning (atmosConfig , fmt .Sprintf ("failed to clean up temp directory %s: %v" , tempDir , err ))
326
+ }
327
+ }()
328
+
317
329
// Allow having duplicate targets in different sources.
318
330
// This can be used to vendor mixins (from local and remote sources) and write them to the same targets.
319
331
// TODO: consider adding a flag to `atmos vendor pull` to specify if duplicate targets are allowed or not.
@@ -356,7 +368,24 @@ func ExecuteAtmosVendorInternal(
356
368
return err
357
369
}
358
370
359
- useOciScheme , useLocalFileSystem , sourceIsLocalFile := determineSourceType (& uri , vendorConfigFilePath )
371
+ useOciScheme , useLocalFileSystem , sourceIsLocalFile , isGitHubSource := determineSourceType (& uri , vendorConfigFilePath )
372
+
373
+ // Handle GitHub source
374
+ if isGitHubSource {
375
+ u .LogInfo (atmosConfig , fmt .Sprintf ("Fetching GitHub source: %s" , uri ))
376
+ fileContents , err := u .DownloadFileFromGitHub (uri )
377
+ if err != nil {
378
+ return fmt .Errorf ("failed to download GitHub file: %w" , err )
379
+ }
380
+ // Save the downloaded file to the existing tempDir
381
+ tempGitHubFile := filepath .Join (tempDir , filepath .Base (uri ))
382
+ err = os .WriteFile (tempGitHubFile , fileContents , os .ModePerm )
383
+ if err != nil {
384
+ return fmt .Errorf ("failed to save GitHub file to temp location: %w" , err )
385
+ }
386
+ // Update the URI to point to the saved file in the temp directory
387
+ uri = tempGitHubFile
388
+ }
360
389
361
390
// Determine package type
362
391
var pType pkgType
@@ -494,23 +523,32 @@ func shouldSkipSource(s *schema.AtmosVendorSource, component string, tags []stri
494
523
return (component != "" && s .Component != component ) || (len (tags ) > 0 && len (lo .Intersect (tags , s .Tags )) == 0 )
495
524
}
496
525
497
- func determineSourceType (uri * string , vendorConfigFilePath string ) (bool , bool , bool ) {
498
- // Determine if the URI is an OCI scheme, a local file, or remote
526
+ func determineSourceType (uri * string , vendorConfigFilePath string ) (bool , bool , bool , bool ) {
527
+ // Determine if the URI is an OCI scheme, a local file, a remote GitHub source, or a generic remote
499
528
useOciScheme := strings .HasPrefix (* uri , "oci://" )
500
529
if useOciScheme {
501
530
* uri = strings .TrimPrefix (* uri , "oci://" )
502
531
}
503
532
504
533
useLocalFileSystem := false
505
534
sourceIsLocalFile := false
535
+ isGitHubSource := false
536
+
506
537
if ! useOciScheme {
507
- if absPath , err := u .JoinAbsolutePathWithPath (vendorConfigFilePath , * uri ); err == nil {
508
- uri = & absPath
509
- useLocalFileSystem = true
510
- sourceIsLocalFile = u .FileExists (* uri )
538
+ if strings .Contains (* uri , "github.com" ) {
539
+ // Check if the URL is a GitHub source
540
+ isGitHubSource = true
541
+ } else {
542
+ // Handle local file system sources
543
+ if absPath , err := u .JoinAbsolutePathWithPath (vendorConfigFilePath , * uri ); err == nil {
544
+ uri = & absPath
545
+ useLocalFileSystem = true
546
+ sourceIsLocalFile = u .FileExists (* uri )
547
+ }
511
548
}
512
549
}
513
- return useOciScheme , useLocalFileSystem , sourceIsLocalFile
550
+
551
+ return useOciScheme , useLocalFileSystem , sourceIsLocalFile , isGitHubSource
514
552
}
515
553
516
554
func copyToTarget (atmosConfig schema.AtmosConfiguration , tempDir , targetPath string , s * schema.AtmosVendorSource , sourceIsLocalFile bool , uri string ) error {
0 commit comments