Skip to content

Commit 81b0f56

Browse files
Setting up CI/CD
1 parent ad8032f commit 81b0f56

File tree

3 files changed

+39
-40
lines changed

3 files changed

+39
-40
lines changed

.github/workflows/publish.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Publish to JitPack
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v2
15+
16+
- name: Set up JDK 17
17+
uses: actions/setup-java@v2
18+
with:
19+
distribution: 'temurin'
20+
java-version: '17'
21+
22+
- name: Grant execute permission for gradlew
23+
run: chmod +x gradlew
24+
25+
- name: Build and Publish
26+
run: ./gradlew createGitHubRelease
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.PUBLISH_TOKEN }}

fake-server-lib/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = "com.github.rebecaalbuquerque"
8-
version = "1.0.0"
8+
version = "1.0.1"
99

1010
apply(from = rootProject.file("publish.gradle.kts"))
1111

@@ -49,7 +49,6 @@ afterEvaluate {
4949
create<MavenPublication>("release") {
5050
from(components["release"])
5151
artifactId = project.name
52-
5352
artifact("${layout.buildDirectory}/outputs/aar/${project.name}-release.aar")
5453

5554
pom {

publish.gradle.kts

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,30 @@
11
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-
}
252

263
tasks.register("createGitHubRelease") {
274
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")
307

318
if (githubToken.isNullOrBlank()) {
32-
throw GradleException("GITHUB_TOKEN environment variable is not set")
9+
throw GradleException("PUBLISH_TOKEN environment variable is not set")
3310
}
3411

35-
val description = project.findProperty("releaseDescription") as String?
36-
?: throw GradleException("Please provide a release description as a project property using -PreleaseDescription=\"description\"")
37-
3812
val json = """
3913
{
40-
"tag_name": "$tagName",
14+
"tag_name": "v$version",
4115
"target_commitish": "master",
42-
"name": "$tagName",
43-
"body": "${URLEncoder.encode(description, "UTF-8")}",
16+
"name": "v$version",
17+
"body": "Version $version",
4418
"draft": false,
4519
"prerelease": false
4620
}
4721
""".trimIndent()
4822

4923
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+
)
5228
}
5329
}
5430
}
55-
56-
tasks.register("publishFakeServerVersion") {
57-
dependsOn("gitTag", "createGitHubRelease")
58-
}

0 commit comments

Comments
 (0)