diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..b13910c8 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: + - package-ecosystem: "gradle" + directory: "/" + schedule: + interval: "weekly" + assignees: + - "johnflavin" diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 00000000..8c0f5b46 --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,89 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle + +name: Java CI with Gradle + +on: + push: + branches: [ "main", "develop" ] + pull_request: + branches: [ "main", "develop" ] + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: '8' + distribution: 'corretto' + + # Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies. + # See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md + - name: Setup Gradle + uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 + + - name: Build with Gradle Wrapper + run: ./gradlew fatJar + - uses: actions/upload-artifact@v4 + with: + name: Package + path: build/libs + + test: + + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: '8' + distribution: 'corretto' + + # Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies. + # See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md + - name: Setup Gradle + uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 + + - name: Build with Gradle Wrapper + run: ./gradlew test + + - name: Upload test artifacts + run: mkdir staging && cp -r build/reports staging/ && cp -r build/test-results staging/ + - uses: actions/upload-artifact@v4 + with: + name: Test Results + path: staging + + dependency-submission: + + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: '8' + distribution: 'corretto' + + # Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies. + # See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md + - name: Generate and submit dependency graph + uses: gradle/actions/dependency-submission@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 diff --git a/build.gradle b/build.gradle index e1f5402d..b6b5373e 100644 --- a/build.gradle +++ b/build.gradle @@ -8,11 +8,9 @@ buildscript { plugins { id "idea" id "java" - id "maven-publish" - id "com.palantir.git-version" version "0.12.1" + id "com.palantir.git-version" version "3.1.0" id "io.spring.dependency-management" version "1.0.9.RELEASE" id "io.franzbecker.gradle-lombok" version "4.0.0" - id "net.linguica.maven-settings" version "0.5" } group "org.nrg.xnatx.plugins" @@ -26,7 +24,6 @@ def vJavassist = "3.21.0-GA" def vAwaitility = "2.0.0" repositories { - mavenLocal() maven { url "https://nrgxnat.jfrog.io/nrgxnat/libs-release" } maven { url "https://nrgxnat.jfrog.io/nrgxnat/libs-snapshot" } mavenCentral() @@ -210,42 +207,35 @@ tasks.register ( 'integrationTest', Test ) { test } -// Pulls in the Jenkins BUILD_NUMBER environment variable if available. -def buildDate = new Date() -def buildNumber = System.getenv().BUILD_NUMBER?.toInteger() ?: "Manual" -def isDirty, branchName, gitHash, gitHashFull, commitDistance, lastTag, isCleanTag - +// Build manifest from git repo information, if available +def gitDetails, isDirty try { - def gitDetails = versionDetails() + gitDetails = versionDetails() isDirty = gitVersion().endsWith ".dirty" - branchName = gitDetails.branchName ?: "Unknown" - gitHash = gitDetails.gitHash - gitHashFull = gitDetails.gitHashFull - commitDistance = gitDetails.commitDistance - lastTag = gitDetails.lastTag - isCleanTag = gitDetails.isCleanTag -} catch (IllegalArgumentException e) { +} catch (ignored) { 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." + gitDetails = [ + branchName: "Unknown", + gitHash: "None", + gitHashFull: "None", + commitDistance: 0, + lastTag: "None", + isCleanTag: false + ] isDirty = true - branchName = "Unknown" - gitHash = "None" - gitHashFull = "None" - commitDistance = 0 - lastTag = "None" - isCleanTag = false } -ext.gitManifest = manifest { +def sharedManifest = java.manifest { attributes "Application-Name": pluginAppName, - "Build-Date": buildDate, - "Build-Number": buildNumber, + "Build-Date": new Date(), + "Build-Number": System.getenv().BUILD_NUMBER?.toInteger() ?: "Manual", // Pulls in the Jenkins BUILD_NUMBER environment variable if available. "Implementation-Version": project.version, - "Implementation-Sha": gitHash, - "Implementation-Sha-Full": gitHashFull, - "Implementation-Commit": commitDistance, - "Implementation-LastTag": lastTag, - "Implementation-Branch": branchName, - "Implementation-CleanTag": isCleanTag, + "Implementation-Sha": gitDetails.gitHash, + "Implementation-Sha-Full": gitDetails.gitHashFull, + "Implementation-Commit": gitDetails.commitDistance, + "Implementation-LastTag": gitDetails.lastTag, + "Implementation-Branch": gitDetails.branchName ?: "Unknown", + "Implementation-CleanTag": gitDetails.isCleanTag, "Implementation-Dirty": isDirty } @@ -260,8 +250,8 @@ task fatJar(type: Jar) { exclude "META-INF/*.RSA" } duplicatesStrategy "exclude" - manifest { - from gitManifest + manifest = java.manifest { + from sharedManifest } with jar } @@ -271,9 +261,9 @@ sourceSets.main.java { exclude "*/AutoValue.java" } -jar{ - manifest { - from gitManifest +jar { + manifest = java.manifest { + from sharedManifest } doLast { if (!gradle.taskGraph.hasTask(":fatJar")) { @@ -284,78 +274,73 @@ jar{ task sourceJar(type: Jar, dependsOn: classes) { classifier = "sources" - manifest { - from gitManifest + manifest = java.manifest { + from sharedManifest } from sourceSets.main.allSource } task javadocJar(type: Jar, dependsOn: javadoc) { classifier = "javadoc" - manifest { - from gitManifest + manifest = java.manifest { + from sharedManifest } from javadoc.destinationDir } -publishing { - publications { - mavenJava(MavenPublication) { - artifacts { - artifact sourceJar - artifact javadocJar - artifact fatJar - } - - pom.withXml { - def root = asNode() - root.appendNode("name", pluginAppName) - root.appendNode("description", "XNAT plugin for launching and managing containers.") - root.appendNode("url", "https://github.com/nrgxnat/container-service") - root.appendNode("inceptionYear", "2016") - - def scm = root.appendNode("scm") - scm.appendNode("url", "https://github.com/nrgxnat/container-service") - scm.appendNode("connection", "scm:https://github.com/nrgxnat/container-service.git") - scm.appendNode("developerConnection", "scm:git@github.com:nrgxnat/container-service") - - def license = root.appendNode("licenses").appendNode("license") - license.appendNode("name", "Simplified BSD 2-Clause License") - license.appendNode("url", "https://xnat.org/about/license.php") - license.appendNode("distribution", "repo") - - def developers = root.appendNode("developers") - def flavin = developers.appendNode("developer") - flavin.appendNode("id", "jflavin") - flavin.appendNode("name", "John Flavin") - flavin.appendNode("email", "jflavin@wustl.edu") - - def kelsey = developers.appendNode("developer") - kelsey.appendNode("id", "kelseym") - kelsey.appendNode("name", "Matt Kelsey") - kelsey.appendNode("email", "kelseym@wustl.edu") - - def will = developers.appendNode("developer") - will.appendNode("id", "hortonw") - will.appendNode("name", "Will Horton") - will.appendNode("email", "hortonw@wustl.edu") - } - } - } - repositories { - maven { - if (project.version.endsWith("-SNAPSHOT")) { - url "https://nrgxnat.jfrog.io/nrgxnat/libs-snapshot-local" - } else { - url "https://nrgxnat.jfrog.io/nrgxnat/libs-release-local" - } - // The value for name must match in ~/.m2/settings.xml - name = "XNAT_Artifactory" - } - } -} - -def propertyWithDefault(def String property, def Object value) { - hasProperty(property) ? getProperty(property) : value -} - +//publishing { +// publications { +// mavenJava(MavenPublication) { +// artifacts { +// artifact sourceJar +// artifact javadocJar +// artifact fatJar +// } +// +// pom.withXml { +// def root = asNode() +// root.appendNode("name", pluginAppName) +// root.appendNode("description", "XNAT plugin for launching and managing containers.") +// root.appendNode("url", "https://github.com/nrgxnat/container-service") +// root.appendNode("inceptionYear", "2016") +// +// def scm = root.appendNode("scm") +// scm.appendNode("url", "https://github.com/nrgxnat/container-service") +// scm.appendNode("connection", "scm:https://github.com/nrgxnat/container-service.git") +// scm.appendNode("developerConnection", "scm:git@github.com:nrgxnat/container-service") +// +// def license = root.appendNode("licenses").appendNode("license") +// license.appendNode("name", "Simplified BSD 2-Clause License") +// license.appendNode("url", "https://xnat.org/about/license.php") +// license.appendNode("distribution", "repo") +// +// def developers = root.appendNode("developers") +// def flavin = developers.appendNode("developer") +// flavin.appendNode("id", "jflavin") +// flavin.appendNode("name", "John Flavin") +// flavin.appendNode("email", "jflavin@wustl.edu") +// +// def kelsey = developers.appendNode("developer") +// kelsey.appendNode("id", "kelseym") +// kelsey.appendNode("name", "Matt Kelsey") +// kelsey.appendNode("email", "kelseym@wustl.edu") +// +// def will = developers.appendNode("developer") +// will.appendNode("id", "hortonw") +// will.appendNode("name", "Will Horton") +// will.appendNode("email", "hortonw@wustl.edu") +// } +// } +// } +// repositories { +// maven { +// if (project.version.endsWith("-SNAPSHOT")) { +// url "https://nrgxnat.jfrog.io/nrgxnat/libs-snapshot-local" +// } else { +// url "https://nrgxnat.jfrog.io/nrgxnat/libs-release-local" +// } +// // The value for name must match in ~/.m2/settings.xml +// name = "XNAT_Artifactory" +// } +// } +//}