Skip to content

Commit

Permalink
Merge pull request #72 from ajoberstar/local
Browse files Browse the repository at this point in the history
Work for 2.1.0
  • Loading branch information
ajoberstar authored Mar 23, 2019
2 parents d102127 + 8fc8f0f commit df487aa
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 58 deletions.
17 changes: 2 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ jobs:
<<: *defaults
docker:
- image: ajoberstar/circleci-openjdk-gradle:8-jdk
build-java-9:
<<: *defaults
docker:
- image: ajoberstar/circleci-openjdk-gradle:9-jdk
build-java-10:
<<: *defaults
docker:
- image: ajoberstar/circleci-openjdk-gradle:10-jdk
build-java-11:
<<: *defaults
docker:
Expand Down Expand Up @@ -77,18 +69,13 @@ workflows:
jobs:
- build-java-8:
<<: *branches-and-tags
- build-java-9:
<<: *branches-and-tags
requires:
- build-java-8
- build-java-10:
- build-java-11:
<<: *branches-and-tags
requires:
- build-java-8
- publish:
<<: *tags-only
requires:
- build-java-8
- build-java-9
- build-java-10
- build-java-11
context: ajoberstar
2 changes: 2 additions & 0 deletions .stutter/java11.lock
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# DO NOT MODIFY: Generated by Stutter plugin.
5.0
5.3
4 changes: 3 additions & 1 deletion .stutter/java8.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT MODIFY: Generated by Stutter plugin.
4.3
4.10.2
4.10.3
5.0
5.3
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,17 @@ apply plugin: 'org.ajoberstar.git-publish'

### Configuration

**NOTE:** In general, there are no default values here. The main exception is that the `repoUri` will be automatically set if you use the `org.ajoberstar.grgit` plugin to your project's origin repo URI.
**NOTE:** In general, there are no default values here. The main exception is that the `repoUri` and `referenceRepoUri` will be automatically set if you use the `org.ajoberstar.grgit` plugin to your project's origin repo URI.

```groovy
gitPublish {
// where to publish to (repo must exist)
repoUri = '[email protected]:ajoberstar/test-repo.git'
// (or 'https://github.com/ajoberstar/test-repo.git', depending on authentication)
// where to fetch from prior to fetching from the remote (i.e. a local repo to save time)
referenceRepoUri = 'file:///home/human/projects/test-repo/'
// branch will be created if it doesn't exist
branch = 'gh-pages'
Expand Down Expand Up @@ -84,10 +87,10 @@ gitPublish {

Generally, you'll just run `gitPublishPush`, but there is a series of four tasks that happen in order.

* `gitPublishReset` - Clones/updates the working repo to the latest commit on the `repoUri` `branch` head. All files not included by the `preserve` filters will be deleted and staged.
* `gitPublishCopy` - Copies any files defined in the `contents` CopySpec into the working repo.
* `gitPublishCommit` - Commits all changes to the working repo.
* `gitPublishPush` - If changes were committed, pushed them to the `repoUri`.
- `gitPublishReset` - Clones/updates the working repo to the latest commit on the `repoUri` `branch` head. All files not included by the `preserve` filters will be deleted and staged.
- `gitPublishCopy` - Copies any files defined in the `contents` CopySpec into the working repo.
- `gitPublishCommit` - Commits all changes to the working repo.
- `gitPublishPush` - If changes were committed, pushed them to the `repoUri`.

### Avoiding Extra Copy

Expand All @@ -106,15 +109,15 @@ gitPublishCommit.dependsOn jbakeTask

The following table should help translate settings you used in `org.ajoberstar.github-pages` to this plugin's format. Additionally reference the Configuration section above for more information on the current feature set.

| org.ajoberstar.github-pages | org.ajoberstar.git-publish | Comment |
|-----------------------------|-----------------------------|---------|
| `repoUri` | `repoUri` | Used to allow any Object (which would be lazily unpacked to a String). Now requires a String. |
| `targetBranch` | `branch` | The old plugin defaulted to `gh-pages`, the new one has no default. This must be a String. |
| `workingPath` | `repoDir` | Used to allow any Object and called `file()` on it for you. Now expects a File. |
| `pages` | `contents` | Just a name change. |
| `deleteExistingFiles` | `preserve` | If previously `true` (the default), do nothing. If previously `false`, `preserve { include '**/*' }`
| `commitMessage` | `commitMessage` | Just copy from the old value. |
| `credentials` | env variable or system prop | `GRGIT_USER` environment variable or `org.ajoberstar.grgit.auth.username` system property. |
| org.ajoberstar.github-pages | org.ajoberstar.git-publish | Comment |
| --------------------------- | --------------------------- | ---------------------------------------------------------------------------------------------------- |
| `repoUri` | `repoUri` | Used to allow any Object (which would be lazily unpacked to a String). Now requires a String. |
| `targetBranch` | `branch` | The old plugin defaulted to `gh-pages`, the new one has no default. This must be a String. |
| `workingPath` | `repoDir` | Used to allow any Object and called `file()` on it for you. Now expects a File. |
| `pages` | `contents` | Just a name change. |
| `deleteExistingFiles` | `preserve` | If previously `true` (the default), do nothing. If previously `false`, `preserve { include '**/*' }` |
| `commitMessage` | `commitMessage` | Just copy from the old value. |
| `credentials` | env variable or system prop | `GRGIT_USER` environment variable or `org.ajoberstar.grgit.auth.username` system property. |

Use the `gitPublishPush` task as replacement for the `publishGhPages` task.

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'org.ajoberstar.defaults' version '0.12.0'
id 'org.ajoberstar.defaults' version '0.14.2'
id 'groovy'
id 'java-library'
id 'java-gradle-plugin'
Expand Down Expand Up @@ -27,7 +27,7 @@ dependencies {

// testing
compatTestImplementation gradleTestKit()
compatTestImplementation 'org.spockframework:spock-core:1.1-groovy-2.4'
compatTestImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'
}

stutter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ org.ajoberstar.grgit:grgit-core:3.0.0
org.eclipse.jgit:org.eclipse.jgit:5.1.3.201810200350-r
org.hamcrest:hamcrest-core:1.3
org.slf4j:slf4j-api:1.7.2
org.spockframework:spock-core:1.1-groovy-2.4
org.spockframework:spock-core:1.3-groovy-2.5
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ org.ajoberstar.grgit:grgit-core:3.0.0
org.eclipse.jgit:org.eclipse.jgit:5.1.3.201810200350-r
org.hamcrest:hamcrest-core:1.3
org.slf4j:slf4j-api:1.7.2
org.spockframework:spock-core:1.1-groovy-2.4
org.spockframework:spock-core:1.3-groovy-2.5
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.ajoberstar.gradle.git.publish

import spock.lang.IgnoreIf
import spock.lang.Specification
import spock.lang.Unroll

Expand Down Expand Up @@ -88,6 +89,44 @@ gitPublish {
remoteFile('content.txt').text == 'published content here'
}

def 'reset pulls from reference repo if available before pulling from remote'() {
given:
def referenceDir = tempDir.newFolder('reference')
def reference = Grgit.clone(dir: referenceDir, uri: remote.repository.rootDir.toURI())
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')

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

buildFile << """
plugins {
id 'org.ajoberstar.git-publish'
}
gitPublish {
repoUri = '${remote.repository.rootDir.toURI()}'
referenceRepoUri = '${reference.repository.rootDir.toURI()}'
branch = 'gh-pages'
contents.from 'src'
}
"""
when:
def result = build()
and:
remote.checkout(branch: 'gh-pages')
then:
result.task(':gitPublishPush').outcome == TaskOutcome.SUCCESS
result.output.contains('Fetching from reference repo')
remote.log().size() == 2
remoteFile('content.txt').text == 'published content here'
!remoteFile('newFile.txt').exists()
}

def 'can customize working directory'() {
given:
projectFile('src/content.txt') << 'published content here'
Expand Down Expand Up @@ -293,7 +332,35 @@ task hello {
notThrown(UnexpectedBuildFailure)
}

private BuildResult build(String... args = ['gitPublishPush', '--stacktrace']) {
@IgnoreIf({ Integer.parseInt(System.properties['compat.gradle.version'].split('\\.')[0]) < 5 })
def 'commit message can be changed'() {
given:
projectFile('src/content.txt') << 'published content here'

buildFile << """
plugins {
id 'org.ajoberstar.git-publish'
}
gitPublish {
repoUri = '${remote.repository.rootDir.toURI()}'
branch = 'gh-pages'
contents.from 'src'
commitMessage = "Deploy docs to gh-pages (\${project.name})"
}
"""
when:
def result = build()
and:
remote.checkout(branch: 'gh-pages')
then:
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})"
}

private BuildResult build(String... args = ['gitPublishPush', '--stacktrace', '--info']) {
return GradleRunner.create()
.withGradleVersion(System.properties['compat.gradle.version'])
.withPluginClasspath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,25 @@
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.util.PatternFilterable;
import org.gradle.api.tasks.util.PatternSet;
import org.gradle.util.GradleVersion;

public class GitPublishExtension {
private final DirectoryProperty repoDir;
private final Property<String> repoUri;
private final Property<String> referenceRepoUri;
private final Property<String> branch;
private final Property<String> commitMessage;
private final CopySpec contents;
private final PatternFilterable preserve;

public GitPublishExtension(Project project) {
this.repoDir = project.getLayout().directoryProperty();
if (GradleVersion.current().compareTo(GradleVersion.version("5.0")) >= 0) {
this.repoDir = project.getObjects().directoryProperty();
} else {
this.repoDir = project.getLayout().directoryProperty();
}
this.repoUri = project.getObjects().property(String.class);
this.referenceRepoUri = project.getObjects().property(String.class);
this.branch = project.getObjects().property(String.class);
this.commitMessage = project.getObjects().property(String.class);

Expand All @@ -36,6 +43,10 @@ public Property<String> getRepoUri() {
return repoUri;
}

public Property<String> getReferenceRepoUri() {
return referenceRepoUri;
}

public Property<String> getBranch() {
return branch;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public void apply(Project project) {
// if using the grgit plugin, default to the repo's origin
project.getPluginManager().withPlugin("org.ajoberstar.grgit", plugin -> {
// TODO should this be based on tracking branch instead of assuming origin?
String repoUri = Optional.ofNullable((Grgit) project.findProperty("grgit"))
.map(this::getOriginUri)
.orElse(null);
extension.getRepoUri().set(repoUri);
Optional.ofNullable((Grgit) project.findProperty("grgit")).ifPresent(grgit -> {
extension.getRepoUri().set(getOriginUri(grgit));
extension.getReferenceRepoUri().set(grgit.getRepository().getRootDir().toURI().toString());
});
});

extension.getRepoDir().set(project.getLayout().getBuildDirectory().dir("gitPublish"));
Expand Down Expand Up @@ -58,6 +58,7 @@ private GitPublishReset createResetTask(Project project, GitPublishExtension ext
task.setDescription("Prepares a git repo for new content to be generated.");
task.getRepoDirectory().set(extension.getRepoDir());
task.getRepoUri().set(extension.getRepoUri());
task.getReferenceRepoUri().set(extension.getReferenceRepoUri());
task.getBranch().set(extension.getBranch());
task.setPreserve(extension.getPreserve());
});
Expand Down
Loading

0 comments on commit df487aa

Please sign in to comment.