Skip to content

Commit

Permalink
Run compileTypescript and compileConjure as a dependency of `buil…
Browse files Browse the repository at this point in the history
…d` (#1349)

Run `compileTypescript` and `compileConjure` as a dependency of `build` to catch more failure at PR time rather than publish time.
  • Loading branch information
CRogers authored Feb 9, 2024
1 parent 38c4a26 commit 988da10
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-1349.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: fix
fix:
description: Run `compileTypescript` and `compileConjure` as a dependency of `build`
to catch more failure at PR time rather than publish time.
links:
- https://github.com/palantir/gradle-conjure/pull/1349
1 change: 1 addition & 0 deletions gradle-conjure/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
implementation 'commons-io:commons-io'
implementation 'org.apache.commons:commons-lang3'
implementation 'net.bytebuddy:byte-buddy'
implementation 'com.palantir.gradle.utils:environment-variables'

annotationProcessor 'org.immutables:value'
compileOnly 'org.immutables:value::annotations'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.palantir.gradle.conjure.api.ConjureExtension;
import com.palantir.gradle.conjure.api.ConjureProductDependenciesExtension;
import com.palantir.gradle.conjure.api.GeneratorOptions;
import com.palantir.gradle.utils.environmentvariables.EnvironmentVariables;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -119,7 +120,9 @@ public void apply(Project project) {
task.setDescription("Generates code for your API definitions in src/main/conjure/**/*.yml");
task.setGroup(TASK_GROUP);
});

applyDependencyForIdeTasks(project, compileConjure);
buildDependsOn(project, compileConjure);

setupConjureJavaProjects(
project, immutableOptionsSupplier(conjureExtension::getJava), compileConjure, compileIrTask);
Expand Down Expand Up @@ -388,6 +391,9 @@ private static void setupConjureTypescriptProject(
task.dependsOn(installTypeScriptDependencies);
task.getOutputs().dir(srcDirectory);
});

buildDependsOn(project, compileTypeScript);

TaskProvider<Exec> publishTypeScript = project.getTasks()
.register("publishTypeScript", Exec.class, task -> {
task.setDescription("Runs `npm publish` to publish a TypeScript package "
Expand Down Expand Up @@ -694,4 +700,17 @@ private static Project findDerivedProject(Project project, String projectName) {
return project.getRootProject().findProject(projectName);
}
}

private static void buildDependsOn(Project project, TaskProvider<?> task) {
EnvironmentVariables environmentVariables = project.getObjects().newInstance(EnvironmentVariables.class);

if (!environmentVariables.isCircleNode0OrLocal().get()) {
return;
}

project.getPluginManager().apply(LifecycleBasePlugin.class);
project.getTasks().named(LifecycleBasePlugin.BUILD_TASK_NAME).configure(build -> {
build.dependsOn(task);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ class ConjurePluginTest extends IntegrationSpec {
object: StringExample
returns: StringExample
'''.stripIndent()
file("gradle.properties") << "org.gradle.daemon=false"
file("gradle.properties") << '''
org.gradle.daemon=false
__TESTING=true
'''.stripIndent(true)
}

def 'compileConjure generates code and ir: #location'() {
Expand Down Expand Up @@ -709,6 +712,33 @@ class ConjurePluginTest extends IntegrationSpec {
sourcesFolderUrls.contains('file://$MODULE_DIR$/src/generated/java')
}

def 'compileTypeScript is run on build for circle node 0'() {
when:
def stdout = runTasksSuccessfully('build', '--dry-run',
'-P__TESTING_CIRCLE_NODE_INDEX=0').standardOutput

then:
stdout.contains ':api:compileTypeScript SKIPPED'
}

def 'compileTypeScript is not run on build for circle node 1'() {
when:
def stdout = runTasksSuccessfully('build', '--dry-run',
'-P__TESTING_CIRCLE_NODE_INDEX=1').standardOutput

then:
!stdout.contains(':api:compileTypeScript SKIPPED')
}

def 'compileTypeScript is run on build locally'() {
when:
// No CIRCLE_NODE_INDEX property set means local build
def stdout = runTasksSuccessfully('build', '--dry-run').standardOutput

then:
stdout.contains ':api:compileTypeScript SKIPPED'
}

@RestoreSystemProperties
def 'works with checkUnusedDependencies'() {
System.setProperty("ignoreMutableProjectStateWarnings", "true")
Expand Down
1 change: 1 addition & 0 deletions versions.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (1 c
com.google.j2objc:j2objc-annotations:2.8 (1 constraints: be09f5a0)
com.palantir.conjure.java.runtime:conjure-java-jackson-optimizations:8.4.0 (1 constraints: 521c3c88)
com.palantir.conjure.java.runtime:conjure-java-jackson-serialization:8.4.0 (1 constraints: 0e051f36)
com.palantir.gradle.utils:environment-variables:0.7.0 (1 constraints: 09050036)
com.palantir.safe-logging:logger:3.6.0 (2 constraints: 0c2d526d)
com.palantir.safe-logging:logger-slf4j:3.6.0 (1 constraints: 040e6542)
com.palantir.safe-logging:logger-spi:3.6.0 (2 constraints: 171e6d7b)
Expand Down
1 change: 1 addition & 0 deletions versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ com.fasterxml.jackson.core:jackson-databind = 2.15.3
com.google.errorprone:error_prone_annotations = 2.11.0
com.google.guava:guava = 33.0.0-jre
com.netflix.nebula:nebula-test = 10.0.0
com.palantir.gradle.utils:environment-variables = 0.7.0
com.palantir.sls.versions:sls-versions = 1.5.0
com.squareup.okhttp3:mockwebserver = 4.12.0
commons-io:commons-io = 2.15.1
Expand Down

0 comments on commit 988da10

Please sign in to comment.