@@ -2,53 +2,8 @@ package com.powersync.plugins.sonatype
22
33import org.gradle.api.Project
44import org.gradle.api.publish.PublishingExtension
5- import java.net.URI
65
76internal inline val Project .gradlePublishing: PublishingExtension
87 get() = extensions.getByType(PublishingExtension ::class .java)
98
109internal fun Project.findOptionalProperty (propertyName : String ) = findProperty(propertyName)?.toString()
11-
12-
13- /* * Sets up repository for publishing to Github Packages to GITHUB_REPO property
14- * username and password (a personal Github access token) should be specified as
15- * `GITHUB_PUBLISH_USER` and `GITHUB_PUBLISH_TOKEN` gradle properties
16- */
17- @Suppress(" unused" )
18- public fun Project.setupGithubRepository () {
19- gradlePublishing.apply {
20- val githubRepo = githubRepoOrNull ? : return
21-
22- val githubPublishToken =
23- githubPublishTokenOrNull ? : return
24- val githubPublishUser = project.githubPublishUser ? : " cirunner"
25-
26- repositories.maven {
27- it.name = " githubPackages"
28- it.url = URI .create(" https://maven.pkg.github.com/$githubRepo " )
29- it.credentials { cred ->
30- cred.username = githubPublishUser
31- cred.password = githubPublishToken
32- }
33- }
34- }
35- }
36-
37- internal val Project .githubPublishUser: String?
38- get() = project.findOptionalProperty(" GITHUB_PUBLISH_USER" )
39-
40- internal val Project .githubPublishTokenOrNull: String?
41- get() = project.findOptionalProperty(" GITHUB_PUBLISH_TOKEN" )
42-
43- internal val Project .githubRepoOrNull: String?
44- get() {
45- val repo = findOptionalProperty(" GITHUB_REPO" ) ? : return null
46- val repoWithoutGitSuffix = repo.removeSuffix(" .git" )
47- val regex = Regex (" ((.*)[/:])?(?<owner>[^:/]+)/(?<repo>[^/]+)" )
48- val matchResult = regex.matchEntire(repoWithoutGitSuffix)
49- if (matchResult != null ) {
50- return (matchResult.groups[" owner" ]!! .value + " /" + matchResult.groups[" repo" ]!! .value)
51- } else {
52- throw IllegalArgumentException (" Incorrect Github repository path, should be \" Owner/Repo\" " )
53- }
54- }
0 commit comments