Skip to content

Commit 8f48aeb

Browse files
committed
[skip ci] Update to fix output
1 parent 9a3ca14 commit 8f48aeb

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

action.yml

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ runs:
3636
BRANCH: ${{ inputs.branch || github.ref }}
3737
COMMIT: ${{ inputs.commit || github.sha }}
3838
CORRELATOR: ${{ github.workflow_ref }}-${{ github.job }}-${{ github.action }}-${{ runner.os }}
39-
RUN_ID: ${{ github.run_id }}
4039
REPO_SPEC: ${{ inputs.repository || github.repository }}
4140
TOKEN: ${{ inputs.token || github.token }}
4241
shell: bash

convert-dependency-graph.swift

+29-18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ struct PackageDependency: Codable {
99

1010
struct SwiftPUrl: Codable, RawRepresentable {
1111
let scheme: String, type: String, source: String, name: String, version: String
12+
1213
var rawValue: String { "\(self.scheme):\(self.type)/\(self.source)/\(self.name)@\(self.version)" }
1314

1415
init?(rawValue raw: String) {
@@ -33,21 +34,28 @@ struct GithubDependencyGraph: Codable {
3334
struct Manifest: Codable {
3435
struct File: Codable { let source_location: String }
3536
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
3943
}
4044
}
41-
let name: String, file: File, resolved: [String: Package]
45+
let name: String, file: File, resolved: [SwiftPUrl: Package]
4246
}
4347
let version: Int, sha: String, ref: String, job: Job, detector: Detector,
4448
scanned: Date, manifests: [String: Manifest]
4549
}
4650

51+
func fail(_ message: @autoclosure () -> String) -> Never {
52+
try? FileHandle.standardError.write(contentsOf: Array("\(message())\n".utf8))
53+
exit(1)
54+
}
55+
4756
func env(_ name: String) -> String {
4857
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)")
5159
}
5260
return value
5361
}
@@ -58,42 +66,45 @@ func main() {
5866
encoder.dateEncodingStrategy = .iso8601
5967
encoder.outputFormatting = [.withoutEscapingSlashes, .sortedKeys]
6068

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")
6475

65-
let dependencies = try! decoder.decode(
76+
let topLevelDependencies = try! decoder.decode(
6677
PackageDependency.self,
6778
from: FileHandle.standardInput.readToEnd() ?? .init()
6879
).dependencies
6980

70-
var resolved = [String: GithubDependencyGraph.Manifest.Package]()
81+
var resolved = [SwiftPUrl: GithubDependencyGraph.Manifest.Package]()
7182

7283
func handleDeps(_ dependencies: [PackageDependency]) {
7384
for dep in dependencies where !resolved.keys.contains(dep.identity) {
7485
handleDeps(dep.dependencies)
7586
guard !resolved.keys.contains(dep.identity) else { continue }
7687
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)")
7989
}
80-
resolved[dep.identity] = .init(
90+
resolved[.init(with: url, version: dep.version)] = .init(
8191
package_url: .init(with: url, version: dep.version),
8292
dependencies: dep.dependencies.map {
8393
SwiftPUrl(with: URL(string: $0.url)!, version: $0.version).rawValue
84-
}.sorted()
94+
}.sorted(),
95+
relationship: topLevelDependencies.map(\.identity).contains(dep.identity) ? "direct" : "indirect"
8596
)
8697
}
8798
}
88-
handleDeps(dependencies)
99+
handleDeps(topLevelDependencies)
89100

90101
let graph = GithubDependencyGraph(
91102
version: 0, sha: commit, ref: branch,
92103
job: .init(correlator: correlator, id: runId),
93104
detector: .init(
94-
name: .init(detector.drop(while: { $0 == "_" }).prefix(while: { $0 != "_" })),
105+
name: "vapor-community/swift-dependency-submission",
95106
version: detectorVer.isEmpty ? "v0" : detectorVer,
96-
url: "\(serverUrl)/\(detectorRepo.isEmpty ? "vapor/ci" : detectorRepo)"
107+
url: "\(serverUrl)/vapor-community/swift-dependency-submission"
97108
),
98109
scanned: Date(),
99110
manifests: ["Package.resolved": .init(

0 commit comments

Comments
 (0)