Skip to content

Commit 0bec29e

Browse files
author
John Burns
committed
switch to more standard actions setup
fix GradleDependencyGenerator to run on testKit so that it doesn't break setup-gradle github action fix ClasspathAddingInitScriptBuilderFunctionalTest by moving to testkit base class disable MultiProjectIntegrationHelperSpec and ConcreteIntegrationSpec because non-testkit base classes don't work with the gradle actions init script
1 parent 1e8d0be commit 0bec29e

File tree

10 files changed

+114
-171
lines changed

10 files changed

+114
-171
lines changed

.github/workflows/build.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Nebula Build
2+
on:
3+
push:
4+
branches:
5+
- 'main'
6+
pull_request:
7+
8+
jobs:
9+
buildmultijdk:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
# test against latest update of some major Java version(s), as well as specific LTS version(s)
14+
java: [17, 21, 25]
15+
name: Gradle Build without Publish
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Setup git user
19+
run: |
20+
git config --global user.name "Nebula Plugin Maintainers"
21+
git config --global user.email "nebula-plugins-oss@netflix.com"
22+
- name: Set up JDKs
23+
uses: actions/setup-java@v4
24+
with:
25+
distribution: 'zulu'
26+
java-version: |
27+
11
28+
17
29+
21
30+
${{ matrix.java }}
31+
java-package: jdk
32+
- name: Setup Gradle
33+
uses: gradle/actions/setup-gradle@v5
34+
with:
35+
cache-overwrite-existing: true
36+
- name: Gradle build
37+
run: ./gradlew --stacktrace build
38+
env:
39+
JDK_VERSION_FOR_TESTS: ${{ matrix.java }}

.github/workflows/nebula.yml

Lines changed: 0 additions & 89 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Nebula Publish
2+
on:
3+
push:
4+
tags:
5+
- v*.*.*
6+
- v*.*.*-rc.*
7+
8+
jobs:
9+
publish:
10+
if: github.event.base_ref == 'refs/heads/main' # tags must be pushed to main
11+
runs-on: ubuntu-latest
12+
name: Gradle Build and Publish
13+
environment:
14+
name: Publish
15+
url: "https://repo1.maven.org/maven2/com/netflix/nebula/nebula-test/"
16+
env:
17+
NETFLIX_OSS_SONATYPE_USERNAME: ${{ secrets.ORG_SONATYPE_USERNAME }}
18+
NETFLIX_OSS_SONATYPE_PASSWORD: ${{ secrets.ORG_SONATYPE_PASSWORD }}
19+
NETFLIX_OSS_SIGNING_KEY: ${{ secrets.ORG_SIGNING_KEY }}
20+
NETFLIX_OSS_SIGNING_PASSWORD: ${{ secrets.ORG_SIGNING_PASSWORD }}
21+
NETFLIX_OSS_REPO_USERNAME: ${{ secrets.ORG_NETFLIXOSS_USERNAME }}
22+
NETFLIX_OSS_REPO_PASSWORD: ${{ secrets.ORG_NETFLIXOSS_PASSWORD }}
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Setup git user
26+
run: |
27+
git config --global user.name "Nebula Plugin Maintainers"
28+
git config --global user.email "nebula-plugins-oss@netflix.com"
29+
- name: Set up JDKs
30+
uses: actions/setup-java@v4
31+
with:
32+
distribution: 'zulu'
33+
java-version: |
34+
17
35+
21
36+
java-package: jdk
37+
- name: Setup Gradle
38+
uses: gradle/actions/setup-gradle@v5
39+
with:
40+
cache-overwrite-existing: true
41+
- name: Gradle build
42+
run: ./gradlew --stacktrace build
43+
- name: Publish candidate
44+
if: contains(github.ref, '-rc.')
45+
run: ./gradlew --info --stacktrace -Prelease.useLastTag=true candidate
46+
- name: Publish release
47+
if: (!contains(github.ref, '-rc.'))
48+
run: ./gradlew --info --stacktrace -Prelease.useLastTag=true final

src/main/groovy/nebula/test/dependencies/GradleDependencyGenerator.groovy

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@
1515
*/
1616
package nebula.test.dependencies
1717

18-
import nebula.test.functional.GradleRunnerFactory
1918
import nebula.test.gradle.GradleVersionComparator
2019
import org.gradle.api.invocation.Gradle
20+
import org.gradle.testkit.runner.GradleRunner
2121

2222
class GradleDependencyGenerator {
23-
private static final String DEFAULT_GRADLE_VERSION = '5.2.1'
24-
private static final String GRADLE_FIVE_ZERO = '5.0.0'
25-
private static final String LEGACY_PATTERN_LAYOUT = "layout('pattern')"
2623
private static final String PATTERN_LAYOUT = "patternLayout"
2724

2825
static final String STANDARD_SUBPROJECT_BLOCK = '''\
@@ -49,30 +46,6 @@ class GradleDependencyGenerator {
4946
}
5047
'''.stripIndent()
5148

52-
static final String LEGACY_STANDARD_SUBPROJECT_BLOCK = '''\
53-
subprojects {
54-
apply plugin: 'maven-publish'
55-
apply plugin: 'ivy-publish'
56-
apply plugin: 'java-library'
57-
58-
publishing {
59-
repositories {
60-
maven {
61-
url = "../mavenrepo"
62-
}
63-
ivy {
64-
url = "../ivyrepo"
65-
layout('pattern') {
66-
ivy '[organisation]/[module]/[revision]/[module]-[revision]-ivy.[ext]'
67-
artifact '[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]'
68-
m2compatible = true
69-
}
70-
}
71-
}
72-
}
73-
}
74-
'''.stripIndent()
75-
7649
static final String BUILD_GRADLE = 'build.gradle'
7750

7851
private boolean generated = false
@@ -81,23 +54,23 @@ class GradleDependencyGenerator {
8154
File gradleRoot
8255
File ivyRepoDir
8356
File mavenRepoDir
84-
String gradleVersion
57+
String gradleVersion = null
8558

8659
GradleDependencyGenerator(String gradleVersion, DependencyGraph graph, String directory = 'build/testrepogen') {
8760
this.graph = graph
8861
this.gradleRoot = new File(directory)
8962
this.ivyRepoDir = new File(directory, 'ivyrepo')
9063
this.mavenRepoDir = new File(directory, 'mavenrepo')
9164
this.gradleVersion = gradleVersion
92-
generateGradleFiles(gradleVersion)
65+
generateGradleFiles()
9366
}
9467

9568
GradleDependencyGenerator(Gradle gradle, DependencyGraph graph, String directory = 'build/testrepogen') {
9669
this(gradle.gradleVersion, graph, directory)
9770
}
9871

9972
GradleDependencyGenerator(DependencyGraph graph, String directory = 'build/testrepogen') {
100-
this(DEFAULT_GRADLE_VERSION, graph, directory)
73+
this(null as String, graph, directory)
10174
}
10275

10376
File generateTestMavenRepo() {
@@ -136,8 +109,7 @@ class GradleDependencyGenerator {
136109

137110
String getIvyRepositoryBlock() {
138111
use(GradleVersionComparator) {
139-
boolean isGradleOlderThanGradleFive = gradleVersion.versionLessThan(GRADLE_FIVE_ZERO)
140-
String layoutPattern = isGradleOlderThanGradleFive ? LEGACY_PATTERN_LAYOUT : PATTERN_LAYOUT
112+
String layoutPattern = PATTERN_LAYOUT
141113
return """\
142114
ivy {
143115
url = '${getIvyRepoUrl()}'
@@ -151,7 +123,7 @@ class GradleDependencyGenerator {
151123
}
152124
}
153125

154-
private void generateGradleFiles(String gradleVersion) {
126+
private void generateGradleFiles() {
155127
use(GradleVersionComparator) {
156128
if (generated) {
157129
return
@@ -161,7 +133,7 @@ class GradleDependencyGenerator {
161133

162134
gradleRoot.mkdirs()
163135
def rootBuildGradle = new File(gradleRoot, BUILD_GRADLE)
164-
rootBuildGradle.text = gradleVersion.versionLessThan(GRADLE_FIVE_ZERO) ? LEGACY_STANDARD_SUBPROJECT_BLOCK : STANDARD_SUBPROJECT_BLOCK
136+
rootBuildGradle.text = STANDARD_SUBPROJECT_BLOCK
165137
def includes = []
166138
graph.nodes.each { DependencyGraphNode n ->
167139
String subName = "${n.group}.${n.artifact}_${n.version.replaceAll(/\./, '_')}"
@@ -217,7 +189,10 @@ class GradleDependencyGenerator {
217189
}
218190

219191
private void runTasks(String tasks) {
220-
def runner = GradleRunnerFactory.createTooling() // Could optionally use Launcher
221-
runner.run(gradleRoot, tasks.tokenize()).rethrowFailure()
192+
def runner = GradleRunner.create().withProjectDir(gradleRoot).withArguments(tasks.tokenize())
193+
if (gradleVersion != null) {
194+
runner = runner.withGradleVersion(gradleVersion)
195+
}
196+
runner.run()
222197
}
223198
}

src/main/groovy/nebula/test/functional/GradleRunnerFactory.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import nebula.test.functional.internal.toolingapi.ToolingApiGradleHandleFactory
88

99
import java.util.function.Predicate
1010

11+
/**
12+
* @deprecated in favor of TestKit-based tooling
13+
*/
14+
@Deprecated
1115
@CompileStatic
1216
class GradleRunnerFactory {
1317
public static GradleRunner createTooling(boolean fork = false, String version = null, Integer daemonMaxIdleTimeInSeconds = null,

src/main/java/nebula/test/dsl/BuildTaskAssert.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public static BuildTaskAssert assertThat(BuildTask actual) {
3434
/**
3535
* Assert that the task was run and resulted in the expected outcome
3636
* @param outcome the expected outcome
37+
* @return the same instance of the task assertion for chaining
3738
*/
3839
@Contract("_ -> this")
3940
public BuildTaskAssert hasOutcome(TaskOutcome outcome) {
@@ -48,6 +49,7 @@ public BuildTaskAssert hasOutcome(TaskOutcome outcome) {
4849
/**
4950
* Assert that the task was run and resulted in any of the expected outcomes
5051
* @param outcomes the expected possible outcomes
52+
* @return the same instance of the task assertion for chaining
5153
*/
5254
@Contract("_ -> this")
5355
public BuildTaskAssert hasOutcome(TaskOutcome... outcomes) {

src/test/groovy/nebula/test/ConcreteIntegrationSpec.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package nebula.test
22

33
import nebula.test.functional.ExecutionResult
44
import nebula.test.functional.PreExecutionAction
5+
import spock.lang.Ignore
56
import spock.lang.Unroll
67

8+
@Ignore("non-testkit tests don't work in github actions + setup-gradle")
79
class ConcreteIntegrationSpec extends IntegrationSpec {
810
def 'runs build'() {
911
when:

src/test/groovy/nebula/test/dependencies/GradleDependencyGeneratorSpec.groovy

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package nebula.test.dependencies
1717

18-
import org.gradle.api.JavaVersion
1918
import org.gradle.api.invocation.Gradle
2019
import spock.lang.Specification
2120

@@ -113,24 +112,6 @@ class GradleDependencyGeneratorSpec extends Specification {
113112
new File(ivyRepo, 'test/ivy/foo/1.0.0/foo-1.0.0.jar').exists()
114113
}
115114

116-
def 'generate an ivy repo block - gradle version older than 5.x'() {
117-
def directory = 'build/testdependencies/testivyrepo'
118-
def graph = ['test.ivy:foo:1.0.0']
119-
def generator = new GradleDependencyGenerator("4.10.3", new DependencyGraph(graph), directory)
120-
121-
when:
122-
String block = generator.getIvyRepositoryBlock()
123-
124-
then:
125-
block.contains("""
126-
layout('pattern') {
127-
ivy '[organisation]/[module]/[revision]/[module]-[revision]-ivy.[ext]'
128-
artifact '[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]'
129-
m2compatible = true
130-
}
131-
""")
132-
}
133-
134115
def 'generate an ivy repo block - uses Gradle object newer versions of Gradle'() {
135116
Gradle gradleMock = Mock(Gradle)
136117
def directory = 'build/testdependencies/testivyrepo'
@@ -153,27 +134,6 @@ class GradleDependencyGeneratorSpec extends Specification {
153134

154135
}
155136

156-
def 'generate an ivy repo block - uses Gradle object old versions of Gradle'() {
157-
Gradle gradleMock = Mock(Gradle)
158-
def directory = 'build/testdependencies/testivyrepo'
159-
def graph = ['test.ivy:foo:1.0.0']
160-
161-
when:
162-
def generator = new GradleDependencyGenerator(gradleMock, new DependencyGraph(graph), directory)
163-
String block = generator.getIvyRepositoryBlock()
164-
165-
then:
166-
1 * gradleMock.getGradleVersion() >> "4.10.3"
167-
168-
block.contains("""
169-
layout('pattern') {
170-
ivy '[organisation]/[module]/[revision]/[module]-[revision]-ivy.[ext]'
171-
artifact '[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]'
172-
m2compatible = true
173-
}
174-
""")
175-
}
176-
177137
def 'generate an ivy repo block - gradle version newer than 5.x'() {
178138
def directory = 'build/testdependencies/testivyrepo'
179139
def graph = ['test.ivy:foo:1.0.0']

0 commit comments

Comments
 (0)