Skip to content

Commit c385678

Browse files
committed
better use of rachet
1 parent 6960d4b commit c385678

2 files changed

Lines changed: 53 additions & 2 deletions

File tree

.github/workflows/beam_PreCommit_Spotless.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ jobs:
8787
github_job: ${{ matrix.job_name }} (${{ matrix.job_phrase }})
8888
- name: Setup environment
8989
uses: ./.github/actions/setup-environment-action
90+
- name: Fetch base branch for Spotless ratchet
91+
if: github.event.pull_request.base.ref != ''
92+
run: |
93+
git fetch --no-tags --prune --depth=1 origin ${{ github.event.pull_request.base.ref }}:refs/remotes/origin/${{ github.event.pull_request.base.ref }}
94+
shell: bash
9095
- name: run Spotless PreCommit script
9196
uses: ./.github/actions/gradle-command-self-hosted-action
9297
with:

buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,41 @@ class BeamModulePlugin implements Plugin<Project> {
507507

508508
project.ext.mavenGroupId = 'org.apache.beam'
509509

510+
project.ext.getRatchetBranch = {
511+
->
512+
if (project.hasProperty('disableSpotlessRatchet') && project.disableSpotlessRatchet == 'true') {
513+
return null
514+
}
515+
try {
516+
def checkRef = { ref ->
517+
try {
518+
def res = project.exec {
519+
executable 'git'
520+
args 'rev-parse', '--verify', ref
521+
ignoreExitValue = true
522+
standardOutput = new ByteArrayOutputStream()
523+
errorOutput = new ByteArrayOutputStream()
524+
}
525+
return res.getExitValue() == 0
526+
} catch (Exception e) {
527+
return false
528+
}
529+
}
530+
531+
if (checkRef('upstream/master')) {
532+
return 'upstream/master'
533+
} else if (checkRef('origin/master')) {
534+
return 'origin/master'
535+
} else if (checkRef('master')) {
536+
return 'master'
537+
} else {
538+
return null
539+
}
540+
} catch (Exception e) {
541+
return null
542+
}
543+
}
544+
510545
// Default to dash-separated directories for artifact base name,
511546
// which will also be the default artifactId for maven publications
512547
project.apply plugin: 'base'
@@ -1476,9 +1511,13 @@ class BeamModulePlugin implements Plugin<Project> {
14761511
project.disableSpotlessCheck == 'true'
14771512
project.spotless {
14781513
enforceCheck !disableSpotlessCheck
1514+
def ratchetBranch = project.ext.getRatchetBranch()
1515+
if (ratchetBranch != null) {
1516+
ratchetFrom ratchetBranch
1517+
}
14791518
java {
14801519
licenseHeader javaLicenseHeader
1481-
googleJavaFormat('1.7')
1520+
googleJavaFormat('1.17.0')
14821521
target project.fileTree(project.projectDir) {
14831522
include 'src/*/java/**/*.java'
14841523
exclude '**/DefaultPackageTest.java'
@@ -2403,10 +2442,17 @@ class BeamModulePlugin implements Plugin<Project> {
24032442
project.disableSpotlessCheck == 'true'
24042443
project.spotless {
24052444
enforceCheck !disableSpotlessCheck
2445+
def ratchetBranch = project.ext.getRatchetBranch()
2446+
if (ratchetBranch != null) {
2447+
ratchetFrom ratchetBranch
2448+
}
24062449
def grEclipseConfig = project.project(":").file("buildSrc/greclipse.properties")
24072450
groovy {
24082451
greclipse().configFile(grEclipseConfig)
2409-
target project.fileTree(project.projectDir) { include '**/*.groovy' }
2452+
target project.fileTree(project.projectDir) {
2453+
include '**/*.groovy'
2454+
exclude '**/build/**'
2455+
}
24102456
}
24112457
groovyGradle { greclipse().configFile(grEclipseConfig) }
24122458
}

0 commit comments

Comments
 (0)