Skip to content

Commit 7f6318b

Browse files
committed
Enable cross-PR testing
1 parent d82d736 commit 7f6318b

File tree

4 files changed

+123
-10
lines changed

4 files changed

+123
-10
lines changed

.github/workflows/pull_request.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ jobs:
88
tests:
99
name: Test
1010
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
11-
soundness:
12-
name: Soundness
13-
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
1411
with:
15-
license_header_check_enabled: false
16-
license_header_check_project_name: "Swift.org"
12+
enable_windows_checks: false
13+
linux_pre_build_command: |
14+
swift cross-pr-checkout.swift
15+
# soundness:
16+
# name: Soundness
17+
# uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
18+
# with:
19+
# license_header_check_enabled: false
20+
# license_header_check_project_name: "Swift.org"

Sources/SwiftFormat/Rules/UseShorthandTypeNames.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public final class UseShorthandTypeNames: SyntaxFormatRule {
4848
switch node.name.text {
4949
case "Array":
5050
guard let argument = genericArgumentList.firstAndOnly,
51-
case .type(let typeArgument) = argument else {
51+
case .type(let typeArgument) = argument.argument else {
5252
newNode = nil
5353
break
5454
}
@@ -62,7 +62,7 @@ public final class UseShorthandTypeNames: SyntaxFormatRule {
6262
case "Dictionary":
6363
guard let arguments = exactlyTwoChildren(of: genericArgumentList),
6464
case .type(let type0Argument) = arguments.0.argument,
65-
caes .type(let type1Argument) = arguments.1.argument else {
65+
case .type(let type1Argument) = arguments.1.argument else {
6666
newNode = nil
6767
break
6868
}
@@ -79,7 +79,7 @@ public final class UseShorthandTypeNames: SyntaxFormatRule {
7979
break
8080
}
8181
guard let argument = genericArgumentList.firstAndOnly,
82-
case .type(let typeArgument) = argument else {
82+
case .type(let typeArgument) = argument.argument else {
8383
newNode = nil
8484
break
8585
}
@@ -143,7 +143,7 @@ public final class UseShorthandTypeNames: SyntaxFormatRule {
143143
switch expression.baseName.text {
144144
case "Array":
145145
guard let argument = genericArgumentList.firstAndOnly,
146-
case .type(let typeArgument) = argument else {
146+
case .type(let typeArgument) = argument.argument else {
147147
newNode = nil
148148
break
149149
}
@@ -172,7 +172,7 @@ public final class UseShorthandTypeNames: SyntaxFormatRule {
172172

173173
case "Optional":
174174
guard let argument = genericArgumentList.firstAndOnly,
175-
case .type(let typeArgument) = argument else {
175+
case .type(let typeArgument) = argument.argument else {
176176
newNode = nil
177177
break
178178
}

cross-pr-checkout.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import subprocess
2+
import pathlib
3+
import requests
4+
5+
class CrossRepoPR:
6+
org: str
7+
repo: str
8+
pr_num: str
9+
10+
def __init__(self, org: str, repo: str, pr_num: str) -> None:
11+
self.org = org
12+
self.repo = repo
13+
self.pr_num = pr_num
14+
15+
def cross_repo_prs() -> list[CrossRepoPR]:
16+
return [
17+
CrossRepoPR("swiftlang", "swift-syntax", "2859")
18+
]
19+
20+
def run(cmd: list[str], cwd: str|None = None):
21+
print(" ".join(cmd))
22+
subprocess.check_call(cmd, cwd=cwd)
23+
24+
def main():
25+
for cross_repo_pr in cross_repo_prs():
26+
run(["git", "clone", f"https://github.com/{cross_repo_pr.org}/{cross_repo_pr.repo}.git", f"{cross_repo_pr.repo}"], cwd="..")
27+
run(["git", "fetch", "origin", f"pull/{cross_repo_pr.pr_num}/merge:pr_merge"], cwd="../swift-syntax")
28+
run(["git", "checkout", "main"], cwd="../swift-syntax")
29+
run(["git", "reset", "--hard", "pr_merge"], cwd="../swift-syntax")
30+
run(["swift", "package", "config", "set-mirror", "--package-url", "https://github.com/swiftlang/swift-syntax.git", "--mirror-url", str(pathlib.Path("../swift-syntax").resolve())])
31+
32+
if __name__ == "__main__":
33+
main()

cross-pr-checkout.swift

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import Foundation
2+
3+
#if canImport(FoundationNetworking)
4+
import FoundationNetworking
5+
#endif
6+
7+
func run(_ executable: URL, _ arguments: String..., workingDirectory: URL? = nil) {
8+
print("Running " + ([executable.path] + arguments).joined(separator: " "))
9+
let process = Process()
10+
process.executableURL = executable
11+
process.arguments = arguments
12+
if let workingDirectory {
13+
process.currentDirectoryURL = workingDirectory
14+
}
15+
16+
process.launch()
17+
process.waitUntilExit()
18+
}
19+
20+
struct CrossRepoPR {
21+
let org: String
22+
let repo: String
23+
let prNum: String
24+
}
25+
26+
let crossRepoPrs = [
27+
CrossRepoPR(org: "swiftlang", repo: "swift-syntax", prNum: "2859")
28+
]
29+
30+
func getBaseBranch(_ crossRepoPr: CrossRepoPR) throws -> String {
31+
struct PR: Codable {
32+
struct Base: Codable {
33+
let ref: String
34+
}
35+
let base: Base
36+
}
37+
38+
let data = try Data(
39+
contentsOf: URL(
40+
string: "https://api.github.com/repos/\(crossRepoPr.org)/\(crossRepoPr.repo)/pulls/\(crossRepoPr.prNum)"
41+
)!
42+
)
43+
let decoded = try JSONDecoder().decode(PR.self, from: data)
44+
return decoded.base.ref
45+
}
46+
47+
print(ProcessInfo.processInfo.environment)
48+
49+
for crossRepoPr in crossRepoPrs {
50+
let git = URL(fileURLWithPath: "/usr/bin/git")
51+
let swift = URL(fileURLWithPath: "/usr/bin/swift")
52+
let baseBranch = try getBaseBranch(crossRepoPr)
53+
54+
let workspaceDir = URL(fileURLWithPath: "..")
55+
let repoDir = workspaceDir.appendingPathComponent(crossRepoPr.repo)
56+
run(
57+
git,
58+
"clone",
59+
"https://github.com/\(crossRepoPr.org)/\(crossRepoPr.repo).git",
60+
"\(crossRepoPr.repo)",
61+
workingDirectory: workspaceDir
62+
)
63+
run(git, "fetch", "origin", "pull/\(crossRepoPr.prNum)/merge:pr_merge", workingDirectory: repoDir)
64+
run(git, "checkout", baseBranch, workingDirectory: repoDir)
65+
run(git, "reset", "--hard", "pr_merge", workingDirectory: repoDir)
66+
run(
67+
swift,
68+
"package",
69+
"config",
70+
"set-mirror",
71+
"--package-url",
72+
"https://github.com/\(crossRepoPr.org)/\(crossRepoPr.repo).git",
73+
"--mirror-url",
74+
repoDir.resolvingSymlinksInPath().path
75+
)
76+
}

0 commit comments

Comments
 (0)