@@ -9,6 +9,7 @@ struct PackageDependency: Codable {
9
9
10
10
struct SwiftPUrl : Codable , RawRepresentable {
11
11
let scheme : String , type : String , source : String , name : String , version : String
12
+
12
13
var rawValue : String { " \( self . scheme) : \( self . type) / \( self . source) / \( self . name) @ \( self . version) " }
13
14
14
15
init ? ( rawValue raw: String ) {
@@ -33,21 +34,28 @@ struct GithubDependencyGraph: Codable {
33
34
struct Manifest : Codable {
34
35
struct File : Codable { let source_location : String }
35
36
struct Package : Codable {
36
- let package_url : SwiftPUrl , scope : String , dependencies : [ String ]
37
- init ( package_url: SwiftPUrl , dependencies: [ String ] ) {
38
- ( self . package_url, self . scope, self . dependencies) = ( package_url, " runtime " , dependencies)
37
+ let package_url : SwiftPUrl , scope : String , relationship : String , dependencies : [ String ]
38
+ init ( package_url: SwiftPUrl , dependencies: [ String ] , relationship: String ) {
39
+ self . package_url = package_url
40
+ self . scope = " runtime "
41
+ self . dependencies = dependencies
42
+ self . relationship = relationship
39
43
}
40
44
}
41
- let name : String , file : File , resolved : [ String : Package ]
45
+ let name : String , file : File , resolved : [ SwiftPUrl : Package ]
42
46
}
43
47
let version : Int , sha : String , ref : String , job : Job , detector : Detector ,
44
48
scanned : Date , manifests : [ String : Manifest ]
45
49
}
46
50
51
+ func fail( _ message: @autoclosure ( ) -> String ) -> Never {
52
+ try ? FileHandle . standardError. write ( contentsOf: Array ( " \( message ( ) ) \n " . utf8) )
53
+ exit ( 1 )
54
+ }
55
+
47
56
func env( _ name: String ) -> String {
48
57
guard let value = ProcessInfo . processInfo. environment [ name] else {
49
- try ? FileHandle . standardError. write ( contentsOf: Array ( " Incomplete environment: \( name) . \n " . utf8) )
50
- exit ( 1 )
58
+ fail ( " Incomplete environment: \( name) " )
51
59
}
52
60
return value
53
61
}
@@ -58,42 +66,45 @@ func main() {
58
66
encoder. dateEncodingStrategy = . iso8601
59
67
encoder. outputFormatting = [ . withoutEscapingSlashes, . sortedKeys]
60
68
61
- let branch = env ( " BRANCH " ) , commit = env ( " COMMIT " ) , correlator = env ( " CORRELATOR " ) ,
62
- runId = env ( " RUN_ID " ) , detector = env ( " GITHUB_ACTION " ) , detectorVer = env ( " GITHUB_ACTION_REF " ) ,
63
- detectorRepo = env ( " GITHUB_ACTION_REPOSITORY " ) , serverUrl = env ( " GITHUB_SERVER_URL " )
69
+ let branch = env ( " BRANCH " ) ,
70
+ commit = env ( " COMMIT " ) ,
71
+ correlator = env ( " CORRELATOR " ) ,
72
+ runId = env ( " GITHUB_RUN_ID " ) ,
73
+ detectorVer = env ( " GITHUB_ACTION_REF " ) ,
74
+ serverUrl = env ( " GITHUB_SERVER_URL " )
64
75
65
- let dependencies = try ! decoder. decode (
76
+ let topLevelDependencies = try ! decoder. decode (
66
77
PackageDependency . self,
67
78
from: FileHandle . standardInput. readToEnd ( ) ?? . init( )
68
79
) . dependencies
69
80
70
- var resolved = [ String : GithubDependencyGraph . Manifest. Package] ( )
81
+ var resolved = [ SwiftPUrl : GithubDependencyGraph . Manifest. Package] ( )
71
82
72
83
func handleDeps( _ dependencies: [ PackageDependency ] ) {
73
84
for dep in dependencies where !resolved. keys. contains ( dep. identity) {
74
85
handleDeps ( dep. dependencies)
75
86
guard !resolved. keys. contains ( dep. identity) else { continue }
76
87
guard let url = URL ( string: dep. url) else {
77
- try ? FileHandle . standardError. write ( contentsOf: Array ( " Invalid URL for package \( dep. identity) \n " . utf8) )
78
- exit ( 1 )
88
+ fail ( " Invalid URL for package \( dep. identity) " )
79
89
}
80
- resolved [ dep. identity ] = . init(
90
+ resolved [ . init ( with : url , version : dep. version ) ] = . init(
81
91
package_url: . init( with: url, version: dep. version) ,
82
92
dependencies: dep. dependencies. map {
83
93
SwiftPUrl ( with: URL ( string: $0. url) !, version: $0. version) . rawValue
84
- } . sorted ( )
94
+ } . sorted ( ) ,
95
+ relationship: topLevelDependencies. map ( \. identity) . contains ( dep. identity) ? " direct " : " indirect "
85
96
)
86
97
}
87
98
}
88
- handleDeps ( dependencies )
99
+ handleDeps ( topLevelDependencies )
89
100
90
101
let graph = GithubDependencyGraph (
91
102
version: 0 , sha: commit, ref: branch,
92
103
job: . init( correlator: correlator, id: runId) ,
93
104
detector: . init(
94
- name: . init ( detector . drop ( while : { $0 == " _ " } ) . prefix ( while : { $0 != " _ " } ) ) ,
105
+ name: " vapor-community/swift-dependency-submission " ,
95
106
version: detectorVer. isEmpty ? " v0 " : detectorVer,
96
- url: " \( serverUrl) / \( detectorRepo . isEmpty ? " vapor/ci " : detectorRepo ) "
107
+ url: " \( serverUrl) /vapor-community/swift-dependency-submission "
97
108
) ,
98
109
scanned: Date ( ) ,
99
110
manifests: [ " Package.resolved " : . init(
0 commit comments