|
| 1 | +name: SDLC / SDK Update |
| 2 | +run-name: "SDK ${{inputs.run-mode == 'Update' && format('Update - {0}', inputs.sdk-version) || format('Test #{0} - {1}', inputs.pr-id, inputs.sdk-version)}}" |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + run-mode: |
| 8 | + description: "Run Mode" |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - Test # used for testing sdk-internal repo PRs |
| 12 | + - Update # opens a PR in this repo updating the SDK |
| 13 | + default: Test |
| 14 | + # |
| 15 | + sdk-package: |
| 16 | + description: "SDK Package ID" |
| 17 | + required: true |
| 18 | + default: "BitwardenSdk" |
| 19 | + sdk-version: |
| 20 | + description: "SDK Version" |
| 21 | + required: true |
| 22 | + default: "2a6609428275c758fcda5383bfb6b3166ec29eda" |
| 23 | + pr-id: |
| 24 | + description: "Pull Request ID" |
| 25 | + |
| 26 | +jobs: |
| 27 | + update: |
| 28 | + name: Update and PR |
| 29 | + if: ${{ inputs.run-mode == 'Update' }} |
| 30 | + runs-on: ubuntu-24.04 |
| 31 | + permissions: |
| 32 | + id-token: write |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: Log in to Azure |
| 36 | + uses: bitwarden/gh-actions/azure-login@main |
| 37 | + with: |
| 38 | + subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
| 39 | + tenant_id: ${{ secrets.AZURE_TENANT_ID }} |
| 40 | + client_id: ${{ secrets.AZURE_CLIENT_ID }} |
| 41 | + |
| 42 | + - name: Get Azure Key Vault secrets |
| 43 | + id: get-kv-secrets |
| 44 | + uses: bitwarden/gh-actions/get-keyvault-secrets@main |
| 45 | + with: |
| 46 | + keyvault: gh-org-bitwarden |
| 47 | + secrets: "BW-GHAPP-ID,BW-GHAPP-KEY" |
| 48 | + |
| 49 | + - name: Log out from Azure |
| 50 | + uses: bitwarden/gh-actions/azure-logout@main |
| 51 | + |
| 52 | + - name: Generate GH App token |
| 53 | + uses: actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b # v2.1.1 |
| 54 | + id: app-token |
| 55 | + with: |
| 56 | + app-id: ${{ steps.get-kv-secrets.outputs.BW-GHAPP-ID }} |
| 57 | + private-key: ${{ steps.get-kv-secrets.outputs.BW-GHAPP-KEY }} |
| 58 | + |
| 59 | + - name: Check out repo |
| 60 | + uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 |
| 61 | + with: |
| 62 | + token: ${{ steps.app-token.outputs.token }} |
| 63 | + |
| 64 | + - name: Log inputs to job summary |
| 65 | + uses: ./.github/actions/log-inputs |
| 66 | + with: |
| 67 | + inputs: ${{ toJson(inputs) }} |
| 68 | + |
| 69 | + - name: Switch to branch |
| 70 | + id: switch-branch |
| 71 | + run: | |
| 72 | + BRANCH_NAME="sdlc/sdk-update" |
| 73 | + echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT |
| 74 | + git switch -c $BRANCH_NAME |
| 75 | +
|
| 76 | + - name: Get current SDK version |
| 77 | + id: get-current-sdk |
| 78 | + run: | |
| 79 | + SDK_VERSION=$(awk '/BitwardenSdk:/,/^ [A-Za-z]/ { if ($1 == "revision:") print $2 }' project-bwa.yml) |
| 80 | + GIT_REF=$(echo "$SDK_VERSION" | cut -d'-' -f3-) # handles both commit hashes and branch names |
| 81 | + echo "Current SDK version: $SDK_VERSION" |
| 82 | + echo "Current SDK git ref: $GIT_REF" |
| 83 | + echo "version=$SDK_VERSION" >> $GITHUB_OUTPUT |
| 84 | + echo "git_ref=$GIT_REF" >> $GITHUB_OUTPUT |
| 85 | +
|
| 86 | + - name: Update SDK Version |
| 87 | + env: |
| 88 | + _SDK_PACKAGE: ${{ inputs.sdk-package }} |
| 89 | + _SDK_VERSION: ${{ inputs.sdk-version }} |
| 90 | + run: | |
| 91 | + ./scripts/update-sdk-version.sh "$_SDK_PACKAGE" "$_SDK_VERSION" |
| 92 | +
|
| 93 | + - name: Create branch and commit |
| 94 | + env: |
| 95 | + _SDK_PACKAGE: ${{ inputs.sdk-package }} |
| 96 | + _SDK_VERSION: ${{ inputs.sdk-version }} |
| 97 | + _BRANCH_NAME: ${{ steps.switch-branch.outputs.branch_name }} |
| 98 | + run: | |
| 99 | + echo "👀 Committing SDK version update..." |
| 100 | +
|
| 101 | + git config user.name "bw-ghapp[bot]" |
| 102 | + git config user.email "178206702+bw-ghapp[bot]@users.noreply.github.com" |
| 103 | +
|
| 104 | + git add project-bwa.yml project-bwk.yml project-pm.yml |
| 105 | + git commit -m "SDK Update - $_SDK_PACKAGE $_SDK_VERSION" |
| 106 | + git push origin $_BRANCH_NAME |
| 107 | +
|
| 108 | + - name: Create Pull Request |
| 109 | + env: |
| 110 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 111 | + _BRANCH_NAME: ${{ steps.switch-branch.outputs.branch_name }} |
| 112 | + _SDK_PACKAGE: ${{ inputs.sdk-package }} |
| 113 | + _SDK_VERSION: ${{ inputs.sdk-version }} |
| 114 | + _OLD_SDK_VERSION: ${{ steps.get-current-sdk.outputs.version }} |
| 115 | + _OLD_SDK_GIT_REF: ${{ steps.get-current-sdk.outputs.git_ref }} |
| 116 | + run: | |
| 117 | + NEW_SDK_GIT_REF=$(echo "$_SDK_VERSION" | cut -d'-' -f3-) |
| 118 | + PR_BODY="Updates the SDK version from \`$_OLD_SDK_VERSION\` to \`$_SDK_PACKAGE $_SDK_VERSION\` |
| 119 | +
|
| 120 | + ## What's Changed |
| 121 | +
|
| 122 | + # Use echo -e to interpret escape sequences and pipe to gh pr create |
| 123 | + PR_URL=$(echo -e "$PR_BODY" | gh pr create \ |
| 124 | + --title "Update SDK to $_SDK_VERSION" \ |
| 125 | + --body-file - \ |
| 126 | + --base main \ |
| 127 | + --head $_BRANCH_NAME \ |
| 128 | + --label "automated-pr" \ |
| 129 | + --label "t:ci") |
| 130 | +
|
| 131 | + echo "🚀 Created PR: $PR_URL" |
| 132 | + echo "## 🚀 Created PR: $PR_URL" >> $GITHUB_STEP_SUMMARY |
| 133 | +
|
| 134 | +# test: |
| 135 | +# name: Test Update |
| 136 | +# if: ${{ inputs.run-mode == 'Test' }} |
| 137 | +# runs-on: ubuntu-24.04 |
| 138 | +# permissions: |
| 139 | +# contents: read |
| 140 | +# packages: read |
| 141 | +# |
| 142 | +# steps: |
| 143 | +# - name: Check out repo |
| 144 | +# uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 |
| 145 | +# |
| 146 | +# - name: Log inputs to job summary |
| 147 | +# uses: ./.github/actions/log-inputs |
| 148 | +# with: |
| 149 | +# inputs: ${{ toJson(inputs) }} |
| 150 | +# |
| 151 | +# - name: Setup Android Build |
| 152 | +# uses: ./.github/actions/setup-android-build |
| 153 | +# |
| 154 | +# - name: Update SDK Version |
| 155 | +# env: |
| 156 | +# _SDK_PACKAGE: ${{ inputs.sdk-package }} |
| 157 | +# _SDK_VERSION: ${{ inputs.sdk-version }} |
| 158 | +# run: | |
| 159 | +# ./scripts/update-sdk-version.sh "$_SDK_PACKAGE" "$_SDK_VERSION"0 |
| 160 | +# |
| 161 | +# - name: Build |
| 162 | +# env: |
| 163 | +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Used in settings.gradle.kts to download the SDK from GitHub Maven Packages |
| 164 | +# run: | |
| 165 | +# ./gradlew assembleDebug --warn |
0 commit comments