Skip to content

update workflow #586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 34 additions & 15 deletions .github/workflows/autoupdate-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch tags history
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
# - run: make install-goimports

# Installing mockery manually as tools/scripts/generate_mocks.sh would error out even after go version update in go.mod
# err: exit status 1: stderr: go: go.mod requires go >= 1.23.0 (running go 1.22.1; GOTOOLCHAIN=local)\n" dry-run=false version=v2.42.1
- name: Install mockery
run: go install github.com/vektra/mockery/v2@v2.42.1

- name: Fetch changes
working-directory: ./tools
run: make fetch_openapi
Expand All @@ -22,12 +31,15 @@ jobs:
git config --global user.name "github-actions[bot]"
git add .
git commit --allow-empty -m "fix: update OpenAPI spec"
- name: Set old commit for SDK API diff
run: echo "API_DIFF_OLD_COMMIT=v20231115014.0.0" >> $GITHUB_ENV
- name: Run generation
working-directory: ./tools
run: |
export PATH=${PATH}:`go env GOPATH`/bin
make clean_and_generate
- name: Verify Changed files
uses: tj-actions/verify-changed-files@fd85a6022db9aa8345ca15c3adb91d486780bfd9
uses: tj-actions/verify-changed-files@bbd436f8e34e14fee2a0f7bc5b14bcc6b40927cf
id: verify-changed-files
with:
files: |
Expand All @@ -36,35 +48,43 @@ jobs:
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: make gen-docs
- name: Commit Generator Changes
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |
git add . && git commit -m "fix: Generated SDK source code and docs"
- name: Set new commit for SDK API diff
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: echo "API_DIFF_NEW_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Release updates
if: steps.verify-changed-files.outputs.files_changed == 'true'
working-directory: ./tools
env:
GIT_BASE_REF: ${{ github.sha }}
run: |
make new-release
run: make new-release
- name: Ensure all markdown code is formatted
if: steps.verify-changed-files.outputs.files_changed == 'true'
working-directory: ./tools
run: |
npm install && npm run format
- name: Install dependencies for mocks
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |
go mod tidy
go get -u golang.org/x/oauth2

- name: Run mock generation
working-directory: ./tools
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: make generate_mocks
- uses: peter-evans/create-pull-request@v6

- uses: peter-evans/create-pull-request@v7
if: steps.verify-changed-files.outputs.files_changed == 'true'
env:
GITHUB_TOKEN: ${{ secrets.REPO_SCOPED_GITHUB_TOKEN }}
with:
title: "APIBot: SDK update based on recent changes in Atlas API"
token: ${{ secrets.APIX_BOT_PAT }}
title: "APIBot: SDK update based on recent changes in Atlas API (v20231115014) - DO NOT merge"
commit-message: "fix: required version bumps for Atlas SDK release"
delete-branch: true
branch: api-bot-update
draft: true
branch: api-bot-update-v20231115014-backport-cluster
body: |
Automatic update for MongoDB Atlas Go Client based on OpenAPI changes.
Automatic update for MongoDB Atlas Go Client based on OpenAPI changes for API version 2023-11-15.
PR contains autogenerated changes for the MongoDB Atlas client.

## Automated checks
Expand All @@ -73,8 +93,6 @@ jobs:
2. Documentation style
3. Transformation engine linting

> NOTE: New automation PRs need to be closed and reopened to trigger builds

## Important Details

1. If the build is failing please check the logs and fix the issues in the OpenAPI file (openapi/atlas-api.yaml)
Expand All @@ -87,7 +105,8 @@ jobs:
2. If PR contains breaking changes, review `./releaser/breaking_changes/{release_version}.md` file
3. Approve and merge PR into the main branch
4. After the merge automated release process will be triggered.



## Troubleshooting

To skip release process after merge please revert changes from `version.go` file.
Release can be triggered by restoring changes in version.go.
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
args: --timeout=10m

tests-on-unix:
needs: golangci-lint # run after golangci-lint action to not produce duplicated errors
# needs: golangci-lint # run after golangci-lint action to not produce duplicated errors
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -34,4 +34,4 @@ jobs:
with:
go-version-file: 'go.mod'
- name: Run tests
run: make test
run: make test
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module go.mongodb.org/atlas-sdk/v20231115014

go 1.21
go 1.23.0

toolchain go1.23.8

require (
github.com/go-test/deep v1.1.0
Expand Down
17 changes: 8 additions & 9 deletions tools/releaser/scripts/new-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,32 @@ if [ "$NEW_RESOURCE_VERSION" == "$SDK_RESOURCE_VERSION" ]; then
# Update the SDK_VERSION
SDK_VERSION="${SDK_MAJOR_VERSION}.${new_minor_version}.0"

echo "Print breaking changes"
echo "Print breaking changes"
# shellcheck source=/dev/null
source "$script_path/breaking-changes.sh"
if [ -n "$BREAKING_CHANGES" ]; then
echo "BREAKING CHANGES DETECTED FOR NON MAJOR VERSION BUMP"
# shellcheck source=/dev/null
source "$script_path/update-version.sh"
exit 0;
# source "$script_path/update-version.sh" # we don't want to update the version so commenting this out for now
# exit 0;
fi
else
else
# Update the SDK_VERSION
echo "Resource Version is not up to date. Changing major version."
NEW_MAJOR_VERSION="v${NEW_RESOURCE_VERSION}001"
SDK_VERSION="${NEW_MAJOR_VERSION}.0.0"
echo "generate breaking changes file"
SDK_VERSION="${NEW_MAJOR_VERSION}.0.0"
echo "generate breaking changes file"
export TARGET_BREAKING_CHANGES_FILE=${NEW_MAJOR_VERSION}
# shellcheck source=/dev/null
source "$script_path/breaking-changes.sh"

echo "Modifying all instances of version from $SDK_RESOURCE_VERSION to $NEW_RESOURCE_VERSION across the repository."
npm install
npm exec -c "replace-in-file /$SDK_MAJOR_VERSION/g $NEW_MAJOR_VERSION $VERSION_UPDATE_PATHS --isRegex"
fi
fi

echo "Creating new version.go file with $SDK_VERSION and resource version: $NEW_RESOURCE_VERSION"

export SDK_VERSION
export NEW_RESOURCE_VERSION

envsubst < "$script_path/../templates/VERSION.tmpl" > $target_file_path
envsubst <"$script_path/../templates/VERSION.tmpl" >$target_file_path
19 changes: 10 additions & 9 deletions tools/scripts/fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,26 @@ OPENAPI_FOLDER=${OPENAPI_FOLDER:-"../openapi"}
S3_BUCKET=${S3_BUCKET:-"mongodb-mms-prod-build-server"}

versions_url="${API_BASE_URL}/api/openapi/versions"
versions_file="versions.json"
# versions_file="versions.json"

pushd "${OPENAPI_FOLDER}"
echo "Fetching versions from $versions_url"

curl --show-error --fail --silent -o "${versions_file}" \
-H "Accept: application/json" "${versions_url}"
# curl --show-error --fail --silent -o "${versions_file}" \
# -H "Accept: application/json" "${versions_url}"

## Dynamic Versioned API Version
CURRENT_API_REVISION=$(jq -r '.versions."2.0" | .[-1]' < "./${versions_file}")
# CURRENT_API_REVISION=$(jq -r '.versions."2.0" | .[-1]' <"./${versions_file}")

echo "Fetching OpenAPI release sha"
sha=$(curl --show-error --fail --silent -H "Accept: text/plain" "${API_BASE_URL}/api/private/unauth/version")
# echo "Fetching OpenAPI release sha"
# sha=$(curl --show-error --fail --silent -H "Accept: text/plain" "${API_BASE_URL}/api/private/unauth/version")

echo "Fetching OAS file for ${sha}"
openapi_url="https://${S3_BUCKET}.s3.amazonaws.com/openapi/${sha}-v2-${CURRENT_API_REVISION}.yaml"
# echo "Fetching OAS file for ${sha}"
# openapi_url="https://${S3_BUCKET}.s3.amazonaws.com/openapi/${sha}-v2-${CURRENT_API_REVISION}.yaml"
openapi_url="https://raw.githubusercontent.com/mongodb/openapi/refs/heads/main/openapi/v2/openapi-2023-11-15.yaml"

echo "Fetching api from $openapi_url to $OPENAPI_FILE_NAME"

curl --show-error --fail --silent -o "$OPENAPI_FILE_NAME" "$openapi_url"

popd -0
popd -0
13 changes: 9 additions & 4 deletions tools/scripts/generate_mocks.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#!/bin/sh
rm -Rf ../mockadmin

# install only if not already present
if ! which mockery ; then
docker run --rm -u "$(id -u):$(id -g)" -v "$(dirname "$PWD")":/src --workdir=/src vektra/mockery:v2.42.1
else
# Use the locally installed mockery
if which mockery >/dev/null 2>&1; then
mockery --dir ../mockadmin
else
echo "mockery not found; please ensure it is installed."
exit 1
fi

# Use any instead of interface{} in generated mocks
npm install
npm exec -c "replace-in-file /interface{}/g any ../mockadmin/**/*.go --isRegex"