Skip to content

Commit 7802573

Browse files
authored
CLOUDP-362263: Add update Atlas SDK script from CLI (#2945)
* add update sdk script from CLI * add SDK Update GHA * correct current sdk version * use go.mod for current sdk rather than file * add license text * appease linter
1 parent 0a24d10 commit 7802573

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed

.github/workflows/update-sdk.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Weekly Atlas SDK Update
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 3' # This cron expression runs the action at 00:00 UTC every Sunday
6+
workflow_dispatch:
7+
8+
jobs:
9+
update-devbox:
10+
runs-on: ubuntu-latest
11+
environment: release
12+
steps:
13+
- name: Checkout Repository
14+
uses: actions/checkout@v6
15+
- name: Generate GitHub App Token
16+
id: generate_token
17+
uses: actions/create-github-app-token@v2
18+
with:
19+
app-id: ${{ secrets.AKO_RELEASER_APP_ID }}
20+
private-key: ${{ secrets.AKO_RELEASER_RSA_KEY }}
21+
owner: ${{ github.repository_owner }}
22+
repositories: mongodb-atlas-kubernetes
23+
- name: Install devbox
24+
uses: jetify-com/[email protected]
25+
with:
26+
enable-cache: 'true'
27+
- name: Update Atlas SDK
28+
run: |
29+
./scripts/update-sdk.sh
30+
- name: Check for Changes
31+
id: check_changes
32+
run: |
33+
if git diff --quiet; then
34+
echo "No changes to commit."
35+
echo "CHANGES=false" >> $GITHUB_OUTPUT
36+
else
37+
echo "Changes detected."
38+
echo "CHANGES=true" >> $GITHUB_OUTPUT
39+
fi
40+
- name: Generate Branch Name
41+
id: generate_branch
42+
if: steps.check_changes.outputs.CHANGES == 'true'
43+
run: |
44+
RANDOM_NUM=$((RANDOM % 10000)) # Generate a random number between 0 and 9999
45+
BRANCH_NAME="atlas-sdk-update-$(date +'%Y-%m-%d')-$RANDOM_NUM"
46+
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_OUTPUT # Export branch name
47+
- name: Commit and Push Changes
48+
if: steps.check_changes.outputs.CHANGES == 'true'
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
COMMIT_MESSAGE: 'Atlas SDK Dependency Update'
52+
BRANCH: ${{ steps.generate_branch.outputs.BRANCH_NAME }}
53+
run: |
54+
git checkout -b "${BRANCH}"
55+
git add .
56+
scripts/create-signed-commit.sh
57+
58+
- name: Create Pull Request
59+
if: steps.check_changes.outputs.CHANGES == 'true'
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
run: |
63+
gh pr create --head=${{ steps.generate_branch.outputs.BRANCH_NAME }} --title "Atlas SDK Dependency Update" \
64+
--body "This PR contains the new updates to the Atlas Go SDK." \
65+
&& echo "Pull request created"
66+

scripts/update-sdk.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2025 MongoDB Inc
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -euo pipefail
18+
19+
CURRENT_SDK_RELEASE=$(go list -m all | grep go.mongodb.org/atlas-sdk | awk -F '/| ' '{print $3}')
20+
echo "CURRENT_SDK_RELEASE: $CURRENT_SDK_RELEASE"
21+
22+
LATEST_SDK_TAG=$(curl -sSfL -X GET https://api.github.com/repos/mongodb/atlas-sdk-go/releases/latest | jq -r '.tag_name')
23+
echo "LATEST_SDK_TAG: $LATEST_SDK_TAG"
24+
25+
LATEST_SDK_RELEASE=$(echo "${LATEST_SDK_TAG}" | cut -d '.' -f 1)
26+
echo "LATEST_SDK_RELEASE: $LATEST_SDK_RELEASE"
27+
echo "==> Updating SDK to latest major version ${LATEST_SDK_TAG}"
28+
29+
go tool --modfile tools/toolbox/go.mod gomajor get --rewrite "go.mongodb.org/atlas-sdk/${CURRENT_SDK_RELEASE}" "go.mongodb.org/atlas-sdk/${LATEST_SDK_RELEASE}@${LATEST_SDK_TAG}"
30+
go mod tidy
31+
32+
echo "Done"

tools/toolbox/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ tool (
66
fybrik.io/crdoc
77
github.com/crd2go/crd2go/cmd/crd2go
88
github.com/daixiang0/gci
9+
github.com/icholy/gomajor
910
github.com/vektra/mockery/v2
1011
)
1112

@@ -28,6 +29,7 @@ require (
2829
github.com/hexops/gotextdiff v1.0.3 // indirect
2930
github.com/huandu/xstrings v1.5.0 // indirect
3031
github.com/iancoleman/strcase v0.3.0 // indirect
32+
github.com/icholy/gomajor v0.15.0 // indirect
3133
github.com/inconshreveable/mousetrap v1.1.0 // indirect
3234
github.com/jinzhu/copier v0.4.0 // indirect
3335
github.com/json-iterator/go v1.1.12 // indirect

tools/toolbox/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI
4646
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
4747
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
4848
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
49+
github.com/icholy/gomajor v0.15.0 h1:/H5vbLaDIZddNKg90OK3bpjhkvlQQDsztFEJdxkv7wE=
50+
github.com/icholy/gomajor v0.15.0/go.mod h1:9i98u5jOn79D5/KHbQxhPI1Nqb+abJw+zFMOPTKSb6E=
4951
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
5052
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
5153
github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=

0 commit comments

Comments
 (0)