Skip to content

Commit 7d6b0a4

Browse files
Merge pull request #32 from ovitrif/master
feat: github packages android distribution
2 parents aa55eb8 + cb1272e commit 7d6b0a4

File tree

9 files changed

+143
-30
lines changed

9 files changed

+143
-30
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
2+
# For more info see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle
3+
4+
name: Gradle Package
5+
6+
on:
7+
release:
8+
types: [created]
9+
10+
jobs:
11+
publish:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
packages: write
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Set up JDK 17
20+
uses: actions/setup-java@v4
21+
with:
22+
java-version: '17'
23+
distribution: 'temurin'
24+
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
25+
settings-path: ${{ github.workspace }} # location for the settings.xml file
26+
27+
- name: Setup Gradle
28+
uses: gradle/actions/setup-gradle@v4
29+
30+
- name: Extract version from tag
31+
id: version
32+
run: echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
33+
34+
- name: Build with Gradle
35+
working-directory: bindings/android
36+
run: ./gradlew build -Pversion=${{ steps.version.outputs.version }}
37+
38+
# same credentials env vars used in the publishing section of build.gradle.kts
39+
- name: Publish to GitHub Packages
40+
working-directory: bindings/android
41+
env:
42+
GITHUB_ACTOR: ${{ github.actor }}
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
GITHUB_REPO: ${{ github.repository }}
45+
run: ./gradlew publish -Pversion=${{ steps.version.outputs.version }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
target/
22
.idea/
3+
.DS_Store

bindings/android/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
.gradle
2-
.idea
3-
.DS_Store
42
build
53
local.properties

bindings/android/README.md

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,88 @@ Android library for Bitkit Core bindings.
44

55
## Installation
66

7-
### Via JitPack (Recommended)
7+
### GitHub Packages
88

9-
See [Jitpack.io](https://jitpack.io/).
9+
#### 1. Setup your GitHub credentials
1010

11-
### Via Maven Local (Development)
11+
Create a GitHub PAT (Personal Access Token):
12+
- Go to GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)
13+
- Generate new token with scopes: `read:packages` (and `repo` if package/repo is private)
14+
- Copy the token once and use it in the next steps:
15+
16+
Set env vars:
17+
```sh
18+
export GITHUB_ACTOR="your_pat_with_read"
19+
export GITHUB_TOKEN="your_pat_with_read:packages"
20+
```
21+
22+
Or add to `~/.gradle/gradle.properties`:
23+
```properties
24+
# ~/.gradle/gradle.properties
25+
gpr.user=<your_github_username>
26+
gpr.key=<your_pat_with_read:packages>
27+
```
28+
29+
#### 2. Add the GitHub Packages repository
1230

1331
```kotlin
1432
// settings.gradle.kts
1533
dependencyResolutionManagement {
16-
repositories {
17-
mavenLocal()
18-
// ... other repositories
34+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
35+
repositories {
36+
google()
37+
mavenCentral()
38+
maven {
39+
url = uri("https://maven.pkg.github.com/synonymdev/bitkit-core")
40+
credentials {
41+
username = System.getenv("GITHUB_ACTOR") ?: providers.gradleProperty("gpr.user").orNull
42+
password = System.getenv("GITHUB_TOKEN") ?: providers.gradleProperty("gpr.key").orNull
43+
}
1944
}
45+
}
2046
}
47+
```
48+
49+
#### 3. Declare the dependency
2150

22-
// build.gradle.kts
51+
```kotlin
52+
// app/build.gradle.kts
2353
dependencies {
24-
implementation("com.synonym:bitkit-core-android:LATEST_VERSION")
54+
implementation("com.synonym:bitkit-core-android:<VERSION>")
55+
// example:
56+
// implementation("com.synonym:bitkit-core-android:0.1.0")
2557
}
2658
```
59+
### Maven Local (development)
60+
61+
```kotlin
62+
// settings.gradle.kts
63+
dependencyResolutionManagement {
64+
repositories {
65+
mavenLocal()
66+
// others
67+
}
68+
}
69+
70+
// build.gradle.kts
71+
dependencies {
72+
implementation("com.synonym:bitkit-core-android:<LOCAL_VERSION>")
73+
}
74+
```
75+
76+
---
77+
78+
## Publishing
79+
80+
**⚠️ Reminder:** Versions are immutable, bump for each publish.
81+
82+
### GitHub Actions
83+
84+
Create a GitHub Release with a new tag like `v0.1.0`. The workflow `gradle-publish.yml` will publish that version.
85+
86+
### Terminal
87+
88+
```sh
89+
cd bindings/android
90+
./gradlew publish -Pversion=0.1.0
91+
```

bindings/android/build.gradle.kts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,5 @@ buildscript {
88
}
99
}
1010

11-
// library version is defined in gradle.properties
12-
val libraryVersion: String by project
13-
14-
group = "com.synonym"
15-
version = libraryVersion
11+
group = providers.gradleProperty("group").orNull ?: "com.synonym"
12+
version = providers.gradleProperty("version").orNull ?: "0.0.0"

bindings/android/gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ org.gradle.jvmargs=-Xmx1536m
22
android.useAndroidX=true
33
android.enableJetifier=true
44
kotlin.code.style=official
5-
libraryVersion=0.1.9
5+
group=com.synonym
6+
version=0.1.9

bindings/android/lib/build.gradle.kts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// library version is defined in gradle.properties
2-
val libraryVersion: String by project
3-
41
plugins {
52
id("com.android.library")
63
id("org.jetbrains.kotlin.android") version "1.9.10"
@@ -68,16 +65,15 @@ afterEvaluate {
6865
publishing {
6966
publications {
7067
create<MavenPublication>("maven") {
71-
groupId = "com.synonym"
72-
artifactId = "bitkit-core-android"
73-
version = libraryVersion
68+
val mavenArtifactId = "bitkit-core-android"
69+
groupId = providers.gradleProperty("group").orNull ?: "com.synonym"
70+
artifactId = mavenArtifactId
71+
version = providers.gradleProperty("version").orNull ?: "0.0.0"
7472

7573
from(components["release"])
7674
pom {
77-
name.set("bitkit-core-android")
78-
description.set(
79-
"Bitkit Core Android bindings library."
80-
)
75+
name.set(mavenArtifactId)
76+
description.set("Bitkit Core Android bindings.")
8177
url.set("https://github.com/synonymdev/bitkit-core")
8278
licenses {
8379
license {
@@ -95,6 +91,19 @@ afterEvaluate {
9591
}
9692
}
9793
}
94+
repositories {
95+
maven {
96+
val repo = System.getenv("GITHUB_REPO")
97+
?: providers.gradleProperty("gpr.repo").orNull
98+
?: "synonymdev/bitkit-core"
99+
name = "GitHubPackages"
100+
url = uri("https://maven.pkg.github.com/$repo")
101+
credentials {
102+
username = System.getenv("GITHUB_ACTOR") ?: providers.gradleProperty("gpr.user").orNull
103+
password = System.getenv("GITHUB_TOKEN") ?: providers.gradleProperty("gpr.key").orNull
104+
}
105+
}
106+
}
98107
}
99108
}
100109

build_android.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fi
152152
# Sync version
153153
echo "Syncing version from Cargo.toml..."
154154
CARGO_VERSION=$(grep '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/' | head -1)
155-
sed -i.bak "s/^libraryVersion=.*/libraryVersion=$CARGO_VERSION/" "$ANDROID_LIB_DIR/gradle.properties"
155+
sed -i.bak "s/^version=.*/version=$CARGO_VERSION/" "$ANDROID_LIB_DIR/gradle.properties"
156156
rm -f "$ANDROID_LIB_DIR/gradle.properties.bak"
157157

158158
# Verify android library publish

jitpack.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)