Skip to content

Commit 5cef775

Browse files
authored
Add GitHub CI files (#16)
* Add dependabot file * Add gradle build workflow * Clean up / modify jar manifest definition * Add some logging around manifest definition (for testing purposes) * Modify how manifest is built and exception is caught * Update version of git-details plugin * Remove maven settings plugin and mavenLocal repository * Remove maven publishing
1 parent a8f4615 commit 5cef775

File tree

3 files changed

+184
-102
lines changed

3 files changed

+184
-102
lines changed

.github/dependabot.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "gradle"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
assignees:
8+
- "johnflavin"

.github/workflows/gradle.yml

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
6+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
7+
8+
name: Java CI with Gradle
9+
10+
on:
11+
push:
12+
branches: [ "main", "develop" ]
13+
pull_request:
14+
branches: [ "main", "develop" ]
15+
16+
jobs:
17+
build:
18+
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Set up JDK
26+
uses: actions/setup-java@v4
27+
with:
28+
java-version: '8'
29+
distribution: 'corretto'
30+
31+
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
32+
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
33+
- name: Setup Gradle
34+
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
35+
36+
- name: Build with Gradle Wrapper
37+
run: ./gradlew fatJar
38+
- uses: actions/upload-artifact@v4
39+
with:
40+
name: Package
41+
path: build/libs
42+
43+
test:
44+
45+
runs-on: ubuntu-latest
46+
permissions:
47+
contents: read
48+
49+
steps:
50+
- uses: actions/checkout@v4
51+
- name: Set up JDK
52+
uses: actions/setup-java@v4
53+
with:
54+
java-version: '8'
55+
distribution: 'corretto'
56+
57+
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
58+
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
59+
- name: Setup Gradle
60+
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
61+
62+
- name: Build with Gradle Wrapper
63+
run: ./gradlew test
64+
65+
- name: Upload test artifacts
66+
run: mkdir staging && cp -r build/reports staging/ && cp -r build/test-results staging/
67+
- uses: actions/upload-artifact@v4
68+
with:
69+
name: Test Results
70+
path: staging
71+
72+
dependency-submission:
73+
74+
runs-on: ubuntu-latest
75+
permissions:
76+
contents: write
77+
78+
steps:
79+
- uses: actions/checkout@v4
80+
- name: Set up JDK
81+
uses: actions/setup-java@v4
82+
with:
83+
java-version: '8'
84+
distribution: 'corretto'
85+
86+
# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
87+
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
88+
- name: Generate and submit dependency graph
89+
uses: gradle/actions/dependency-submission@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

build.gradle

+87-102
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ buildscript {
88
plugins {
99
id "idea"
1010
id "java"
11-
id "maven-publish"
12-
id "com.palantir.git-version" version "0.12.1"
11+
id "com.palantir.git-version" version "3.1.0"
1312
id "io.spring.dependency-management" version "1.0.9.RELEASE"
1413
id "io.franzbecker.gradle-lombok" version "4.0.0"
15-
id "net.linguica.maven-settings" version "0.5"
1614
}
1715

1816
group "org.nrg.xnatx.plugins"
@@ -26,7 +24,6 @@ def vJavassist = "3.21.0-GA"
2624
def vAwaitility = "2.0.0"
2725

2826
repositories {
29-
mavenLocal()
3027
maven { url "https://nrgxnat.jfrog.io/nrgxnat/libs-release" }
3128
maven { url "https://nrgxnat.jfrog.io/nrgxnat/libs-snapshot" }
3229
mavenCentral()
@@ -207,42 +204,35 @@ tasks.register ( 'integrationTest', Test ) {
207204
test
208205
}
209206

210-
// Pulls in the Jenkins BUILD_NUMBER environment variable if available.
211-
def buildDate = new Date()
212-
def buildNumber = System.getenv().BUILD_NUMBER?.toInteger() ?: "Manual"
213-
def isDirty, branchName, gitHash, gitHashFull, commitDistance, lastTag, isCleanTag
214-
207+
// Build manifest from git repo information, if available
208+
def gitDetails, isDirty
215209
try {
216-
def gitDetails = versionDetails()
210+
gitDetails = versionDetails()
217211
isDirty = gitVersion().endsWith ".dirty"
218-
branchName = gitDetails.branchName ?: "Unknown"
219-
gitHash = gitDetails.gitHash
220-
gitHashFull = gitDetails.gitHashFull
221-
commitDistance = gitDetails.commitDistance
222-
lastTag = gitDetails.lastTag
223-
isCleanTag = gitDetails.isCleanTag
224-
} catch (IllegalArgumentException e) {
212+
} catch (ignored) {
225213
logger.info "Got an error trying to read VCS metadata from git. It's possible this project is not under VCS control. Using placeholder values for manifest entries."
214+
gitDetails = [
215+
branchName: "Unknown",
216+
gitHash: "None",
217+
gitHashFull: "None",
218+
commitDistance: 0,
219+
lastTag: "None",
220+
isCleanTag: false
221+
]
226222
isDirty = true
227-
branchName = "Unknown"
228-
gitHash = "None"
229-
gitHashFull = "None"
230-
commitDistance = 0
231-
lastTag = "None"
232-
isCleanTag = false
233223
}
234224

235-
ext.gitManifest = manifest {
225+
def sharedManifest = java.manifest {
236226
attributes "Application-Name": pluginAppName,
237-
"Build-Date": buildDate,
238-
"Build-Number": buildNumber,
227+
"Build-Date": new Date(),
228+
"Build-Number": System.getenv().BUILD_NUMBER?.toInteger() ?: "Manual", // Pulls in the Jenkins BUILD_NUMBER environment variable if available.
239229
"Implementation-Version": project.version,
240-
"Implementation-Sha": gitHash,
241-
"Implementation-Sha-Full": gitHashFull,
242-
"Implementation-Commit": commitDistance,
243-
"Implementation-LastTag": lastTag,
244-
"Implementation-Branch": branchName,
245-
"Implementation-CleanTag": isCleanTag,
230+
"Implementation-Sha": gitDetails.gitHash,
231+
"Implementation-Sha-Full": gitDetails.gitHashFull,
232+
"Implementation-Commit": gitDetails.commitDistance,
233+
"Implementation-LastTag": gitDetails.lastTag,
234+
"Implementation-Branch": gitDetails.branchName ?: "Unknown",
235+
"Implementation-CleanTag": gitDetails.isCleanTag,
246236
"Implementation-Dirty": isDirty
247237
}
248238

@@ -257,8 +247,8 @@ task fatJar(type: Jar) {
257247
exclude "META-INF/*.RSA"
258248
}
259249
duplicatesStrategy "exclude"
260-
manifest {
261-
from gitManifest
250+
manifest = java.manifest {
251+
from sharedManifest
262252
}
263253
with jar
264254
}
@@ -268,9 +258,9 @@ sourceSets.main.java {
268258
exclude "*/AutoValue.java"
269259
}
270260

271-
jar{
272-
manifest {
273-
from gitManifest
261+
jar {
262+
manifest = java.manifest {
263+
from sharedManifest
274264
}
275265
doLast {
276266
if (!gradle.taskGraph.hasTask(":fatJar")) {
@@ -281,78 +271,73 @@ jar{
281271

282272
task sourceJar(type: Jar, dependsOn: classes) {
283273
classifier = "sources"
284-
manifest {
285-
from gitManifest
274+
manifest = java.manifest {
275+
from sharedManifest
286276
}
287277
from sourceSets.main.allSource
288278
}
289279

290280
task javadocJar(type: Jar, dependsOn: javadoc) {
291281
classifier = "javadoc"
292-
manifest {
293-
from gitManifest
282+
manifest = java.manifest {
283+
from sharedManifest
294284
}
295285
from javadoc.destinationDir
296286
}
297287

298-
publishing {
299-
publications {
300-
mavenJava(MavenPublication) {
301-
artifacts {
302-
artifact sourceJar
303-
artifact javadocJar
304-
artifact fatJar
305-
}
306-
307-
pom.withXml {
308-
def root = asNode()
309-
root.appendNode("name", pluginAppName)
310-
root.appendNode("description", "XNAT plugin for launching and managing containers.")
311-
root.appendNode("url", "https://github.com/nrgxnat/container-service")
312-
root.appendNode("inceptionYear", "2016")
313-
314-
def scm = root.appendNode("scm")
315-
scm.appendNode("url", "https://github.com/nrgxnat/container-service")
316-
scm.appendNode("connection", "scm:https://github.com/nrgxnat/container-service.git")
317-
scm.appendNode("developerConnection", "scm:git@github.com:nrgxnat/container-service")
318-
319-
def license = root.appendNode("licenses").appendNode("license")
320-
license.appendNode("name", "Simplified BSD 2-Clause License")
321-
license.appendNode("url", "https://xnat.org/about/license.php")
322-
license.appendNode("distribution", "repo")
323-
324-
def developers = root.appendNode("developers")
325-
def flavin = developers.appendNode("developer")
326-
flavin.appendNode("id", "jflavin")
327-
flavin.appendNode("name", "John Flavin")
328-
flavin.appendNode("email", "jflavin@wustl.edu")
329-
330-
def kelsey = developers.appendNode("developer")
331-
kelsey.appendNode("id", "kelseym")
332-
kelsey.appendNode("name", "Matt Kelsey")
333-
kelsey.appendNode("email", "kelseym@wustl.edu")
334-
335-
def will = developers.appendNode("developer")
336-
will.appendNode("id", "hortonw")
337-
will.appendNode("name", "Will Horton")
338-
will.appendNode("email", "hortonw@wustl.edu")
339-
}
340-
}
341-
}
342-
repositories {
343-
maven {
344-
if (project.version.endsWith("-SNAPSHOT")) {
345-
url "https://nrgxnat.jfrog.io/nrgxnat/libs-snapshot-local"
346-
} else {
347-
url "https://nrgxnat.jfrog.io/nrgxnat/libs-release-local"
348-
}
349-
// The value for name must match <id> in ~/.m2/settings.xml
350-
name = "XNAT_Artifactory"
351-
}
352-
}
353-
}
354-
355-
def propertyWithDefault(def String property, def Object value) {
356-
hasProperty(property) ? getProperty(property) : value
357-
}
358-
288+
//publishing {
289+
// publications {
290+
// mavenJava(MavenPublication) {
291+
// artifacts {
292+
// artifact sourceJar
293+
// artifact javadocJar
294+
// artifact fatJar
295+
// }
296+
//
297+
// pom.withXml {
298+
// def root = asNode()
299+
// root.appendNode("name", pluginAppName)
300+
// root.appendNode("description", "XNAT plugin for launching and managing containers.")
301+
// root.appendNode("url", "https://github.com/nrgxnat/container-service")
302+
// root.appendNode("inceptionYear", "2016")
303+
//
304+
// def scm = root.appendNode("scm")
305+
// scm.appendNode("url", "https://github.com/nrgxnat/container-service")
306+
// scm.appendNode("connection", "scm:https://github.com/nrgxnat/container-service.git")
307+
// scm.appendNode("developerConnection", "scm:git@github.com:nrgxnat/container-service")
308+
//
309+
// def license = root.appendNode("licenses").appendNode("license")
310+
// license.appendNode("name", "Simplified BSD 2-Clause License")
311+
// license.appendNode("url", "https://xnat.org/about/license.php")
312+
// license.appendNode("distribution", "repo")
313+
//
314+
// def developers = root.appendNode("developers")
315+
// def flavin = developers.appendNode("developer")
316+
// flavin.appendNode("id", "jflavin")
317+
// flavin.appendNode("name", "John Flavin")
318+
// flavin.appendNode("email", "jflavin@wustl.edu")
319+
//
320+
// def kelsey = developers.appendNode("developer")
321+
// kelsey.appendNode("id", "kelseym")
322+
// kelsey.appendNode("name", "Matt Kelsey")
323+
// kelsey.appendNode("email", "kelseym@wustl.edu")
324+
//
325+
// def will = developers.appendNode("developer")
326+
// will.appendNode("id", "hortonw")
327+
// will.appendNode("name", "Will Horton")
328+
// will.appendNode("email", "hortonw@wustl.edu")
329+
// }
330+
// }
331+
// }
332+
// repositories {
333+
// maven {
334+
// if (project.version.endsWith("-SNAPSHOT")) {
335+
// url "https://nrgxnat.jfrog.io/nrgxnat/libs-snapshot-local"
336+
// } else {
337+
// url "https://nrgxnat.jfrog.io/nrgxnat/libs-release-local"
338+
// }
339+
// // The value for name must match <id> in ~/.m2/settings.xml
340+
// name = "XNAT_Artifactory"
341+
// }
342+
// }
343+
//}

0 commit comments

Comments
 (0)