Skip to content

generate-python

generate-python #37

name: Generate Python SDK
on:
repository_dispatch:
types: [generate-python]
jobs:
generate-python-sdk:
runs-on: ubuntu-latest
env:
GIT_REPO_ID: fattureincloud-python-sdk
GIT_USER_ID: fattureincloud
steps:
- id: checkout
name: Checkout repo
uses: actions/checkout@v4
with:
token: ${{ secrets.FATTUREINCLOUD_BOT_TOKEN }}
- id: checkout-python
name: Checkout Python repo
env:
GIT_REPO_PATH: '${{ env.GIT_USER_ID }}/${{ env.GIT_REPO_ID }}'
uses: actions/checkout@v4
with:
path: ./generated/python
ref: master
repository: ${{ env.GIT_REPO_PATH }}
token: ${{ secrets.FATTUREINCLOUD_BOT_TOKEN }}
- id: init-git
name: Init GIT
run: |
git config --global user.email "info@fattureincloud.it"
git config --global user.name "fattureincloud-bot"
- id: setup-node
name: Setup Node.js
uses: actions/setup-node@v4
- id: setup-java
name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: '11'
- id: setup-python
name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- id: setup-libraries
name: Install libraries
run: |
npm install -g yarn
yarn global add @apidevtools/swagger-cli @openapitools/openapi-generator-cli standard-version
sudo add-apt-repository ppa:rmescandon/yq -y
sudo apt update
sudo apt install yq -y
cd ./scripts/
yarn
cd ../generated/python/scripts
yarn
- id: bump-python-sdk-version
name: Bump Python SDK
env:
OPENAPI_VERSION: ${{ github.event.client_payload.version }}
run: |
echo "openapi_version=$OPENAPI_VERSION"
BUMP_TYPE=$(node ./scripts/sdk-version-checker.js ./generated/python/sdk-version.yaml $OPENAPI_VERSION)
cd ./generated/python
if [ "$BUMP_TYPE" == "patch" ];then
echo 'Bumping the SDK patch version...'
standard-version --skip.tag --skip.changelog --skip.commit --release-as patch
elif [ "$BUMP_TYPE" == "openapi" ];then
echo 'Using the openapi version...'
standard-version --skip.tag --skip.changelog --skip.commit --release-as $OPENAPI_VERSION
else
echo "Something bad happened - impossible to bump Python SDK version. value=$BUMP_TYPE"
fi
SDK_VERSION=$(yq e '.info.version' ./sdk-version.yaml)
echo "sdk_version=$SDK_VERSION" >> $GITHUB_ENV
echo "openapi_version=$OPENAPI_VERSION" >> $GITHUB_ENV
- id: move-custom-files-to-backup
name: Move custom files to backup
run: |
mkdir -p ./backup/python/fattureincloud_python_sdk/filter
mkdir -p ./backup/python/fattureincloud_python_sdk/oauth2
mv ./generated/python/fattureincloud_python_sdk/filter ./backup/python/fattureincloud_python_sdk/
mv ./generated/python/fattureincloud_python_sdk/oauth2 ./backup/python/fattureincloud_python_sdk/
- id: delete-old-files
name: Delete old files
run: |
rm -rf ./generated/python/fattureincloud_python_sdk
rm -rf ./generated/python/docs
- id: generate-python-sdk
name: Generate Python SDK
env:
PACKAGE_NAME: "fattureincloud_python_sdk"
PACKAGE_URL: "https://github.com/fattureincloud/fattureincloud-python-sdk"
PROJECT_NAME: "fattureincloud-python-sdk"
INFO_NAME: "\"Fatture in Cloud API Team\""
APP_NAME: "FattureInCloud"
run: |
SDK_VERSION=${{ env.sdk_version }}
echo "${{ env.sdk_version }}"
RELEASE_NOTE="\"bumping version to $SDK_VERSION\""
USER_AGENT="$APP_NAME/${{ env.sdk_version }}/Python-SDK"
openapi-generator-cli generate -i ./openapi.yaml -g python -o ./generated/python/ -t ./templates/openapi-generator/python --git-repo-id=${GIT_REPO_ID} --git-user-id=${GIT_USER_ID} --release-note=${RELEASE_NOTE} --http-user-agent=${USER_AGENT} --additional-properties=packageVersion=${SDK_VERSION},packageName=${PACKAGE_NAME},packageUrl=${PACKAGE_URL},projectName=${PROJECT_NAME},infoName=${INFO_NAME}
- id: move-custom-files-to-repo
name: Move custom files to repo
run: |
mv ./backup/python/fattureincloud_python_sdk/filter ./generated/python/fattureincloud_python_sdk/
mv ./backup/python/fattureincloud_python_sdk/oauth2 ./generated/python/fattureincloud_python_sdk/
- id: generate-additional-files
name: Generate Additional files
run: |
node ./scripts/generate-scopes.js python
- id: format
name: Format files
run: |
pip install black
black ./generated/python/
- id: create-pr
name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
path: ./generated/python
branch: "devel-${{ env.sdk_version }}"
token: "${{ secrets.FATTUREINCLOUD_BOT_TOKEN }}"
delete-branch: true
base: master
commit-message: "chore: bumping version to ${{ env.sdk_version }}"
title: "Updating SDK to ${{ env.sdk_version }}"
body: "New SDK verson ${{ env.sdk_version }} generated by Github Action from OpenAPI Spec ${{ env.openapi_version }}"