Skip to content

Commit 04b2e99

Browse files
committed
build: publish the aar to the github packages maven registry
Adds maven-publish (dev.firechip:cobs_codec_kt) and a publish workflow.
1 parent ab5acb1 commit 04b2e99

3 files changed

Lines changed: 130 additions & 3 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Publish to GitHub Packages
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
packages: write
12+
13+
jobs:
14+
publish:
15+
name: Publish Maven package
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v7
19+
- uses: actions/setup-java@v5
20+
with:
21+
distribution: temurin
22+
java-version: "17"
23+
- uses: android-actions/setup-android@v4
24+
- name: Install SDK packages
25+
run: sdkmanager "platforms;android-35" "build-tools;36.0.0"
26+
- name: Test and publish to GitHub Packages
27+
env:
28+
GITHUB_ACTOR: ${{ github.actor }}
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
run: >-
31+
./gradlew :cobs:testDebugUnitTest
32+
:cobs:publishReleasePublicationToGitHubPackagesRepository
33+
--console=plain

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,40 @@ as a serial/UART, USB, or BLE link.
2626

2727
## Install
2828

29-
The `.aar` is attached to each
30-
[GitHub release](https://github.com/firechip/cobs_codec_kt/releases). Download
31-
`cobs_codec_kt-<version>.aar` into your app's `libs/` directory and add:
29+
### Gradle (GitHub Packages)
30+
31+
The library is published to the GitHub Packages Maven registry as
32+
`dev.firechip:cobs_codec_kt`. Add the repository and the dependency:
33+
34+
```kotlin
35+
repositories {
36+
maven {
37+
url = uri("https://maven.pkg.github.com/firechip/cobs_codec_kt")
38+
credentials {
39+
username = providers.gradleProperty("gpr.user").orNull
40+
?: System.getenv("GITHUB_ACTOR")
41+
password = providers.gradleProperty("gpr.key").orNull
42+
?: System.getenv("GITHUB_TOKEN")
43+
}
44+
}
45+
}
46+
47+
dependencies {
48+
implementation("dev.firechip:cobs_codec_kt:1.0.0")
49+
}
50+
```
51+
52+
> GitHub Packages requires authentication even for public packages. Use a GitHub
53+
> [personal access token](https://github.com/settings/tokens) with the
54+
> `read:packages` scope, set as `gpr.user` / `gpr.key` in
55+
> `~/.gradle/gradle.properties` (or the `GITHUB_ACTOR` / `GITHUB_TOKEN`
56+
> environment variables).
57+
58+
### Direct `.aar` download
59+
60+
Alternatively, the `.aar` is attached to every
61+
[GitHub release](https://github.com/firechip/cobs_codec_kt/releases) and needs no
62+
authentication:
3263

3364
```kotlin
3465
dependencies {

cobs/build.gradle.kts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
22

33
plugins {
44
id("com.android.library")
5+
id("maven-publish")
56
}
67

8+
group = "dev.firechip"
9+
version = "1.0.0"
10+
711
android {
812
namespace = "dev.firechip.cobs"
913
compileSdk = 35
@@ -28,6 +32,12 @@ android {
2832
it.useJUnit()
2933
}
3034
}
35+
36+
publishing {
37+
singleVariant("release") {
38+
withSourcesJar()
39+
}
40+
}
3141
}
3242

3343
kotlin {
@@ -39,3 +49,56 @@ kotlin {
3949
dependencies {
4050
testImplementation("junit:junit:4.13.2")
4151
}
52+
53+
publishing {
54+
publications {
55+
register<MavenPublication>("release") {
56+
afterEvaluate {
57+
from(components["release"])
58+
}
59+
groupId = "dev.firechip"
60+
artifactId = "cobs_codec_kt"
61+
version = project.version.toString()
62+
pom {
63+
name = "cobs_codec_kt"
64+
description =
65+
"Pure-Kotlin Consistent Overhead Byte Stuffing (COBS) and " +
66+
"COBS/R for Android."
67+
url = "https://github.com/firechip/cobs_codec_kt"
68+
licenses {
69+
license {
70+
name = "MIT"
71+
url =
72+
"https://github.com/firechip/cobs_codec_kt/blob/main/LICENSE"
73+
}
74+
}
75+
developers {
76+
developer {
77+
id = "ajsb85"
78+
name = "Alexander Salas Bastidas"
79+
email = "ajsb85@firechip.dev"
80+
}
81+
}
82+
scm {
83+
url = "https://github.com/firechip/cobs_codec_kt"
84+
connection =
85+
"scm:git:https://github.com/firechip/cobs_codec_kt.git"
86+
developerConnection =
87+
"scm:git:ssh://git@github.com/firechip/cobs_codec_kt.git"
88+
}
89+
}
90+
}
91+
}
92+
repositories {
93+
maven {
94+
name = "GitHubPackages"
95+
url = uri("https://maven.pkg.github.com/firechip/cobs_codec_kt")
96+
credentials {
97+
username = System.getenv("GITHUB_ACTOR")
98+
?: providers.gradleProperty("gpr.user").orNull
99+
password = System.getenv("GITHUB_TOKEN")
100+
?: providers.gradleProperty("gpr.key").orNull
101+
}
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)