Skip to content

Add deep transitive projects to release #5331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,34 @@ abstract class PublishingPlugin : Plugin<Project> {

if (projectsToPublish == null) return null

val projectNames = projectsToPublish.split(",")
val publishingProjects =
allFirebaseLibraries.filter { it.artifactId.get() in projectsToPublish.split(",") }

val librariesToRelease = getDeepTransitiveReleases(publishingProjects, libraryGroups)

return ReleaseMetadata(librariesToRelease, releaseName)
}

/**
* Finds all transitive libraries that need to be released so that the input list of project names
* can be released. This includes all project level dependencies, and anything in the same library
* group.
*/
private tailrec fun getDeepTransitiveReleases(
inputProjects: List<FirebaseLibraryExtension>,
libraryGroups: Map<String, List<FirebaseLibraryExtension>>
): List<FirebaseLibraryExtension> {
val libraryGroupsToRelease =
allFirebaseLibraries
.filter { it.artifactId.get() in projectNames }
inputProjects
.flatMap { it.resolveProjectLevelDependencies() + it }
.map { it.libraryGroupName }
val librariesToRelease =
val projectsToRelease =
libraryGroups
.filterKeys { it in libraryGroupsToRelease }
.flatMap { it.value }
.distinctBy { it.artifactId.get() }
return ReleaseMetadata(librariesToRelease, releaseName)
return if (inputProjects == projectsToRelease) inputProjects
else getDeepTransitiveReleases(projectsToRelease, libraryGroups)
}

private fun releaseMetadataFromReleaseConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,27 @@ class PublishingPluginTests {
Project(name = "childProject2", version = "0.9", projectDependencies = setOf(project1))

withProjects(project1, project2)
publishAndFail(project2)
publish(project2)

project1.pomOrNull().shouldNotBeNull()
project2.pom.dependencies shouldHaveSingleElement project1.toArtifact()
}
}

@Test
fun `Publish with very transitive dependency`() {
with(controller) {
val project1 = Project(name = "childProject1", version = "1.0", libraryGroup = "libraryGroup")
val project2 =
Project(name = "childProject2", version = "0.9", projectDependencies = setOf(project1))
val project3 = Project(name = "childProject3", version = "1.0", libraryGroup = "libraryGroup")

withProjects(project1, project2, project3)
publish(project2)

project1.pomOrNull().shouldNotBeNull()
project3.pomOrNull().shouldNotBeNull()
project2.pom.dependencies shouldHaveSingleElement project1.toArtifact()
}
}

Expand Down