Repository navigation
Autogenerated Python SDK #229
Workflow file for this run
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
| name: Publish Python SDK to PyPI | |
| on: | |
| push: | |
| branches: | |
| - 'release-**' | |
| workflow_dispatch: | |
| inputs: | |
| from_branch: | |
| description: 'Source branch to publish from' | |
| required: true | |
| default: 'release-main' | |
| type: string | |
| to_branch: | |
| description: 'Target branch to merge to' | |
| required: true | |
| default: 'github-action-test' | |
| type: string | |
| should_publish_to_pypi: | |
| description: 'Whether to publish package to PyPI' | |
| required: false | |
| default: false | |
| type: boolean | |
| should_create_and_merge_pr: | |
| description: 'Whether to create and merge pull request' | |
| required: false | |
| default: false | |
| type: boolean | |
| # Permissions to create PR, to write changes, to use PyPi auth | |
| permissions: | |
| pull-requests: write | |
| contents: write | |
| id-token: write | |
| jobs: | |
| publish_package: | |
| name: Publish Python SDK to PyPI | |
| runs-on: ubuntu-latest | |
| env: | |
| SOURCE_BRANCH: ${{ github.event.inputs.from_branch || github.ref_name }} | |
| TARGET_BRANCH: ${{ github.event.inputs.to_branch || 'main' }} | |
| strategy: | |
| matrix: | |
| package_folder: | |
| - visier_platform_sdk | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ env.SOURCE_BRANCH }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install setuptools wheel twine build | |
| - name: Build package | |
| run: | | |
| cd "src/${{ matrix.package_folder }}" | |
| python -m build --outdir ./dist | |
| - name: Publish PyPi package | |
| if: github.event_name == 'workflow_dispatch' && github.event.inputs.should_publish_to_pypi == 'true' || github.event_name == 'push' | |
| uses: pypa/gh-action-pypi-publish@v1.13.0 | |
| with: | |
| packages-dir: "src/${{ matrix.package_folder }}/dist" | |
| create_and_merge_pr: | |
| needs: publish_package | |
| if: needs.publish_package.result == 'success' && (github.event_name == 'workflow_dispatch' && github.event.inputs.should_create_and_merge_pr == 'true' || github.event_name == 'push') | |
| name: Merge PR | |
| runs-on: ubuntu-latest | |
| env: | |
| SOURCE_BRANCH: ${{ github.event.inputs.from_branch || github.ref_name }} | |
| TARGET_BRANCH: ${{ github.event.inputs.to_branch || 'main' }} | |
| steps: | |
| - name: Check out before merge | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ env.TARGET_BRANCH }} | |
| - name: Create a token | |
| id: create-token | |
| uses: actions/create-github-app-token@v2 | |
| with: | |
| app-id: ${{ secrets.APP_ID }} | |
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
| owner: ${{ github.repository_owner }} | |
| repositories: python-sdk | |
| - name: Create Pull Request | |
| id: create_pr | |
| env: | |
| GITHUB_TOKEN: ${{ steps.create-token.outputs.token }} | |
| run: | | |
| pr_output=$(gh pr create \ | |
| --title "Auto-generated SDK from ${{ env.SOURCE_BRANCH }}" \ | |
| --body "This PR includes the autogenerated SDKs from branch ${{ env.SOURCE_BRANCH }}." \ | |
| --head "${{ env.SOURCE_BRANCH }}" \ | |
| --base "${{ env.TARGET_BRANCH }}") | |
| pr_number=$(echo "$pr_output" | grep -oE '[0-9]+$') | |
| echo "Pull Request #$pr_number created successfully." | |
| echo "pr_number=$pr_number" >> $GITHUB_OUTPUT | |
| - name: Merge Pull Request | |
| env: | |
| GITHUB_TOKEN: ${{ steps.create-token.outputs.token }} | |
| run: | | |
| gh pr merge ${{ steps.create_pr.outputs.pr_number }} --merge --delete-branch |