From 0185899f1479a945d4df6b74784e701071ad58d2 Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Thu, 21 Sep 2023 16:33:20 +0200 Subject: [PATCH] Change maven artifactId to sdk-android (#235) * Remove github_actor * Use custom git commands instead * Grab from cargo file instead * Add workflow for cleaning up old packages * Only specify min-versions-to-keep * Update name --------- Co-authored-by: Matt Bishop --- .github/workflows/build-android.yml | 15 +------------- .github/workflows/delete-old-packages.yml | 25 +++++++++++++++++++++++ languages/kotlin/app/build.gradle | 2 +- languages/kotlin/sdk/build.gradle | 24 +++++++++++++++------- 4 files changed, 44 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/delete-old-packages.yml diff --git a/.github/workflows/build-android.yml b/.github/workflows/build-android.yml index f723859a6..579392c8e 100644 --- a/.github/workflows/build-android.yml +++ b/.github/workflows/build-android.yml @@ -101,23 +101,10 @@ jobs: working-directory: languages/kotlin run: ./build-schemas.sh - - name: Login to Azure - CI Subscription - uses: Azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7 - with: - creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} - - - name: Retrieve bot secrets - id: retrieve-bot-secrets - uses: bitwarden/gh-actions/get-keyvault-secrets@8fccdaea2810d5dfb13753b6dd93bbd3a63ff82e - with: - keyvault: bitwarden-ci - secrets: "github-pat-bitwarden-devops-bot-packages-scope" - - name: Publish uses: gradle/gradle-build-action@ef76a971e2fa3f867b617efd72f2fbd72cf6f8bc # v2.8.0 with: arguments: sdk:publish build-root-directory: languages/kotlin env: - GITHUB_ACTOR: "bitwarden-devops-bot" - GITHUB_TOKEN: ${{ steps.retrieve-bot-secrets.outputs.github-pat-bitwarden-devops-bot-packages-scope }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/delete-old-packages.yml b/.github/workflows/delete-old-packages.yml new file mode 100644 index 000000000..517560ede --- /dev/null +++ b/.github/workflows/delete-old-packages.yml @@ -0,0 +1,25 @@ +--- +name: Delete old packages + +on: + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + +defaults: + run: + shell: bash + +jobs: + delete: + name: Cleanup Android SDK + runs-on: ubuntu-22.04 + steps: + - uses: actions/delete-package-versions@0d39a63126868f5eefaa47169615edd3c0f61e20 # v4.1.1 + with: + package-name: com.bitwarden.sdk-android + package-type: maven + min-versions-to-keep: 25 + + # Ignore versions only containing version numbers + ignore-versions: '^\\d*\\.\\d*\\.\\d*$' diff --git a/languages/kotlin/app/build.gradle b/languages/kotlin/app/build.gradle index 2b7bc0255..709e32889 100644 --- a/languages/kotlin/app/build.gradle +++ b/languages/kotlin/app/build.gradle @@ -48,7 +48,7 @@ android { } dependencies { - // implementation 'com.bitwarden.sdk' + // implementation 'com.bitwarden.sdk-android' implementation project(':sdk') implementation 'androidx.core:core-ktx:1.8.0' diff --git a/languages/kotlin/sdk/build.gradle b/languages/kotlin/sdk/build.gradle index 3d164e094..5b8637f83 100644 --- a/languages/kotlin/sdk/build.gradle +++ b/languages/kotlin/sdk/build.gradle @@ -2,7 +2,6 @@ plugins { id 'com.android.library' id 'org.jetbrains.kotlin.android' id 'maven-publish' - id 'com.palantir.git-version' version '3.0.0' } android { @@ -42,14 +41,25 @@ publishing { publications { maven(MavenPublication) { groupId = 'com.bitwarden' - artifactId = 'sdk' + artifactId = 'sdk-android' - def details = versionDetails() + // Determine the version from the git history. + // + // PRs: use the branch name. + // Master: Grab it from `crates/bitwarden/Cargo.toml` - if (details.branchName == null) { - version = "master-SNAPSHOT" + def branchName = "git branch --show-current".execute().text.trim() + + if (branchName == null) { + def content = ['grep', '-o', '^version = ".*"', '../../crates/bitwarden/Cargo.toml'].execute().text.trim() + def match = ~/version = "(.*)"/ + def matcher = match.matcher(content) + matcher.find() + + version = "${matcher.group(1)}-SNAPSHOT" } else { - version "${details.branchName.replaceAll('/', '-')}-SNAPSHOT" + // branchName-SNAPSHOT + version = "${branchName.replaceAll('/', '-')}-SNAPSHOT" } afterEvaluate { @@ -60,7 +70,7 @@ publishing { repositories { maven { name = "GitHubPackages" - url = "https://maven.pkg.github.com/bitwarden/sdk-maven" + url = "https://maven.pkg.github.com/bitwarden/sdk" credentials { username = System.getenv("GITHUB_ACTOR") password = System.getenv("GITHUB_TOKEN")