From 3f128e1fcc5518c24310946fd8bc0e1bb5e73022 Mon Sep 17 00:00:00 2001 From: Andrew Oberstar Date: Fri, 16 Dec 2016 19:17:31 -0600 Subject: [PATCH] Usage documentation --- .github/CONTRIBUTING.md | 0 README.md | 89 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 .github/CONTRIBUTING.md diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index 3dd6dbd..abcc6d3 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,7 @@ ## Why do you care? -Git is immensely popular and being able to interact with it as part of a build process can be very valuable -to provide a more powerful and consistent result. +Git is immensely popular and being able to publish to it as part of a build process can be very valuable, for example to publish a blog or project documentation to GitHub Pages. ## What is it? @@ -20,12 +19,84 @@ configuration for authentication. ## Usage -**NOTE:** gradle-git-publish requires Java 8 (or higher) and Gradle 3.0 or higher. +See the [Release Notes](https://github.com/ajoberstar/gradle-git-publish/releases) for updates on +changes and compatibility with Java and Gradle versions. -* [Release Notes](https://github.com/ajoberstar/gradle-git-publish/releases) -* [Wiki](https://github.com/ajoberstar/gradle-git-publish/wiki) -* [Javadoc](http://ajoberstar.org/gradle-git-publish/docs/javadoc) -* [Groovydoc](http://ajoberstar.org/gradle-git-publish/docs/groovydoc) +### Applying the Plugin + +**Plugins DSL** + +```groovy +plugins { + id 'org.ajoberstar.git-publish' version '' +} +``` + +**Classic** + +```groovy +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'org.ajoberstar:gradle-git-publish:' + } +} + +apply plugin: 'org.ajoberstar.git-publish' +``` + +### Configuration + +**NOTE:** In general, there are no default values here. The one exception is that the `repoUri` 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 + repoUri = 'git@github.com/ajoberstar/test-repo.git' + branch = 'gh-pages' + + // generally, you don't need to touch this + repoDir = file("$buildDir/somewhereelse") // defaults to $buildDir/gitPublish + + // what to publish, this is a standard CopySpec + contents { + from 'src/pages' + from(javadoc) { + into 'api' + } + } + + // what to keep in the existing branch (include=keep) + preserve { + include '1.0.0/**' + exclude '1.0.0/temp.txt' + } +} +``` + +### Tasks and Execution + +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`. + +### Avoiding Extra Copy + +If you are generating a large site, you may want to directly generate it into the working repo to save an extra copy step. You can do this with task dependencies and referring to the `repoDir`. + +```groovy +jbakeTask { + outputDir gitPublish.repoDir + dependsOn gitPublishReset +} + +gitPublishCommit.dependsOn jbakeTask +``` ## Questions, Bugs, and Features @@ -47,5 +118,5 @@ to make sure it's not already in progress and for any needed discussion. Thanks to all of the [contributors](https://github.com/ajoberstar/gradle-git-publish/graphs/contributors). -Credit goes to [Peter Ledbrook](https://github.com/pledbrook) for the initial -idea for the plugin. +I also want to acknowledge [Peter Ledbrook](https://github.com/pledbrook) for the initial +idea and code for the plugin.