diff --git a/.github/workflows/generate-bindings.yml b/.github/workflows/generate-bindings.yml index b3a712eb..6bf08b19 100644 --- a/.github/workflows/generate-bindings.yml +++ b/.github/workflows/generate-bindings.yml @@ -88,24 +88,40 @@ jobs: cd $GITHUB_WORKSPACE git config --global --add safe.directory $GITHUB_WORKSPACE if git diff --exit-code; then + echo "No changes detected, skipping PR creation" exit 0 fi + git config --global user.email "action@github.com" git config --global user.name "GitHub Action" git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} - git remote update origin - CREATE_PR=0 - if ! git checkout update-bindings-${{ matrix.ros_distribution }}; then + git fetch origin + + echo "Github env set and origin is fetched! Now checking if PR exists.." + + BRANCH_NAME="update-bindings-${{ matrix.ros_distribution }}" + if gh pr list --head "$BRANCH_NAME" --state open --json number --jq length | grep -q '^0$'; then + echo "No existing PR found, will create new one" CREATE_PR=1 - git checkout -b update-bindings-${{ matrix.ros_distribution }} + else + echo "PR already exists, will update it" + CREATE_PR=0 fi + git add rclrs/src/rcl_bindings_generated_${{ matrix.ros_distribution }}.rs git commit -m "Regenerate bindings for ${{ matrix.ros_distribution }}" - git fetch origin update-bindings-${{ matrix.ros_distribution }} - git rebase origin/update-bindings-${{ matrix.ros_distribution }} - git push -u origin update-bindings-${{ matrix.ros_distribution }} + + git push -f origin HEAD:refs/heads/$BRANCH_NAME + if [ $CREATE_PR -eq 1 ]; then - gh pr create --base main --head update-bindings-${{ matrix.ros_distribution }} --title "Regenerate bindings for ${{ matrix.ros_distribution }}" --body "This PR regenerates the bindings for ${{ matrix.ros_distribution }}." + gh pr create \ + --base main \ + --head "$BRANCH_NAME" \ + --title "Regenerate bindings for ${{ matrix.ros_distribution }}" \ + --body "This PR regenerates the bindings for ${{ matrix.ros_distribution }}." + echo "Created new PR!" + else + echo "PR already exists and has been updated with new commit" fi env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}