Skip to content

Commit 2f777cd

Browse files
[PM-24248] Refining android sdk package publishing and versioning (#368)
## 🎟️ Tracking <!-- Paste the link to the Jira or GitHub issue or otherwise describe / point to where this change is coming from. --> [PM-24248](https://bitwarden.atlassian.net/browse/PM-24248) ## 📔 Objective <!-- Describe what the purpose of this PR is, for example what bug you're fixing or new feature you're adding. --> This PR changes the package name for main and feature branches as well as the name version for the package generated. On `build-android.yml` added manual run support. ## ⏰ Reminders before review - Contributor guidelines followed - All formatters and local linters executed and passed - Written new unit and / or integration tests where applicable - Protected functional changes with optionality (feature flags) - Used internationalization (i18n) for all UI strings - CI builds passed - Communicated to DevOps any deployment requirements - Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team ## 🦮 Reviewer guidelines <!-- Suggested interactions but feel free to use (or not) as you desire! --> - 👍 (`:+1:`) or similar for great changes - 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info - ❓ (`:question:`) for questions - 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion - 🎨 (`:art:`) for suggestions / improvements - ❌ (`:x:`) or ⚠️ (`:warning:`) for more significant problems or concerns needing attention - 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or indications of technical debt - ⛏ (`:pick:`) for minor or nitpick changes [PM-24248]: https://bitwarden.atlassian.net/browse/PM-24248?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent ae0cae2 commit 2f777cd

File tree

2 files changed

+60
-21
lines changed

2 files changed

+60
-21
lines changed

.github/workflows/build-android.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ jobs:
7171
fetch-depth: 0
7272
ref: ${{ github.event.pull_request.head.ref }}
7373

74-
- name: Checkout repo (Push)
74+
- name: Checkout repo (Push or manual run)
7575
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
76-
if: github.event_name == 'push'
76+
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
7777
with:
7878
fetch-depth: 0
7979

crates/bitwarden-uniffi/kotlin/sdk/build.gradle

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,38 +43,77 @@ android {
4343
}
4444
}
4545

46+
String composeDescription() {
47+
def commitHash = 'git rev-parse HEAD'.execute().text.trim()
48+
def changelog = 'git log -1 --oneline'.execute().text.trim()
49+
def workflowRunId = System.getenv('GITHUB_RUN_ID') ?: "local"
50+
51+
def workflowRunUrl
52+
switch (workflowRunId) {
53+
case "local":
54+
workflowRunUrl = "local"
55+
break
56+
default:
57+
workflowRunUrl = "https://github.com/bitwarden/sdk-internal/actions/runs/${workflowRunId}"
58+
break
59+
}
60+
61+
return """\
62+
🧱 commit: ${commitHash}
63+
💻 build source: ${workflowRunUrl}
64+
📜 changelog: ${changelog}""".stripIndent()
65+
}
66+
67+
String composeVersion(String branchName){
68+
def shortCommitHash = 'git rev-parse --short HEAD'.execute().text.trim()
69+
def workflowRunNumber = System.getenv('GITHUB_RUN_NUMBER') ?: "local"
70+
71+
def content = ['grep', '-o', '^version = ".*"', rootDir.toString() + '/../../../Cargo.toml'].execute().text.trim()
72+
def match = ~/version = "(.*)"/
73+
def sdkVersion = match.matcher(content)
74+
sdkVersion.find()
75+
76+
switch(branchName){
77+
case "main":
78+
return "${sdkVersion.group(1)}-${workflowRunNumber}-${shortCommitHash}"
79+
default:
80+
return "${sdkVersion.group(1)}-${workflowRunNumber}-${branchName.replaceAll('/', '-')}"
81+
}
82+
}
83+
4684
publishing {
4785
publications {
4886
maven(MavenPublication) {
87+
def branchName = 'git branch --show-current'.execute().text.trim()
4988
groupId = 'com.bitwarden'
50-
artifactId = 'sdk-android-temp'
89+
90+
switch (branchName) {
91+
case "main":
92+
artifactId = 'sdk-android'
93+
break
94+
default:
95+
artifactId = 'sdk-android.dev'
96+
break
97+
}
98+
99+
def aboutThisPackage = composeDescription()
51100

52101
if (findProperty('version') == 'unspecified') {
53-
// Determine the version from the git history.
54-
//
55-
// PRs: use the branch name.
56-
// Main: Grab it from `crates/bitwarden/Cargo.toml`
57-
58-
def branchName = 'git branch --show-current'.execute().text.trim()
59-
60-
if (branchName == 'main') {
61-
def content = ['grep', '-o', '^version = ".*"', rootDir.toString() + '/../../../Cargo.toml'].execute().text.trim()
62-
def match = ~/version = "(.*)"/
63-
def matcher = match.matcher(content)
64-
matcher.find()
65-
66-
version = "${matcher.group(1)}-SNAPSHOT"
67-
} else {
68-
// branchName-SNAPSHOT
69-
version = "${branchName.replaceAll('/', '-')}-SNAPSHOT"
70-
}
102+
version = composeVersion(branchName)
103+
}
104+
105+
pom {
106+
name.set("Bitwarden SDK for Android")
107+
description.set(aboutThisPackage)
108+
url.set("https://github.com/bitwarden/sdk-internal")
71109
}
72110

73111
afterEvaluate {
74112
from components.release
75113
}
76114
}
77115
}
116+
78117
repositories {
79118
maven {
80119
name = 'GitHubPackages'

0 commit comments

Comments
 (0)