Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions .github/workflows/test.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ workflow(
run(
name = "Check for actions",
) {
validateTypings(github.sha, github.base_ref?.ifEmpty { null })
validateAllMajorVersionsPresent(github.base_ref?.ifEmpty { null })
val baseRef = resolveBaseRef(github.base_ref?.ifEmpty { null }, github.ref, github.repository)
validateTypings(github.sha, baseRef)
validateAllMajorVersionsPresent(baseRef)
}
}

Expand Down Expand Up @@ -169,6 +170,22 @@ private data class TypingInference(
val isMismatch: Boolean get() = actual != inferred
}

private fun resolveBaseRef(rawBaseRef: String?, ref: String?, repository: String?): String? {
if (rawBaseRef == null || !rawBaseRef.startsWith("graphite-base/")) return rawBaseRef

// Graphite reports a synthetic, non-existent base branch for stacked PRs. Ask GitHub for the real one.
val prNumber = ref?.removePrefix("refs/pull/")?.substringBefore("/merge")
check(prNumber != null && prNumber != ref) {
"Cannot resolve the real base branch for Graphite PR from ref $ref"
}
val process = ProcessBuilder(
"gh", "api", "repos/$repository/pulls/$prNumber", "--jq", ".base.ref",
).redirectErrorStream(true).start()
val output = process.inputStream.bufferedReader().readText().trim()
check(process.waitFor() == 0) { "Failed to resolve the PR base branch: $output" }
return output
}

private fun validateTypings(sha: String, baseRef: String?) {
val typingsSchema = JsonSchema.fromDefinition(
URI.create("https://raw.githubusercontent.com/typesafegithub/github-actions-typing/" +
Expand Down