-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
130 lines (118 loc) · 3.95 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
buildscript {
repositories { jcenter() }
dependencies {
classpath 'com.github.jruby-gradle:jruby-gradle-plugin:1.5.0'
classpath 'de.qaware.seu.as.code:seuac-git-plugin:2.4.0'
classpath 'org.yaml:snakeyaml:1.21'
}
}
apply plugin: 'com.github.jruby-gradle.base'
apply plugin: 'de.qaware.seu.as.code.git'
dependencies {
jrubyExec 'rubygems:kramdown-asciidoc:2.1.0'
jrubyExec 'rubygems:rjgit:4.11.0.0'
}
jruby {
execVersion '9.2.0.0'
}
def assembly = new org.yaml.snakeyaml.Yaml().load(file('assembly.yml').text)
ext {
rootProjectDir = '../..'
upstreamProjectDir = "${rootProjectDir}/src"
docsUpstreamDir = "${upstreamProjectDir}/doc/src/main/markdown"
docsBuildDir = "${buildDir}/markdown"
docsPublishDir = "${buildDir}/docs"
}
git {
upstream {
url assembly.repos.upstream.url
branch assembly.repos.upstream.branch
directory file(upstreamProjectDir)
options {
clone.singleBranch = true
}
}
destination {
url assembly.repos.destination.url
branch assembly.repos.destination.branch
username System.env.GITHUB_TOKEN
directory file(docsPublishDir)
options {
commit {
message = assembly.commit.message
author {
//username = assembly.commit.author.name
email = assembly.commit.author.email
}
}
clone.singleBranch = true
}
}
}
def hasChanges(directory) {
def dirty = false
def repo = null
try {
repo = org.eclipse.jgit.api.Git.open(directory)
dirty = !repo.status().call().isClean()
} finally {
if (repo) repo.close()
}
dirty
}
task copyImages(type: Copy) {
from '.'
include '*/images/*.png'
includeEmptyDirs false
eachFile { path = name }
into "${docsBuildDir}/images"
}
task compileDocs(group: 'Documentation', description: 'Overlays the documentation from this directory onto the documentation from Product.') {
dependsOn copyImages
doLast {
assembly.files.each { target, sources ->
ant.concat(destfile: "${docsBuildDir}/${target}") {
sources.each { source ->
if (source.startsWith('^')) {
filelist(dir: docsUpstreamDir, files: source.substring(1))
} else {
filelist(dir: projectDir, files: source)
}
}
}
}
assembly.replacements.each { match, replace ->
ant.replaceregexp(match: match, replace: replace, flags: 'g', byline: 'true') {
fileset(dir: docsBuildDir, includes: '*.md')
}
}
}
}
task cleanDestination(type: Delete) {
delete(docsPublishDir)
}
task convertDocsToAntora(type: com.github.jrubygradle.JRubyExec, group: 'Documentation', description: 'Converts the documentation from Markdown to AsciiDoc and organizes it as an Antora component.') {
script 'convert-docs-to-antora.rb'
scriptArgs assembly.target.component, assembly.target.version, assembly.target.module, assembly.repos.destination.branch
doLast {
if (System.env.PUBLISH && hasChanges(tasks.gitCommitDestination.directory)) {
// author.username gets dropped, so we have to reassign
tasks.gitCommitDestination.author.username = assembly.commit.author.name
tasks.gitCommitDestination.doCommit()
tasks.gitPushDestination.doPush()
// NOTE indicate that a change was pushed
file("${docsPublishDir}/.trigger-build").createNewFile()
}
}
}
afterEvaluate {
if (file("${upstreamProjectDir}/.git").directory) {
tasks.compileDocs.dependsOn gitPullUpstream
}
else {
delete(upstreamProjectDir)
tasks.compileDocs.dependsOn gitCloneUpstream
}
tasks.gitCloneDestination.dependsOn cleanDestination
tasks.convertDocsToAntora.dependsOn gitCloneDestination, compileDocs
}