From 61af67058db58913a16679f71adaecd5345bcc47 Mon Sep 17 00:00:00 2001 From: "timur.malikov" Date: Mon, 8 Sep 2025 12:07:47 -0700 Subject: [PATCH 1/7] Updating github action to create and merge pull requests. --- .github/workflows/publish-sdk.yml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-sdk.yml b/.github/workflows/publish-sdk.yml index 3b106b1e62..5edea71c71 100644 --- a/.github/workflows/publish-sdk.yml +++ b/.github/workflows/publish-sdk.yml @@ -21,6 +21,11 @@ on: 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: @@ -63,20 +68,31 @@ jobs: create_and_merge_pr: needs: publish_package - if: needs.publish_package.result == 'success' && (github.event_name == 'workflow_dispatch' && github.event.inputs.from_branch != github.event.inputs.to_branch) + 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 + - name: Check out code uses: actions/checkout@v4 + with: + ref: ${{ env.SOURCE_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: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ steps.create-token.outputs.token }} run: | pr_output=$(gh pr create \ --title "Auto-generated SDK from ${{ env.SOURCE_BRANCH }}" \ @@ -89,6 +105,6 @@ jobs: - name: Merge Pull Request env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ steps.create-token.outputs.token }} run: | gh pr merge ${{ steps.create_pr.outputs.pr_number }} --merge --delete-branch \ No newline at end of file From 7f88844060f02bdf8b80faf6ee76e36be0787ecc Mon Sep 17 00:00:00 2001 From: "timur.malikov" Date: Mon, 8 Sep 2025 14:12:22 -0700 Subject: [PATCH 2/7] Added step to wait for Pull Request status. --- .github/workflows/publish-sdk.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/publish-sdk.yml b/.github/workflows/publish-sdk.yml index 5edea71c71..8b1e211417 100644 --- a/.github/workflows/publish-sdk.yml +++ b/.github/workflows/publish-sdk.yml @@ -103,6 +103,21 @@ jobs: echo "Pull Request #$pr_number created successfully." echo "pr_number=$pr_number" >> $GITHUB_OUTPUT + - name: Wait for PR to be ready + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + for i in {1..5}; do + if gh pr view ${{ steps.create_pr.outputs.pr_number }} --json mergeable,state --jq '.mergeable == true and .state == "OPEN"' | grep -q true; then + echo "PR is ready for merge" + exit 0 + fi + sleep 5 + done + + echo "ERROR: PR is not ready after 25 seconds" + exit 1 + - name: Merge Pull Request env: GITHUB_TOKEN: ${{ steps.create-token.outputs.token }} From 5952c06a1c64503d2aec9766cfa654c3e785f63e Mon Sep 17 00:00:00 2001 From: "timur.malikov" Date: Mon, 8 Sep 2025 14:19:03 -0700 Subject: [PATCH 3/7] Added logs for status check. --- .github/workflows/publish-sdk.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-sdk.yml b/.github/workflows/publish-sdk.yml index 8b1e211417..696f83e4ec 100644 --- a/.github/workflows/publish-sdk.yml +++ b/.github/workflows/publish-sdk.yml @@ -108,10 +108,18 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | for i in {1..5}; do - if gh pr view ${{ steps.create_pr.outputs.pr_number }} --json mergeable,state --jq '.mergeable == true and .state == "OPEN"' | grep -q true; then + echo "Checking PR status (attempt $i/5)..." + + # Get PR status details + pr_status=$(gh pr view ${{ steps.create_pr.outputs.pr_number }} --json mergeable,state,mergeStateStatus --jq '{mergeable: .mergeable, state: .state, mergeStateStatus: .mergeStateStatus}') + echo "PR Status: $pr_status" + + if echo "$pr_status" | jq '.mergeable == true and .state == "OPEN"' | grep -q true; then echo "PR is ready for merge" exit 0 fi + + echo "PR not ready, waiting 5 seconds..." sleep 5 done From 8002133703922f7eab30fe9a11973a933391a39d Mon Sep 17 00:00:00 2001 From: "timur.malikov" Date: Mon, 8 Sep 2025 14:26:38 -0700 Subject: [PATCH 4/7] Updated checkinf the status. --- .github/workflows/publish-sdk.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-sdk.yml b/.github/workflows/publish-sdk.yml index 696f83e4ec..2761875b36 100644 --- a/.github/workflows/publish-sdk.yml +++ b/.github/workflows/publish-sdk.yml @@ -114,7 +114,11 @@ jobs: pr_status=$(gh pr view ${{ steps.create_pr.outputs.pr_number }} --json mergeable,state,mergeStateStatus --jq '{mergeable: .mergeable, state: .state, mergeStateStatus: .mergeStateStatus}') echo "PR Status: $pr_status" - if echo "$pr_status" | jq '.mergeable == true and .state == "OPEN"' | grep -q true; then + # Extract values + mergeable=$(echo "$pr_status" | jq -r '.mergeable') + state=$(echo "$pr_status" | jq -r '.state') + + if [ "$mergeable" = "MERGEABLE" ] && [ "$state" = "OPEN" ]; then echo "PR is ready for merge" exit 0 fi From 3b12487f2371527a55912eb2e2d67d83d05da5f2 Mon Sep 17 00:00:00 2001 From: "timur.malikov" Date: Mon, 8 Sep 2025 14:29:54 -0700 Subject: [PATCH 5/7] Added debug logs for state. --- .github/workflows/publish-sdk.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish-sdk.yml b/.github/workflows/publish-sdk.yml index 2761875b36..2d15ab55eb 100644 --- a/.github/workflows/publish-sdk.yml +++ b/.github/workflows/publish-sdk.yml @@ -117,6 +117,7 @@ jobs: # Extract values mergeable=$(echo "$pr_status" | jq -r '.mergeable') state=$(echo "$pr_status" | jq -r '.state') + echo "Checking: mergeable=$mergeable, state=$state" if [ "$mergeable" = "MERGEABLE" ] && [ "$state" = "OPEN" ]; then echo "PR is ready for merge" From 3e61416835c461792632d5e14e4cc4cb09adf5ac Mon Sep 17 00:00:00 2001 From: "timur.malikov" Date: Mon, 8 Sep 2025 14:41:08 -0700 Subject: [PATCH 6/7] Fix for checking out the repo, before merging the PR. --- .github/workflows/publish-sdk.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish-sdk.yml b/.github/workflows/publish-sdk.yml index 2d15ab55eb..d2b615ee8b 100644 --- a/.github/workflows/publish-sdk.yml +++ b/.github/workflows/publish-sdk.yml @@ -62,7 +62,7 @@ jobs: - 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.12.4 + uses: pypa/gh-action-pypi-publish@v1.13.0 with: packages-dir: "src/${{ matrix.package_folder }}/dist" @@ -75,10 +75,8 @@ jobs: SOURCE_BRANCH: ${{ github.event.inputs.from_branch || github.ref_name }} TARGET_BRANCH: ${{ github.event.inputs.to_branch || 'main' }} steps: - - name: Check out code + - name: Check out before merge uses: actions/checkout@v4 - with: - ref: ${{ env.SOURCE_BRANCH }} - name: Create a token id: create-token @@ -117,7 +115,7 @@ jobs: # Extract values mergeable=$(echo "$pr_status" | jq -r '.mergeable') state=$(echo "$pr_status" | jq -r '.state') - echo "Checking: mergeable=$mergeable, state=$state" + echo "Extracted variables: mergeable=$mergeable, state=$state" if [ "$mergeable" = "MERGEABLE" ] && [ "$state" = "OPEN" ]; then echo "PR is ready for merge" From 83d9438db84637500991910b952c2c86ee7db4b6 Mon Sep 17 00:00:00 2001 From: "timur.malikov" Date: Mon, 8 Sep 2025 14:46:22 -0700 Subject: [PATCH 7/7] Remove redundant waiting for PR step. --- .github/workflows/publish-sdk.yml | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/.github/workflows/publish-sdk.yml b/.github/workflows/publish-sdk.yml index d2b615ee8b..b01987370b 100644 --- a/.github/workflows/publish-sdk.yml +++ b/.github/workflows/publish-sdk.yml @@ -101,34 +101,6 @@ jobs: echo "Pull Request #$pr_number created successfully." echo "pr_number=$pr_number" >> $GITHUB_OUTPUT - - name: Wait for PR to be ready - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - for i in {1..5}; do - echo "Checking PR status (attempt $i/5)..." - - # Get PR status details - pr_status=$(gh pr view ${{ steps.create_pr.outputs.pr_number }} --json mergeable,state,mergeStateStatus --jq '{mergeable: .mergeable, state: .state, mergeStateStatus: .mergeStateStatus}') - echo "PR Status: $pr_status" - - # Extract values - mergeable=$(echo "$pr_status" | jq -r '.mergeable') - state=$(echo "$pr_status" | jq -r '.state') - echo "Extracted variables: mergeable=$mergeable, state=$state" - - if [ "$mergeable" = "MERGEABLE" ] && [ "$state" = "OPEN" ]; then - echo "PR is ready for merge" - exit 0 - fi - - echo "PR not ready, waiting 5 seconds..." - sleep 5 - done - - echo "ERROR: PR is not ready after 25 seconds" - exit 1 - - name: Merge Pull Request env: GITHUB_TOKEN: ${{ steps.create-token.outputs.token }}