|
1 | 1 | import java.io.ByteArrayOutputStream
|
2 |
| -import java.net.URLEncoder |
3 |
| - |
4 |
| -tasks.register("gitTag") { |
5 |
| - doLast { |
6 |
| - val tagName = project.version.toString() |
7 |
| - val result = ByteArrayOutputStream() |
8 |
| - exec { |
9 |
| - commandLine("git", "tag", "--list", tagName) |
10 |
| - standardOutput = result |
11 |
| - } |
12 |
| - val tagExists = result.toString().trim().isNotEmpty() |
13 |
| - if (tagExists) { |
14 |
| - throw GradleException("This version already exists, update the library version and try publishing again.") |
15 |
| - } else { |
16 |
| - exec { |
17 |
| - commandLine("git", "tag", "-a", tagName, "-m", tagName) |
18 |
| - } |
19 |
| - exec { |
20 |
| - commandLine("git", "push", "origin", tagName) |
21 |
| - } |
22 |
| - } |
23 |
| - } |
24 |
| -} |
25 | 2 |
|
26 | 3 | tasks.register("createGitHubRelease") {
|
27 | 4 | doLast {
|
28 |
| - val tagName = "v${project.version}" |
29 |
| - val githubToken = System.getenv("GITHUB_TOKEN") |
| 5 | + val version = project.version.toString() |
| 6 | + val githubToken = System.getenv("PUBLISH_TOKEN") |
30 | 7 |
|
31 | 8 | if (githubToken.isNullOrBlank()) {
|
32 |
| - throw GradleException("GITHUB_TOKEN environment variable is not set") |
| 9 | + throw GradleException("PUBLISH_TOKEN environment variable is not set") |
33 | 10 | }
|
34 | 11 |
|
35 |
| - val description = project.findProperty("releaseDescription") as String? |
36 |
| - ?: throw GradleException("Please provide a release description as a project property using -PreleaseDescription=\"description\"") |
37 |
| - |
38 | 12 | val json = """
|
39 | 13 | {
|
40 |
| - "tag_name": "$tagName", |
| 14 | + "tag_name": "v$version", |
41 | 15 | "target_commitish": "master",
|
42 |
| - "name": "$tagName", |
43 |
| - "body": "${URLEncoder.encode(description, "UTF-8")}", |
| 16 | + "name": "v$version", |
| 17 | + "body": "Version $version", |
44 | 18 | "draft": false,
|
45 | 19 | "prerelease": false
|
46 | 20 | }
|
47 | 21 | """.trimIndent()
|
48 | 22 |
|
49 | 23 | exec {
|
50 |
| - commandLine("curl", "-X", "POST", "-H", "Authorization: token $githubToken", "-d", json, |
51 |
| - "https://api.github.com/repos/rebecaalbuquerque/android-fake-server/releases") |
| 24 | + commandLine( |
| 25 | + "curl", "-X", "POST", "-H", "Authorization: token $githubToken", "-d", json, |
| 26 | + "https://api.github.com/repos/rebecaalbuquerque/android-fake-server/releases" |
| 27 | + ) |
52 | 28 | }
|
53 | 29 | }
|
54 | 30 | }
|
55 |
| - |
56 |
| -tasks.register("publishFakeServerVersion") { |
57 |
| - dependsOn("gitTag", "createGitHubRelease") |
58 |
| -} |
0 commit comments