Skip to content

Commit

Permalink
major: Use git cli instead of grgit
Browse files Browse the repository at this point in the history
grgit is not really necessary for this plugin, decoupling it will
improve a lot of things.

The expectation is for behavior equivalence, but I expect there will be
some quirks from switching so this is considered a major version.
  • Loading branch information
ajoberstar committed Oct 6, 2024
1 parent b5064a8 commit 185703d
Show file tree
Hide file tree
Showing 10 changed files with 346 additions and 313 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ jobs:
17
21
- name: Set committer info
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "[email protected]"
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Setup Gradle
Expand Down
7 changes: 1 addition & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@ java {
}

dependencies {
// grgit
api("org.ajoberstar.grgit:grgit-core:[5.0,6.0[")
api("org.ajoberstar.grgit:grgit-gradle:[5.0,6.0[")
compatTestImplementation("org.ajoberstar.grgit:grgit-core:[5.0,6.0[")

// testing
compatTestImplementation(gradleTestKit())
compatTestImplementation("org.spockframework:spock-core:2.3-groovy-3.0")
compatTestImplementation("org.ajoberstar.grgit:grgit-core:[5.0,6.0[")
}

tasks.named<Jar>("jar") {
Expand Down
15 changes: 7 additions & 8 deletions gradle.lockfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# This is a Gradle generated file for dependency locking.
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.googlecode.javaewah:JavaEWAH:1.2.3=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
commons-codec:commons-codec:1.16.0=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.ajoberstar.grgit:grgit-core:5.2.2=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.ajoberstar.grgit:grgit-gradle:5.2.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.googlecode.javaewah:JavaEWAH:1.2.3=compatTestCompileClasspath,compatTestRuntimeClasspath
commons-codec:commons-codec:1.17.0=compatTestCompileClasspath,compatTestRuntimeClasspath
org.ajoberstar.grgit:grgit-core:5.3.0=compatTestCompileClasspath,compatTestRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=compatTestCompileClasspath
org.codehaus.groovy:groovy:3.0.20=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.eclipse.jgit:org.eclipse.jgit:6.8.0.202311291450-r=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.codehaus.groovy:groovy:3.0.22=compatTestCompileClasspath,compatTestRuntimeClasspath
org.eclipse.jgit:org.eclipse.jgit:6.10.0.202406032230-r=compatTestCompileClasspath,compatTestRuntimeClasspath
org.hamcrest:hamcrest:2.2=compatTestCompileClasspath,compatTestRuntimeClasspath
org.junit.platform:junit-platform-commons:1.9.0=compatTestCompileClasspath,compatTestRuntimeClasspath
org.junit.platform:junit-platform-engine:1.9.0=compatTestCompileClasspath,compatTestRuntimeClasspath
org.junit:junit-bom:5.9.0=compatTestCompileClasspath,compatTestRuntimeClasspath
org.opentest4j:opentest4j:1.2.0=compatTestCompileClasspath,compatTestRuntimeClasspath
org.slf4j:slf4j-api:1.7.36=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.slf4j:slf4j-api:1.7.36=compatTestCompileClasspath,compatTestRuntimeClasspath
org.spockframework:spock-core:2.3-groovy-3.0=compatTestCompileClasspath,compatTestRuntimeClasspath
empty=annotationProcessor,compatTestAnnotationProcessor,signatures,testAnnotationProcessor
empty=annotationProcessor,compatTestAnnotationProcessor,compileClasspath,runtimeClasspath,signatures,testAnnotationProcessor,testCompileClasspath,testRuntimeClasspath
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package org.ajoberstar.gradle.git.publish

import spock.lang.IgnoreIf
import spock.lang.Specification
import spock.lang.TempDir

import org.ajoberstar.grgit.Grgit
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.gradle.testkit.runner.UnexpectedBuildFailure
import spock.lang.Specification
import spock.lang.TempDir

class BaseCompatTest extends Specification {
@TempDir File tempDir
Expand All @@ -25,7 +23,7 @@ class BaseCompatTest extends Specification {

remoteFile('master.txt') << 'contents here'
remote.add(patterns: ['.'])
remote.commit(message: 'first commit')
remote.commit(message: 'first commit', sign: false)

// handle different init branches to keep existing tests the same
if (remote.branch.current().name != 'master') {
Expand All @@ -37,7 +35,7 @@ class BaseCompatTest extends Specification {
remoteFile('index.md') << '# This Page is Awesome!'
remoteFile('1.0.0/index.md') << '# Version 1.0.0 is the Best!'
remote.add(patterns: ['.'])
remote.commit(message: 'first pages commit')
remote.commit(message: 'first pages commit', sign: false)

remote.checkout(branch: 'master')
}
Expand All @@ -52,7 +50,7 @@ plugins {
}
gitPublish {
repoUri = '${remote.repository.rootDir.toURI()}'
repoUri = '${repoPath(remote)}'
branch = 'my-pages'
contents.from 'src'
}
Expand All @@ -77,7 +75,7 @@ plugins {
}
gitPublish {
repoUri = '${remote.repository.rootDir.toURI()}'
repoUri = '${repoPath(remote)}'
branch = 'gh-pages'
contents.from 'src'
}
Expand All @@ -97,7 +95,7 @@ gitPublish {
remote.checkout(branch: 'gh-pages')
remoteFile('index.md') << 'And has great content'
remote.add(patterns: ['.'])
remote.commit(message: 'second pages commit')
remote.commit(message: 'second pages commit', sign: false)
remote.checkout(branch: 'master')

projectFile('src/content.txt') << 'published content here'
Expand All @@ -108,7 +106,7 @@ plugins {
}
gitPublish {
repoUri = '${remote.repository.rootDir.toURI()}'
repoUri = '${repoPath(remote)}'
branch = 'gh-pages'
fetchDepth = 1
contents.from 'src'
Expand All @@ -130,14 +128,14 @@ gitPublish {
def 'reset pulls from reference repo if available before pulling from remote'() {
given:
def referenceDir = new File(tempDir, 'reference')
def reference = Grgit.clone(dir: referenceDir, uri: remote.repository.rootDir.toURI())
def reference = Grgit.clone(dir: referenceDir, uri: repoPath(remote))
reference.checkout(branch: 'gh-pages', createBranch: true)
// add a file that will get fetched but not pushed
def refFile = new File(reference.repository.rootDir, 'src/newFile.txt')
refFile.parentFile.mkdirs()
refFile.text = 'Some content'
reference.add(patterns: ['.'])
reference.commit(message: 'This wont get pushed')
reference.commit(message: 'This wont get pushed', sign: false)

projectFile('src/content.txt') << 'published content here'

Expand All @@ -147,8 +145,8 @@ plugins {
}
gitPublish {
repoUri = '${remote.repository.rootDir.toURI()}'
referenceRepoUri = '${reference.repository.rootDir.toURI()}'
repoUri = '${repoPath(remote)}'
referenceRepoUri = '${repoPath(reference)}'
branch = 'gh-pages'
contents.from 'src'
}
Expand All @@ -159,7 +157,7 @@ gitPublish {
remote.checkout(branch: 'gh-pages')
then:
result.task(':gitPublishPush').outcome == TaskOutcome.SUCCESS
result.output.contains('Fetching from reference repo')
result.output.contains('gh-pages -> reference/gh-pages')
remote.log().size() == 2
remoteFile('content.txt').text == 'published content here'
!remoteFile('newFile.txt').exists()
Expand All @@ -175,7 +173,7 @@ plugins {
}
gitPublish {
repoUri = '${remote.repository.rootDir.toURI()}'
repoUri = '${repoPath(remote)}'
repoDir = file('build/this-is-custom')
branch = 'gh-pages'
contents.from 'src'
Expand All @@ -197,7 +195,7 @@ plugins {
}
gitPublish {
repoUri = '${remote.repository.rootDir.toURI()}'
repoUri = '${repoPath(remote)}'
branch = 'gh-pages'
contents.from 'src'
Expand Down Expand Up @@ -229,7 +227,7 @@ plugins {
}
gitPublish {
repoUri = '${remote.repository.rootDir.toURI()}'
repoUri = '${repoPath(remote)}'
branch = 'gh-pages'
contents {
from('src1') {
Expand Down Expand Up @@ -263,7 +261,7 @@ plugins {
}
gitPublish {
repoUri = '${remote.repository.rootDir.toURI()}'
repoUri = '${repoPath(remote)}'
branch = 'gh-pages'
contents.from 'src'
}
Expand All @@ -274,16 +272,16 @@ gitPublish {
remote.checkout(branch: 'gh-pages')
then:
result.task(':gitPublishCommit').outcome == TaskOutcome.UP_TO_DATE
result.task(':gitPublishPush').outcome == TaskOutcome.SKIPPED
result.task(':gitPublishPush').outcome == TaskOutcome.UP_TO_DATE
}

def 'existing working repo is reused if valid'() {
given:
def working = Grgit.clone(dir: "${projectDir}/build/gitPublish", uri: remote.repository.rootDir.toURI())
def working = Grgit.clone(dir: "${projectDir}/build/gitPublish", uri: repoPath(remote))
working.checkout(branch: 'master')
new File(projectDir, 'build/gitPublish/master.txt') << 'working repo was here'
working.add(patterns: ['.'])
working.commit(message: 'working repo was here')
working.commit(message: 'working repo was here', sign: false)
working.checkout(branch: 'gh-pages', startPoint: 'origin/gh-pages', createBranch: 'true')
working.close()

Expand All @@ -293,7 +291,7 @@ plugins {
}
gitPublish {
repoUri = '${remote.repository.rootDir.toURI()}'
repoUri = '${repoPath(remote)}'
branch = 'gh-pages'
contents {
from 'src'
Expand All @@ -320,7 +318,7 @@ gitPublish {

new File(badRemoteDir, 'master.txt') << 'bad contents here'
badRemote.add(patterns: ['.'])
badRemote.commit(message: 'bad first commit')
badRemote.commit(message: 'bad first commit', sign: false)

// handle different init branches to keep existing tests the same
if (badRemote.branch.current().name != 'master') {
Expand All @@ -339,7 +337,7 @@ plugins {
}
gitPublish {
repoUri = '${remote.repository.rootDir.toURI()}'
repoUri = '${repoPath(remote)}'
branch = 'gh-pages'
contents.from 'src'
}
Expand Down Expand Up @@ -384,7 +382,7 @@ plugins {
}
gitPublish {
repoUri = '${remote.repository.rootDir.toURI()}'
repoUri = '${repoPath(remote)}'
branch = 'gh-pages'
contents.from 'src'
commitMessage = "Deploy docs to gh-pages (\${project.name})"
Expand All @@ -398,7 +396,7 @@ gitPublish {
result.task(':gitPublishPush').outcome == TaskOutcome.SUCCESS
remote.log().size() == 2
remoteFile('content.txt').text == 'published content here'
remote.head().fullMessage == "Deploy docs to gh-pages (${projectFile('.').canonicalFile.name})"
remote.head().fullMessage == "Deploy docs to gh-pages (${projectFile('.').canonicalFile.name})\n"
}

def 'can activate signing'() {
Expand All @@ -415,7 +413,7 @@ plugins {
}
gitPublish {
repoUri = '${remote.repository.rootDir.toURI()}'
repoUri = '${repoPath(remote)}'
branch = 'gh-pages'
contents.from 'src'
sign = true
Expand All @@ -425,7 +423,7 @@ gitPublish {
def result = buildAndFail()

then:
result.output.contains("org.eclipse.jgit.api.errors.ServiceUnavailableException")
result.output.contains("gpg: signing failed: No secret key")
}

def 'can deactivate signing'() {
Expand All @@ -442,7 +440,7 @@ plugins {
}
gitPublish {
repoUri = '${remote.repository.rootDir.toURI()}'
repoUri = '${repoPath(remote)}'
branch = 'gh-pages'
contents.from 'src'
sign = false
Expand All @@ -455,11 +453,11 @@ gitPublish {
result.task(':gitPublishPush').outcome == TaskOutcome.SUCCESS
}

private BuildResult build(String... args = ['gitPublishPush', '--stacktrace', '--info', '--configuration-cache']) {
private BuildResult build(String... args = ['gitPublishPush', '--stacktrace', '--configuration-cache']) {
return runner(args).build()
}

private BuildResult buildAndFail(String... args = ['gitPublishPush', '--stacktrace', '--info', '--configuration-cache']) {
private BuildResult buildAndFail(String... args = ['gitPublishPush', '--stacktrace', '--configuration-cache']) {
return runner(args).buildAndFail()
}

Expand All @@ -483,4 +481,8 @@ gitPublish {
file.parentFile.mkdirs()
return file
}

private String repoPath(Grgit repo) {
return repo.repository.rootDir.toPath().toAbsolutePath().toString().replace('\\', '\\\\')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MultiPublicationCompatTest extends Specification {

remote1File('master.txt') << 'contents here'
remote1.add(patterns: ['.'])
remote1.commit(message: 'first commit')
remote1.commit(message: 'first commit', sign: false)

// handle different init branches to keep existing tests the same
if (remote1.branch.current().name != 'master') {
Expand All @@ -37,7 +37,7 @@ class MultiPublicationCompatTest extends Specification {
remote1File('index.md') << '# This Page is Awesome!'
remote1File('1.0.0/index.md') << '# Version 1.0.0 is the Best!'
remote1.add(patterns: ['.'])
remote1.commit(message: 'first pages commit')
remote1.commit(message: 'first pages commit', sign: false)

remote1.checkout(branch: 'master')

Expand All @@ -46,7 +46,7 @@ class MultiPublicationCompatTest extends Specification {

remote2File('master.txt') << 'contents here'
remote2.add(patterns: ['.'])
remote2.commit(message: 'first commit')
remote2.commit(message: 'first commit', sign: false)

// handle different init branches to keep existing tests the same
if (remote2.branch.current().name != 'master') {
Expand All @@ -58,7 +58,7 @@ class MultiPublicationCompatTest extends Specification {
remote2File('index.md') << '# This Page is Awesomest!'
remote2File('1.0.0/index.md') << '# Version 1.0.0 is the Best!'
remote2.add(patterns: ['.'])
remote2.commit(message: 'first pages commit')
remote2.commit(message: 'first pages commit', sign: false)

remote2.checkout(branch: 'master')
}
Expand All @@ -75,7 +75,7 @@ plugins {
gitPublish {
// can configure main at top-level
repoUri = '${remote1.repository.rootDir.toURI()}'
repoUri = '${repoPath(remote1)}'
contents.from 'src'
publications {
Expand All @@ -85,7 +85,7 @@ gitPublish {
}
second {
repoUri.set('${remote2.repository.rootDir.toURI()}')
repoUri.set('${repoPath(remote2)}')
branch.set('gh-pages')
contents.from 'src2'
}
Expand All @@ -107,11 +107,11 @@ gitPublish {
remote2File('content.txt').text == 'second published content here'
}

private BuildResult build(String... args = ['gitPublishPushAll', '--stacktrace', '--info', '--configuration-cache']) {
private BuildResult build(String... args = ['gitPublishPushAll', '--stacktrace', '--configuration-cache']) {
return runner(args).build()
}

private BuildResult buildAndFail(String... args = ['gitPublishPushAll', '--stacktrace', '--info', '--configuration-cache']) {
private BuildResult buildAndFail(String... args = ['gitPublishPushAll', '--stacktrace', '--configuration-cache']) {
return runner(args).buildAndFail()
}

Expand Down Expand Up @@ -141,4 +141,8 @@ gitPublish {
file.parentFile.mkdirs()
return file
}

private String repoPath(Grgit repo) {
return repo.repository.rootDir.toPath().toAbsolutePath().toString().replace('\\', '\\\\')
}
}
Loading

0 comments on commit 185703d

Please sign in to comment.