Skip to content

Commit

Permalink
Remove publishing from feature branches (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvoboda authored Apr 22, 2021
1 parent fda3960 commit 8f3cfae
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@

package com.palantir.gradle.externalpublish;

import java.util.Collections;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import nebula.plugin.info.scm.ScmInfoPlugin;
import nebula.plugin.publishing.maven.MavenBasePublishPlugin;
Expand All @@ -36,14 +34,10 @@
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository;
import org.gradle.api.publish.tasks.GenerateModuleMetadata;
import org.gradle.language.base.plugins.LifecycleBasePlugin;
import org.gradle.plugins.signing.SigningExtension;
import org.gradle.plugins.signing.SigningPlugin;

final class ExternalPublishBasePlugin implements Plugin<Project> {
private static final Set<String> PUBLISHING_UPGRADE_EXCAVATOR_BRANCH_NAMES = Collections.unmodifiableSet(
Stream.of("roomba/external-publish-plugin-migration", "roomba/latest-oss-publishing")
.collect(Collectors.toSet()));

private final Set<String> sonatypePublicationNames = new HashSet<>();

Expand All @@ -55,7 +49,6 @@ public void apply(Project projectVal) {

applyPublishingPlugins();
linkWithRootProject();
alwaysRunPublishIfOnExcavatorUpgradeBranch();
disableOtherPublicationsFromPublishingToSonatype();
disableModuleMetadata();

Expand Down Expand Up @@ -91,8 +84,10 @@ private void linkWithRootProject() {
"The com.palantir.external-publish plugin must be applied to the root project "
+ "*before* this plugin is evaluated"));

project.getTasks().named("publish").configure(publish -> {
publish.dependsOn(rootPlugin.sonatypeFinishingTask());
rootPlugin.sonatypeFinishingTask().ifPresent(sonatypeFinishingTask -> {
project.getTasks().named("publish").configure(publish -> {
publish.dependsOn(sonatypeFinishingTask);
});
});
}

Expand All @@ -109,32 +104,6 @@ private void disableOtherPublicationsFromPublishingToSonatype() {
});
}

private void alwaysRunPublishIfOnExcavatorUpgradeBranch() {
boolean isPublishingExcavatorBranch = EnvironmentVariables.envVarOrFromTestingProperty(project, "CIRCLE_BRANCH")
.filter(PUBLISHING_UPGRADE_EXCAVATOR_BRANCH_NAMES::contains)
.isPresent();

// If we're upgrading publishing logic via excavator using a known excavator PR, ensure we test the publish
// even if the publish command is not called. However, don't force every single PR to do the publish that
// takes ages.
if (isPublishingExcavatorBranch) {
project.afterEvaluate(_ignored -> {
project.getPluginManager().apply(LifecycleBasePlugin.class);

// Use the check task as many OSS don't use circle-templates so can't depend on say publishToMavenLocal
// being run.
project.getTasks().named(LifecycleBasePlugin.CHECK_TASK_NAME, checkTask -> {
// We use publishToSonatype rather than each individual publish task we know about to exercise the
// sonatype publishes of other maven publications (like gradle plugin descriptors) that cause
// errors.
checkTask.dependsOn(
project.getTasks().named("publishToSonatype"),
project.getRootProject().getTasks().named("closeSonatypeStagingRepository"));
});
});
}
}

private void disableModuleMetadata() {
// Turning off module metadata so that all consumers just use regular POMs
project.getTasks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.github.gradlenexus.publishplugin.NexusPublishExtension;
import io.github.gradlenexus.publishplugin.NexusPublishPlugin;
import java.time.Duration;
import java.util.Optional;
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
Expand Down Expand Up @@ -61,11 +62,13 @@ public final void apply(Project rootProjectVal) {
.configure(CircleCiContextDeadlineAvoidance::avoidHittingCircleCiContextDeadlineByPrintingEverySoOften);
}

public final TaskProvider<?> sonatypeFinishingTask() {
public final Optional<TaskProvider<?>> sonatypeFinishingTask() {
boolean isTagBuild = EnvironmentVariables.isTagBuild(rootProject);

return rootProject
.getTasks()
.named(isTagBuild ? "closeAndReleaseSonatypeStagingRepository" : "closeSonatypeStagingRepository");
if (!isTagBuild) {
return Optional.empty();
}

return Optional.of(rootProject.getTasks().named("closeAndReleaseSonatypeStagingRepository"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,13 @@ class ExternalPublishRootPluginIntegrationSpec extends IntegrationSpec {
}

@Unroll
def 'publish task for #type depends on publishing to sonatype'() {
def 'publish task for #type depends on publishing to sonatype on tag builds'() {
setup:
publishProject(type)

when:
def stdout = runSuccessfullyWithSigning('--dry-run', ":${type}:publish").standardOutput
def stdout = runSuccessfullyWithSigning(
'--dry-run', "-P__TESTING_CIRCLE_TAG=tag", ":${type}:publish").standardOutput

then:
stdout.find ":${type}:publish.*PublicationToSonatypeRepository SKIPPED"
Expand Down Expand Up @@ -407,15 +408,18 @@ class ExternalPublishRootPluginIntegrationSpec extends IntegrationSpec {
errorMessage.contains 'dirty'
}

def 'does close but not release staging sonatype repo if not on a tag build'() {
def 'does not close or release staging sonatype repo if not on a tag build'() {
// See https://issues.sonatype.org/browse/OSSRH-65523?focusedCommentId=1046249#comment-1046249 for why we can't
// exercise the publishing codepath on develop - basically it overwhelms Sonatype and harms other users (note
// there is no per user rate limiting, so it's possible for us to harm everyone else).
setup:
allPublishProjects()

when:
def stdout = runSuccessfullyWithSigning('publish', '--dry-run').standardOutput

then:
stdout.contains(':closeSonatypeStagingRepository')
!stdout.contains(':closeSonatypeStagingRepository')
!stdout.contains(':releaseSonatypeStagingRepository')
}

Expand All @@ -431,25 +435,6 @@ class ExternalPublishRootPluginIntegrationSpec extends IntegrationSpec {
stdout.contains(':releaseSonatypeStagingRepository')
}

def 'runs publish tasks as a dependency of check on upgrade excavator'() {
setup:
allPublishProjects()

when:
def stdout = runSuccessfullyWithSigning(
'--dry-run', '-P__TESTING_CIRCLE_BRANCH=roomba/external-publish-plugin-migration', 'check')
.standardOutput

println stdout

then:
stdout.contains(':initializeSonatypeStagingRepository SKIPPED')
stdout.contains(':jar:publishMavenPublicationToSonatypeRepository SKIPPED')
stdout.contains(':dist:publishDistPublicationToSonatypeRepository SKIPPED')
stdout.contains(':closeSonatypeStagingRepository SKIPPED')
!stdout.contains(':releaseSonatypeStagingRepository SKIPPED')
}

def 'does not run publish tasks as a dependency of check on normal run'() {
setup:
allPublishProjects()
Expand Down

0 comments on commit 8f3cfae

Please sign in to comment.