Skip to content
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

feat: maven kotlin multiplatform support #412

Merged
merged 19 commits into from
Mar 13, 2023
Merged

Conversation

buenaflor
Copy link
Contributor

@buenaflor buenaflor commented Sep 1, 2022

This introduces some additions to be able to support a Kotlin Multiplatform publish.

Additional artifacts include: *.klib, *-all.jar, *-metadata.jar, *.module.

Example artifacts of Kermit:

For context: for a KMP publish all platforms need to be published and the root artifact contains metadata, see: getsentry/sentry-kotlin-multiplatform#37 (comment)

The generated gpg command example:
root artifact:

"-Dfile=/var/folders/j2/r3dsjfkx4pj5n0v8jjlb6lv80000gn/T/craft-mSNdRu/sentry-kotlin-multiplatform-0.0.1/sentry-kotlin-multiplatform-0.0.1.jar" 
"-Dfiles=/var/folders/j2/r3dsjfkx4pj5n0v8jjlb6lv80000gn/T/craft-mSNdRu/sentry-kotlin-multiplatform-0.0.1/sentry-kotlin-multiplatform-0.0.1-javadoc.jar,/var/folders/j2/r3dsjfkx4pj5n0v8jjlb6lv80000gn/T/craft-mSNdRu/sentry-kotlin-multiplatform-0.0.1/sentry-kotlin-multiplatform-0.0.1-sources.jar,/var/folders/j2/r3dsjfkx4pj5n0v8jjlb6lv80000gn/T/craft-mSNdRu/sentry-kotlin-multiplatform-0.0.1/sentry-kotlin-multiplatform-0.0.1-all.jar,/var/folders/j2/r3dsjfkx4pj5n0v8jjlb6lv80000gn/T/craft-mSNdRu/sentry-kotlin-multiplatform-0.0.1/sentry-kotlin-multiplatform-0.0.1.module" 
"-Dclassifiers=javadoc,sources,all,module" 
"-Dtypes=jar,jar,jar,module" 
...

ios artifact:

"-Dfile=/var/folders/j2/r3dsjfkx4pj5n0v8jjlb6lv80000gn/T/craft-QEa8yL/sentry-kotlin-multiplatform-iosArm64-0.0.1/sentry-kotlin-multiplatform-iosArm64-0.0.1.klib" 
"-Dfiles=/var/folders/j2/r3dsjfkx4pj5n0v8jjlb6lv80000gn/T/craft-QEa8yL/sentry-kotlin-multiplatform-iosArm64-0.0.1/sentry-kotlin-multiplatform-iosArm64-0.0.1-javadoc.jar,/var/folders/j2/r3dsjfkx4pj5n0v8jjlb6lv80000gn/T/craft-QEa8yL/sentry-kotlin-multiplatform-iosArm64-0.0.1/sentry-kotlin-multiplatform-iosArm64-0.0.1-sources.jar/var/folders/j2/r3dsjfkx4pj5n0v8jjlb6lv80000gn/T/craft-QEa8yL/sentry-kotlin-multiplatform-iosArm64-0.0.1/sentry-kotlin-multiplatform-iosarm64-0.0.1-cinterop-Sentry.NSException.klib,/var/folders/j2/r3dsjfkx4pj5n0v8jjlb6lv80000gn/T/craft-QEa8yL/sentry-kotlin-multiplatform-iosArm64-0.0.1/sentry-kotlin-multiplatform-iosarm64-0.0.1-cinterop-Sentry.Scope.klib,/var/folders/j2/r3dsjfkx4pj5n0v8jjlb6lv80000gn/T/craft-QEa8yL/sentry-kotlin-multiplatform-iosArm64-0.0.1/sentry-kotlin-multiplatform-iosarm64-0.0.1-cinterop-Sentry.klib,/var/folders/j2/r3dsjfkx4pj5n0v8jjlb6lv80000gn/T/craft-QEa8yL/sentry-kotlin-multiplatform-iosArm64-0.0.1/sentry-kotlin-multiplatform-iosArm64-0.0.1-metadata.jar,/var/folders/j2/r3dsjfkx4pj5n0v8jjlb6lv80000gn/T/craft-QEa8yL/sentry-kotlin-multiplatform-iosArm64-0.0.1/sentry-kotlin-multiplatform-iosArm64-0.0.1.module" 
"-Dclassifiers=javadoc,sources,cinterop,cinterop,cinterop,metadata,module"
"-Dtypes=jar,jar,klib,klib,klib,jar,module"
...

Copy link
Contributor

@iker-barriocanal iker-barriocanal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The craft codebase uses semicolons, can we follow the same style?

Comment on lines 452 to 454
if (existsSync(join(distDir, `${moduleName.toLowerCase()}.klib`))) {
return `${moduleName}.klib`;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the file isn't accessible (e.g. it doesn't exist), the .jar filename will be returned. I don't know if the .jar file exists for kotlin, or what the consequences are of uploading it instead of the .klib. If a required file for a release doesn't exist, we should fail the release.

Another thing to consider is how easy it'd be to debug a failing release. A message like "hey, I can't find xxx file" is more helpful than "hey, I'm uploading the files and can't read yyy file, which isn't related to the release at all".

An alternative approach is to update the target's config to keep track of what we are releasing (android? kotlin?). If we know that, we could return directly the .klib filename, and let the upload fail if it can't read the file (which automatically produces a more helpful failure message). This is what currently happens with the .jar file (no disk operations happen in this method).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kotlin Multiplatform needs to upload multiple artifacts, you upload either a .jar or a.klib or .aar in case of Android. so if it's not an android artifact then if .klib is not there then it must be a .jar. So it shouldn't fail if it doesn't find a .klib.

Since only Apple targets (ios, macos, etc...) are packaged as .klib, I can add a target config like you said to keep track of those so I don't have to search for it's existence. However, I would still need to search for the existence of *.metadata and *-all.jar in getFilesForMavenPomDist as they have to be added and they don't exist for every artifact (only the root artifact needs all.jar and only apple artifacts have metadata.jar).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess what I can do is create a target config for kotlin-multiplatform or something like that to keep the uploadPomDistribution separated and only add those files if it's a kotlin-multiplatform artifact. that way it doesn't interfere with the way it has been before I added the changes

src/targets/maven.ts Outdated Show resolved Hide resolved
src/targets/maven.ts Outdated Show resolved Hide resolved
src/targets/maven.ts Outdated Show resolved Hide resolved
src/targets/maven.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@iker-barriocanal iker-barriocanal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better!

Also -- don't forget to add documentation for this new config in the README.

src/targets/maven.ts Outdated Show resolved Hide resolved
src/targets/maven.ts Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@buenaflor buenaflor marked this pull request as ready for review September 6, 2022 09:27
@marandaneto
Copy link
Contributor

marandaneto commented Sep 8, 2022

@buenaflor did you try to call gpg:sign-and-deploy-file manually with all those params and check the temporary ~/.m2/repository/io/sentry folder if it's correct?
It's also worth checking if the new files are also signed, because all the files need to be, you can see that each file has a .asc, .sha, .md5 extension, so the klib, module etc all need to be signed as well but I believe the command does it automatically, I'd double-check tho.

Copy link
Contributor

@iker-barriocanal iker-barriocanal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests currently only cover config loading. Put simply, what this PR introduces is spawning a process with a list of arguments executed under a certain condition (when we make a kotlin multiplatform release, run gpg blahblahblah). Can we verify that the process is spawned, when it should and with the expected arguments?

@romtsn
Copy link
Member

romtsn commented Sep 26, 2022

@iker-barriocanal what do you think is still missing for this PR? just tests from your latest comment or some other comments need to be addressed?

@iker-barriocanal
Copy link
Contributor

@romtsn I think only tests are missing (verifying the temporary folder as Manoel suggests may be one of them). That said, I'm not blocking the PR. I don't know if @asottile-sentry has other thoughts too.

@marandaneto marandaneto marked this pull request as draft September 27, 2022 09:08
@marandaneto
Copy link
Contributor

Making it a draft since it's not fully tested yet.

@buenaflor
Copy link
Contributor Author

buenaflor commented Mar 8, 2023

I added a fix so that the published artifacts are correct and signed. I generated the artifacts manually & locally by calling the gpg publish commands as they were produced by craft during dry runs (I only had to change the output url and the path to the distribution folder). Then tested it on sample kmp apps with multiple platforms (android, cocoa, jvm desktop) by adding it as a dependency throughmavenLocal.

Example output of a specific file:

sentry-kotlin-multiplatform-iossimulatorarm64-0.0.1-cinterop-Sentry.PrivateSentrySDKOnly.klib
sentry-kotlin-multiplatform-iossimulatorarm64-0.0.1-cinterop-Sentry.PrivateSentrySDKOnly.klib.asc
sentry-kotlin-multiplatform-iossimulatorarm64-0.0.1-cinterop-Sentry.PrivateSentrySDKOnly.klib.md5
sentry-kotlin-multiplatform-iossimulatorarm64-0.0.1-cinterop-Sentry.PrivateSentrySDKOnly.klib.sha1

I attached a file with all the generated gpg publish commands for doing it locally for the latest KMP build: kmp local publish via gpg sign deploy.txt

@buenaflor buenaflor marked this pull request as ready for review March 8, 2023 16:39
@buenaflor buenaflor self-assigned this Mar 8, 2023
README.md Outdated Show resolved Hide resolved
@marandaneto
Copy link
Contributor

LGTM from my side but I'd let the owners of this repo approve it.

Copy link
Member

@asottile-sentry asottile-sentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@buenaflor buenaflor merged commit 8f84181 into master Mar 13, 2023
@buenaflor buenaflor deleted the feat/maven-klib-support branch March 13, 2023 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants