Skip to content

Commit 013344c

Browse files
Merge pull request #3298 from SwiftPackageIndex/limit-package-update-on-build
Don't bump packages.update_at when receiving build reports
2 parents 4556da4 + 49e1446 commit 013344c

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

Sources/App/Models/Package.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,7 @@ extension Package {
258258
AND b.status = 'ok'
259259
GROUP BY b.platform
260260
HAVING count(*) > 0
261-
),
262-
updated_at = NOW()
261+
)
263262
WHERE p.id = \#(bind: packageId)
264263
"""#
265264
).run()

Tests/AppTests/ApiTests.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,50 @@ class ApiTests: AppTestCase {
408408
})
409409
}
410410

411+
func test_post_buildReport_package_updatedAt() async throws {
412+
// Ensure we don't change packages.updatedAt when receiving a build report.
413+
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/3290#issuecomment-2293101104
414+
// setup
415+
Current.builderToken = { "secr3t" }
416+
let p = try savePackage(on: app.db, "1")
417+
let originalPackageUpdate = p.updatedAt
418+
let v = try Version(package: p, latest: .defaultBranch)
419+
try await v.save(on: app.db)
420+
let versionId = try v.requireID()
421+
422+
// MUT
423+
let dto: API.PostBuildReportDTO = .init(
424+
buildCommand: "xcodebuild -scheme Foo",
425+
buildDate: .t0,
426+
buildDuration: 123.4,
427+
buildErrors: .init(numSwift6Errors: 42),
428+
builderVersion: "1.2.3",
429+
buildId: .id0,
430+
commitHash: "sha",
431+
jobUrl: "https://example.com/jobs/1",
432+
logUrl: "log url",
433+
platform: .macosXcodebuild,
434+
productDependencies: [.init(identity: "identity", name: "name", url: "url", dependencies: [])],
435+
resolvedDependencies: [.init(packageName: "packageName", repositoryURL: "repositoryURL")],
436+
runnerId: "some-runner",
437+
status: .failed,
438+
swiftVersion: .init(5, 2, 0)
439+
)
440+
let encoder = JSONEncoder()
441+
encoder.dateEncodingStrategy = .secondsSince1970
442+
let body: ByteBuffer = .init(data: try encoder.encode(dto))
443+
try await app.test(
444+
.POST,
445+
"api/versions/\(versionId)/build-report",
446+
headers: .bearerApplicationJSON("secr3t"),
447+
body: body,
448+
afterResponse: { res async throws in
449+
// validation
450+
let p = try await XCTUnwrapAsync(await Package.find(p.id, on: app.db))
451+
XCTAssertEqual(p.updatedAt, originalPackageUpdate)
452+
})
453+
}
454+
411455
func test_post_docReport() async throws {
412456
// setup
413457
Current.builderToken = { "secr3t" }

0 commit comments

Comments
 (0)