-
Notifications
You must be signed in to change notification settings - Fork 8
Add publishAggregationToCentralSnapshots and publishFooPublicationToCentralSnapshots
#63
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package nmcp.internal.task | ||
|
|
||
| import java.time.Duration | ||
| import okhttp3.OkHttpClient | ||
|
|
||
| internal val client = OkHttpClient.Builder() | ||
| .connectTimeout(Duration.ofSeconds(30)) | ||
| .writeTimeout(Duration.ofSeconds(30)) | ||
| .readTimeout(Duration.ofSeconds(60)) | ||
| .build() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package nmcp.internal.task | ||
|
|
||
| import gratatouille.GInputFile | ||
| import gratatouille.GLogger | ||
| import gratatouille.GTask | ||
| import java.util.zip.ZipInputStream | ||
| import okhttp3.Credentials | ||
| import okhttp3.MediaType.Companion.toMediaType | ||
| import okhttp3.Request | ||
| import okhttp3.RequestBody.Companion.toRequestBody | ||
| import okio.buffer | ||
| import okio.source | ||
|
|
||
| @GTask(pure = false) | ||
| fun publishSnapshot( | ||
| logger: GLogger, | ||
| username: String?, | ||
| password: String?, | ||
| version: String, | ||
| inputFile: GInputFile, | ||
| ) { | ||
| check(!username.isNullOrBlank()) { | ||
| "Ncmp: username is missing" | ||
| } | ||
| check(!password.isNullOrBlank()) { | ||
| "Ncmp: password is missing" | ||
| } | ||
| check(version.endsWith("-SNAPSHOT")) { | ||
| "Ncmp: Cannot publish snapshot version '$version' without -SNAPSHOT suffix" | ||
| } | ||
|
|
||
| val okHttpClient = client.newBuilder() | ||
| .addInterceptor { chain -> | ||
| val builder = chain.request().newBuilder() | ||
| builder.addHeader("Authorization", Credentials.basic(username, password)) | ||
| builder.addHeader("Accept", "application/json") | ||
| builder.addHeader("Content-Type", "application/json") | ||
| builder.addHeader("User-Agent", "vespene") | ||
| chain.proceed(builder.build()) | ||
| }.build() | ||
|
|
||
| ZipInputStream(inputFile.inputStream()).use { | ||
| while (true) { | ||
| val entry = it.nextEntry ?: break | ||
| if (entry.isDirectory) continue | ||
| val relativePath = entry.name | ||
| logger.lifecycle("Nmcp: uploading $relativePath...") | ||
|
|
||
| val url = "https://central.sonatype.com/repository/maven-snapshots/$relativePath" | ||
| val request = Request.Builder() | ||
| .put(it.source().buffer().readByteArray().toRequestBody("application/octet-stream".toMediaType())) | ||
| .url(url) | ||
| .build() | ||
|
|
||
| val uploadResponse = okHttpClient.newCall(request).execute() | ||
| check(uploadResponse.isSuccessful) { | ||
| "Cannot put $url:\n${uploadResponse.body?.string()}" | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a single task that decides on
snapshot/releasedepending on the project version?E.g. if
project.version.toString()ends with-SNAPSHOT, then it should publish to snaphots. Otherwise it should publish to releases.WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea maybe that'd be better.
But I also kind of like the separation of intents. Having separate task names and separate CI workflows makes for a clear separation. Plus historically those were 2 different task names so there is some brain muscle attached. Not saying we shouldn't change it of course but I'm not 100% convinced it would help yet. Did you have any specific use cases in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reasoning I have in mind is that the action the same: "push publication to the repository".
I don't understand why should I push it differently depending on the project version.
It is pretty much like you don't have
jarvsjarSnapshotdepending on the project version. You always have a singlejartask which builds the jar according to the current project version.I'm fine if there are two independent technical task for the implementation details, however, in that case it would be nice to have an out of the box wrapper task which would depend on one of them as the project version requires.
Historically, I use "autosnapshot" project version: build script automatically adds
-SNAPSHOTto the version unless there's-Preleaseflag.So it sounds reasonable to have
./gradlew publishAllPublicationsToCentralPortaland./gradlew -Prelease publishAllPublicationsToCentralPortal. In other words:-Preleaseselects the project version while the rest ("publish to central portal") being intact.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not the same repository though. The url to consume and the immutability guarantees are not the same.
I get where you're coming from with the
-Preleaseflag, though. That's interesting and it's currently a pain in my workflows to make a commit specifically to drop the-SNAPSHOT... Having something like this would definitely make it easier.Give me a few weeks so that I can try it out in a pet project and I'll report back? I'll open an issue so we keep track of this. (edit: here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vlsi do you have a sample project using
-PreleaseI could take inspiration from?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/Netcracker/qubership-profiler-agent/blob/3f295af88e417338dce15fbf85b5138f047b5a03/build.gradle.kts#L17-L19 and https://github.com/Netcracker/qubership-profiler-agent/blob/3f295af88e417338dce15fbf85b5138f047b5a03/build-logic/build-parameters/build.gradle.kts#L11-L14
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vlsi I ended up adopting the "autosnapshot" versioning in a couple of projects, it's nice! Thanks for pointing me to this 🙏
That being, said, I'm not 100% convinced that we need a wrapper task just yet. My snapshot and release workflows are usually different and having different task names doesn't hurt me too much. If anything, they act as an additional explicit check that I'm publishing in the correct location.
I might get there ultimately but since it's always easier to add than remove, I prefer keeping our options open there and not committing in that direction.