Skip to content

Commit 0654994

Browse files
authored
Fix github action for binding generation (#546)
* better pr detection * Update generate-bindings.yml * branch name handling in workflow * more echos!
1 parent d359fb9 commit 0654994

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

.github/workflows/generate-bindings.yml

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,40 @@ jobs:
8888
cd $GITHUB_WORKSPACE
8989
git config --global --add safe.directory $GITHUB_WORKSPACE
9090
if git diff --exit-code; then
91+
echo "No changes detected, skipping PR creation"
9192
exit 0
9293
fi
94+
9395
git config --global user.email "[email protected]"
9496
git config --global user.name "GitHub Action"
9597
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
96-
git remote update origin
97-
CREATE_PR=0
98-
if ! git checkout update-bindings-${{ matrix.ros_distribution }}; then
98+
git fetch origin
99+
100+
echo "Github env set and origin is fetched! Now checking if PR exists.."
101+
102+
BRANCH_NAME="update-bindings-${{ matrix.ros_distribution }}"
103+
if gh pr list --head "$BRANCH_NAME" --state open --json number --jq length | grep -q '^0$'; then
104+
echo "No existing PR found, will create new one"
99105
CREATE_PR=1
100-
git checkout -b update-bindings-${{ matrix.ros_distribution }}
106+
else
107+
echo "PR already exists, will update it"
108+
CREATE_PR=0
101109
fi
110+
102111
git add rclrs/src/rcl_bindings_generated_${{ matrix.ros_distribution }}.rs
103112
git commit -m "Regenerate bindings for ${{ matrix.ros_distribution }}"
104-
git fetch origin update-bindings-${{ matrix.ros_distribution }}
105-
git rebase origin/update-bindings-${{ matrix.ros_distribution }}
106-
git push -u origin update-bindings-${{ matrix.ros_distribution }}
113+
114+
git push -f origin HEAD:refs/heads/$BRANCH_NAME
115+
107116
if [ $CREATE_PR -eq 1 ]; then
108-
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 }}."
117+
gh pr create \
118+
--base main \
119+
--head "$BRANCH_NAME" \
120+
--title "Regenerate bindings for ${{ matrix.ros_distribution }}" \
121+
--body "This PR regenerates the bindings for ${{ matrix.ros_distribution }}."
122+
echo "Created new PR!"
123+
else
124+
echo "PR already exists and has been updated with new commit"
109125
fi
110126
env:
111127
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)