Skip to content

Commit 73306e3

Browse files
committed
Detect downgrades
1 parent 854f391 commit 73306e3

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

.github/workflows/sdlc-sdk-update.yml

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,28 @@ jobs:
146146
echo "sdk-swift-ref=$SDK_SWIFT_REF" >> $GITHUB_OUTPUT
147147
echo "sdk-internal-ref=$SDK_INTERNAL_REF" >> $GITHUB_OUTPUT
148148
149+
- name: Detect downgrade and prevent updating to the current version
150+
id: detect-downgrade
151+
env:
152+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
153+
_CURRENT_SDK_SWIFT_REF: ${{ steps.get-current-sdk.outputs.sdk-swift-ref }}
154+
_NEW_SDK_SWIFT_REF: ${{ inputs.sdk-swift-ref }}
155+
run: |
156+
if [ "$_CURRENT_SDK_SWIFT_REF" = "$_NEW_SDK_SWIFT_REF" ]; then
157+
echo "::error::Provided sdk-swift ref is the same as the current version in main."
158+
exit 1
159+
fi
160+
161+
COMPARE_RESULT=$(gh api "repos/bitwarden/sdk-swift/compare/$_CURRENT_SDK_SWIFT_REF...$_NEW_SDK_SWIFT_REF" --jq '.status')
162+
163+
if [ "$COMPARE_RESULT" = "ahead" ]; then
164+
echo "::warning::The new SDK version ($_NEW_SDK_SWIFT_REF) is older than the current version ($_CURRENT_SDK_SWIFT_REF)"
165+
echo "downgrading=true" >> $GITHUB_OUTPUT
166+
else
167+
echo "✅ New SDK version is newer - proceeding with update"
168+
echo "downgrading=false" >> $GITHUB_OUTPUT
169+
fi
170+
149171
- name: Update SDK Version
150172
env:
151173
_SDK_VERSION: ${{ inputs.sdk-version }}
@@ -177,29 +199,34 @@ jobs:
177199
_NEW_SDK_SWIFT_REF: ${{ inputs.sdk-swift-ref }}
178200
_OLD_SDK_SWIFT_REF: ${{ steps.get-current-sdk.outputs.sdk-swift-ref }}
179201
_OLD_SDK_INTERNAL_REF: ${{ steps.get-current-sdk.outputs.sdk-internal-ref }}
202+
_DOWNGRADING: ${{ steps.detect-downgrade.outputs.downgrading }}
180203
run: |
181204
_NEW_SDK_INTERNAL_REF=$(echo "$_NEW_SDK_VERSION" | cut -d'-' -f3-)
182-
CHANGELOG=$(./Scripts/get-repo-changelog.sh "bitwarden/sdk-internal" "$_OLD_SDK_INTERNAL_REF" "$_NEW_SDK_INTERNAL_REF")
183-
PR_BODY="Updates the SDK from \`$_OLD_SDK_SWIFT_REF\` to \`$_NEW_SDK_SWIFT_REF\`
205+
PR_BODY="Updates the SDK from \`$_OLD_SDK_SWIFT_REF\` to \`$_NEW_SDK_SWIFT_REF\`"
184206
185-
## What's Changed
186-
187-
$CHANGELOG"
207+
if [ "$_DOWNGRADING" = "true" ]; then
208+
PR_BODY="$PR_BODY\n\n ##:warning: Downgrading SDK to an older version. :warning:"
209+
PR_TITLE_ACTION="Downgrading"
210+
else
211+
CHANGELOG=$(./Scripts/get-repo-changelog.sh "bitwarden/sdk-internal" "$_OLD_SDK_INTERNAL_REF" "$_NEW_SDK_INTERNAL_REF")
212+
PR_BODY="$PR_BODY\n\n ## What's Changed\n\n$CHANGELOG"
213+
PR_TITLE_ACTION="Updating"
214+
fi
188215
189216
EXISTING_PR=$(gh pr list --head $_BRANCH_NAME --base main --state open --json number --jq '.[0].number // empty')
190217
_NEW_SDK_SWIFT_REF_SHORT="${_NEW_SDK_SWIFT_REF:0:7}"
191218
192219
if [ -n "$EXISTING_PR" ]; then
193220
echo "🔄 Updating existing PR #$EXISTING_PR..."
194221
echo -e "$PR_BODY" | gh pr edit $EXISTING_PR \
195-
--title "Update SDK to $_NEW_SDK_SWIFT_REF_SHORT ($_NEW_SDK_VERSION)" \
222+
--title "$PR_TITLE_ACTION SDK to $_NEW_SDK_SWIFT_REF_SHORT ($_NEW_SDK_VERSION)" \
196223
--body-file -
197224
PR_URL="https://github.com/${{ github.repository }}/pull/$EXISTING_PR"
198225
echo "## ✅ Updated PR: $PR_URL" >> $GITHUB_STEP_SUMMARY
199226
else
200227
echo "📝 Creating new PR..."
201228
PR_URL=$(echo -e "$PR_BODY" | gh pr create \
202-
--title "Update SDK to $_NEW_SDK_SWIFT_REF_SHORT ($_NEW_SDK_VERSION)" \
229+
--title "$PR_TITLE_ACTION SDK to $_NEW_SDK_SWIFT_REF_SHORT ($_NEW_SDK_VERSION)" \
203230
--body-file - \
204231
--base main \
205232
--head $_BRANCH_NAME \

0 commit comments

Comments
 (0)