forked from junit-pioneer/junit-pioneer.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
199 lines (161 loc) · 4.43 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// -----
// SETUP
// -----
plugins {
id 'org.ajoberstar.grgit' version '4.1.1' apply false
}
ext {
onCi = System.getenv("CI")
}
configure(rootProject) {
task wrapper(type: Wrapper) {
description = 'Generates gradlew and gradlew.bat scripts'
gradleVersion = '3.5'
jarFile = "${project.projectDir}/.infra/gradle/gradle-wrapper.jar"
}
}
task setupGitOnCi(type: Exec) {
commandLine './git-ci-setup.sh'
}
task setupGitRepo(type: Exec) {
commandLine './git-repo-setup.sh'
if (onCi)
dependsOn setupGitOnCi
}
task setupJekyll(type: Exec) {
dependsOn setupGitRepo
workingDir 'site-source'
commandLine 'bundle install --quiet'.split(' ')
}
task setup {
dependsOn setupGitRepo, setupJekyll
}
// -----
// CLEAN
// -----
task removeProjectPage(type: Delete) {
delete fileTree('site-source/_pages') {
include 'xp.*'
}
}
task removeDemos(type: Delete) {
delete 'site-source/_demos/xp'
}
task removeDocs(type: Delete) {
delete 'site-source/_docs/xp'
}
task removeDocNav() {
doLast {
description 'Deletes specific lines in _data/naviation.yml'
File nav = file('site-source/_data/navigation.yml')
String fullNav = nav.getText()
String removedNav = fullNav
.replaceAll(/(?m)# @xp:start$\s(^[\D\d]*$\s)*^# @xp:end/, "# @xp:toc")
nav.setText(removedNav)
}
}
task removeXpFromHome {
doLast {
description 'Removes XP excerpt from _site-source/_pages/home.md'
File home = file('site-source/_pages/home.md')
String homeText = home.getText()
String homeTextWithoutXpExcerpt = homeText.replaceAll(/(?m)^excerpt: .*/, "excerpt: @xp:excerpt")
home.setText(homeTextWithoutXpExcerpt)
}
}
task clean {
dependsOn removeProjectPage, removeDemos, removeDocs, removeDocNav, removeXpFromHome
}
// ------
// CREATE
// ------
task copyPioneerProjectPage(type: Copy) {
from 'junit-pioneer/docs/'
include 'project-page.*'
rename 'project-page.adoc', 'xp.adoc'
into 'site-source/_pages'
}
task copyPioneerDemos(type: Copy) {
from 'junit-pioneer/src/demo/java'
into 'site-source/_demos/xp'
}
task copyPioneerDocs(type: Copy) {
from 'junit-pioneer/docs'
exclude 'project-page.*', 'docs-nav.yml', 'project-logo.jpg'
into 'site-source/_docs/xp'
}
task insertDocNav() {
doLast {
description 'Inserts specific lines into _data/naviation.yml'
File navTarget = file('site-source/_data/navigation.yml')
String emptyNav = navTarget.getText()
String xpNavContent = file('junit-pioneer/docs/docs-nav.yml').getText()
String fullNav = emptyNav
.replaceAll(/(?m)# @xp:toc/, "# @xp:start\n${xpNavContent}# @xp:end")
navTarget.setText(fullNav)
}
}
task insertVersion() {
dependsOn copyPioneerProjectPage
doLast {
description 'Inserts current versions into about pages'
insertProjectVersion('junit-pioneer', 'xp')
}
}
import org.ajoberstar.grgit.Grgit
import org.ajoberstar.grgit.Tag
def insertProjectVersion(String project, String abbreviation) {
List<Tag> tags = Grgit
.open(dir: project)
.tag
.list()
if (tags.isEmpty())
throw new IllegalStateException("No tags available for ${project}.")
String latestTagName = tags
.sort { it.commit.dateTime }
.last()
.name
if (!latestTagName.startsWith("v"))
throw new IllegalStateException("Could not determine version of ${project}.")
String version = latestTagName.substring(1)
File about = file("site-source/_pages/${abbreviation}.adoc")
String aboutText = about.getText()
String aboutTextWithVersion = aboutText.replaceAll("@${abbreviation}:version", version)
about.setText(aboutTextWithVersion)
}
task insertXpIntoHome() {
dependsOn insertVersion
doLast {
description 'Inserts XP excerpt into _site-source/_pages/home.md'
String xpContent = file('site-source/_pages/xp.adoc').getText()
String excerpt = xpContent.find(/excerpt: .*/)
File home = file('site-source/_pages/home.md')
String homeText = home.getText()
String homeTextWithXpExcerpt = homeText.replaceAll(/(?m)^excerpt: @xp:excerpt/, excerpt)
home.setText(homeTextWithXpExcerpt)
}
}
task create {
dependsOn copyPioneerProjectPage, copyPioneerDemos, copyPioneerDocs, insertDocNav, insertVersion, insertXpIntoHome
}
// -----
// BUILD
// -----
task recreate {
dependsOn clean, create
}
task buildSite(type: Exec) {
dependsOn recreate
workingDir 'site-source'
commandLine 'bundle exec jekyll build --destination ../site'.split(' ')
}
// -------
// PUBLISH
// -------
task pushSite(type: Exec) {
commandLine './git-commit-push.sh'
}
task publishSite {
dependsOn buildSite, pushSite
pushSite.mustRunAfter buildSite
}