-
Notifications
You must be signed in to change notification settings - Fork 4
feat: adds python SDK #99
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
247e120
make adjustments so the python SDK can be generated
MelvinKl e747c60
adjust pipelines and scripts
MelvinKl 96f750b
adds python tools
MelvinKl f2e5d1d
Update scripts/sdk-create-pr.sh
MelvinKl e2e9e9e
PR comments
MelvinKl be2ef74
ci fix
MelvinKl 2f6d125
fix checkout
MelvinKl 189fe8c
fix
MelvinKl 5f15209
create new job for updating python repo
MelvinKl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| name: Generate SDK | ||
| description: "Generates the Python SDK" | ||
| inputs: | ||
| python-version: | ||
| description: "Python version to install" | ||
| required: true | ||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Download OAS | ||
| shell: bash | ||
| run: make download-oas | ||
| - name: Generate SDK | ||
| shell: bash | ||
| run: make generate-sdk LANGUAGE=python |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ env: | |
| JAVA_VERSION: '11' | ||
|
|
||
| jobs: | ||
| main: | ||
| main-go: | ||
| name: Update SDK Repo | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
|
|
@@ -32,10 +32,38 @@ jobs: | |
| with: | ||
| go-version: ${{ env.GO_VERSION }} | ||
| - name: Generate SDK | ||
| uses: ./.github/actions/generate-sdk | ||
| uses: ./.github/actions/generate-sdk/go | ||
| - name: Push SDK | ||
| env: | ||
| GH_REPO: 'stackitcloud/stackit-sdk-go' | ||
| GH_TOKEN: ${{ secrets.SDK_PR_TOKEN }} | ||
| run: | | ||
| scripts/sdk-create-pr.sh "generator-bot-${{ github.run_id }}" "Generated from GitHub run [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" | ||
| scripts/sdk-create-pr.sh "generator-bot-${{ github.run_id }}" "Generated from GitHub run [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" | ||
| main-python: | ||
| name: Update SDK Repo | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Install SSH Key | ||
| uses: shimataro/ssh-key-action@v2 | ||
| with: | ||
| key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
| known_hosts: ${{ vars.SSH_KNOWN_HOSTS }} | ||
| - name: Install Java | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: 'temurin' | ||
| java-version: ${{ env.JAVA_VERSION }} | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Build | ||
| uses: ./.github/actions/build | ||
| with: | ||
| go-version: ${{ env.GO_VERSION }} | ||
| - name: Generate SDK | ||
| uses: ./.github/actions/generate-sdk/python | ||
| - name: Push SDK | ||
| env: | ||
| GH_REPO: 'stackitcloud/stackit-sdk-python' | ||
| GH_TOKEN: ${{ secrets.SDK_PR_TOKEN }} | ||
| run: | | ||
| scripts/sdk-create-pr.sh "generator-bot-${{ github.run_id }}" "Generated from GitHub run [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" "[email protected]:stackitcloud/stackit-sdk-python.git" "python" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| #!/bin/bash | ||
| # This script clones the SDK repo and updates it with the generated API modules | ||
| # Pre-requisites: Java, goimports, Go | ||
| set -eo pipefail | ||
|
|
||
| ROOT_DIR=$(git rev-parse --show-toplevel) | ||
| SDK_REPO_LOCAL_PATH="${ROOT_DIR}/sdk-repo-updated" | ||
|
|
||
| OAS_REPO=https://github.com/stackitcloud/stackit-api-specifications | ||
|
|
||
| SERVICES_FOLDER="${SDK_REPO_LOCAL_PATH}/services" | ||
|
|
||
| GENERATOR_LOG_LEVEL="error" # Must be a Java log level (error, warn, info...) | ||
|
|
||
| generate_python_sdk() { | ||
| # Required parameters | ||
| local GENERATOR_JAR_PATH=$1 | ||
| local GIT_HOST=$2 | ||
| local GIT_USER_ID=$3 | ||
|
|
||
| # Optional parameters | ||
| local GIT_REPO_ID=$4 | ||
| local SDK_REPO_URL=$5 | ||
|
|
||
| # Check required parameters | ||
| if [[ -z ${GIT_HOST} ]]; then | ||
| echo "GIT_HOST not specified." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ -z ${GIT_USER_ID} ]]; then | ||
| echo "GIT_USER_ID id not specified." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check optional parameters and set defaults if not provided | ||
| if [[ -z ${GIT_REPO_ID} ]]; then | ||
| echo "GIT_REPO_ID not specified, default will be used." | ||
| GIT_REPO_ID="stackit-sdk-python" | ||
| fi | ||
|
|
||
| if [[ -z ${SDK_REPO_URL} ]]; then | ||
| echo "SDK_REPO_URL not specified, default will be used." | ||
| SDK_REPO_URL="https://github.com/stackitcloud/stackit-sdk-python.git" | ||
| fi | ||
|
|
||
| # Prepare folders | ||
| if [[ ! -d $SERVICES_FOLDER ]]; then | ||
| mkdir -p "$SERVICES_FOLDER" | ||
| fi | ||
|
|
||
| # Clone SDK repo | ||
| if [ -d ${SDK_REPO_LOCAL_PATH} ]; then | ||
| echo "Old SDK repo clone was found, it will be removed." | ||
| rm -rf ${SDK_REPO_LOCAL_PATH} | ||
| fi | ||
| git clone --quiet ${SDK_REPO_URL} ${SDK_REPO_LOCAL_PATH} | ||
|
|
||
| # Install SDK project tools | ||
| cd ${ROOT_DIR} | ||
| make project-tools | ||
|
|
||
| # Backup of the current state of the SDK services dir (services/) | ||
| sdk_services_backup_dir=$(mktemp -d) | ||
| if [[ ! ${sdk_services_backup_dir} || -d {sdk_services_backup_dir} ]]; then | ||
| echo "Unable to create temporary directory" | ||
| exit 1 | ||
| fi | ||
| cleanup() { | ||
| rm -rf ${sdk_services_backup_dir} | ||
| } | ||
| cp -a "${SERVICES_FOLDER}/." ${sdk_services_backup_dir} | ||
|
|
||
| # Cleanup after we are done | ||
| trap cleanup EXIT | ||
|
|
||
| # Remove old contents of services dir (services/) | ||
| rm -rf ${SERVICES_FOLDER} | ||
|
|
||
| # Generate SDK for each service | ||
| for service_json in ${ROOT_DIR}/oas/*.json; do | ||
| service="${service_json##*/}" | ||
| service="${service%.json}" | ||
|
|
||
| # Remove invalid characters to ensure a valid Go pkg name | ||
| service="${service//-/}" # remove dashes | ||
| service="${service// /}" # remove empty spaces | ||
| service="${service//_/}" # remove underscores | ||
| service=$(echo "${service}" | tr '[:upper:]' '[:lower:]') # convert upper case letters to lower case | ||
| service=$(echo "${service}" | tr -d -c '[:alnum:]') # remove non-alphanumeric characters | ||
|
|
||
| echo "Generating \"${service}\" service..." | ||
| cd ${ROOT_DIR} | ||
|
|
||
| mkdir -p "${SERVICES_FOLDER}/${service}/" | ||
| cp "${ROOT_DIR}/scripts/generate-sdk/.openapi-generator-ignore" "${SERVICES_FOLDER}/${service}/" | ||
|
|
||
| # Run the generator | ||
| java -Dlog.level=${GENERATOR_LOG_LEVEL} -jar ${jar_path} generate \ | ||
| --generator-name python \ | ||
| --input-spec "${service_json}" \ | ||
| --output "${SERVICES_FOLDER}/${service}" \ | ||
| --package-name "stackit.${service}" \ | ||
| --template-dir "${ROOT_DIR}/templates/python/" \ | ||
| --git-host ${GIT_HOST} \ | ||
| --git-user-id ${GIT_USER_ID} \ | ||
| --git-repo-id ${GIT_REPO_ID} \ | ||
| --global-property apis,models,modelTests=false,modelDocs=false,apiDocs=false,apiTests=false,supportingFiles \ | ||
| --additional-properties=pythonPackageName="stackit-${service},removeEnumValuePrefix=false" >/dev/null | ||
|
|
||
| # Remove unnecessary files | ||
| rm "${SERVICES_FOLDER}/${service}/.openapi-generator-ignore" | ||
| rm -r "${SERVICES_FOLDER}/${service}/.openapi-generator/" | ||
| rm "${SERVICES_FOLDER}/${service}/stackit/__init__.py" | ||
| rm "${SERVICES_FOLDER}/${service}/.github/workflows/python.yml" | ||
|
|
||
|
|
||
| # If the service has a wait package files, move them inside the service folder | ||
| if [ -d ${sdk_services_backup_dir}/${service}/wait ]; then | ||
| echo "Found ${service} \"wait\" package" | ||
| cp -r ${sdk_services_backup_dir}/${service}/wait ${SERVICES_FOLDER}/${service}/wait | ||
| fi | ||
|
|
||
| # If the service has a CHANGELOG file, move it inside the service folder | ||
| if [ -f ${sdk_services_backup_dir}/${service}/CHANGELOG.md ]; then | ||
| echo "Found ${service} \"CHANGELOG\" file" | ||
| cp -r ${sdk_services_backup_dir}/${service}/CHANGELOG.md ${SERVICES_FOLDER}/${service}/CHANGELOG.md | ||
| fi | ||
|
|
||
| # If the service has a LICENSE file, move it inside the service folder | ||
| if [ -f ${sdk_services_backup_dir}/${service}/LICENSE.md ]; then | ||
| echo "Found ${service} \"LICENSE\" file" | ||
| cp -r ${sdk_services_backup_dir}/${service}/LICENSE.md ${SERVICES_FOLDER}/${service}/LICENSE.md | ||
| fi | ||
|
|
||
| # If the service has a NOTICE file, move it inside the service folder | ||
| if [ -f ${sdk_services_backup_dir}/${service}/NOTICE.txt ]; then | ||
| echo "Found ${service} \"NOTICE\" file" | ||
| cp -r ${sdk_services_backup_dir}/${service}/NOTICE.txt ${SERVICES_FOLDER}/${service}/NOTICE.txt | ||
| fi | ||
|
|
||
| cd ${SERVICES_FOLDER}/${service} | ||
| # Run formatter | ||
| isort . | ||
| autoimport --ignore-init-modules . | ||
| black . | ||
|
|
||
| done | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.