Fix spotless ratcheting on release branches (#1401)

This commit is contained in:
Jen Basch
2026-01-09 14:18:18 -08:00
committed by GitHub
parent 9b6f72d5d0
commit 3595c03078

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. * Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -142,9 +142,17 @@ private fun KotlinGradleExtension.configureFormatter() {
} }
val originalRemoteName = System.getenv("PKL_ORIGINAL_REMOTE_NAME") ?: "origin" val originalRemoteName = System.getenv("PKL_ORIGINAL_REMOTE_NAME") ?: "origin"
// if we're running against a release branch (or a PR targeted at one), use that branch for
// ratcheting
// these env vars are set by GitHub actions:
// https://docs.github.com/en/actions/reference/workflows-and-actions/variables#default-environment-variables
val ratchetBranchName =
(System.getenv("GITHUB_BASE_REF") ?: System.getenv("GITHUB_REF_NAME"))?.let {
if (it.startsWith("release/")) it else null
} ?: "main"
spotless { spotless {
ratchetFrom = "$originalRemoteName/main" ratchetFrom = "$originalRemoteName/$ratchetBranchName"
// When building root project, format buildSrc files too. // When building root project, format buildSrc files too.
// We need this because buildSrc is not a subproject of the root project, so a top-level // We need this because buildSrc is not a subproject of the root project, so a top-level