Skip to content

Commit 9349a39

Browse files
committed
Update submodule listener to support multiple branches!
1 parent 8f0ac1d commit 9349a39

4 files changed

Lines changed: 30 additions & 20 deletions

File tree

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,44 @@
1-
name: Update Submodules
2-
3-
permissions:
4-
contents: write
5-
6-
on:
7-
repository_dispatch:
8-
types: [update_submodule]
9-
101
jobs:
112
update:
123
runs-on: ubuntu-latest
134
steps:
14-
- name: Checkout meta repo at main
5+
- name: Checkout root repo (Default Branch)
156
uses: actions/checkout@v3
167
with:
17-
ref: latest
8+
# Start by checking out the default branch to ensure we have a base
9+
ref: ${{ github.event.repository.default_branch }}
1810
token: ${{ secrets.GITHUB_TOKEN }}
19-
submodules: false # Avoid broken recursive update
2011
fetch-depth: 0
21-
# persist-credentials: false
12+
13+
- name: Switch to target branch (Create if missing)
14+
run: |
15+
TARGET_BRANCH="${{ github.event.client_payload.branch }}"
16+
17+
# Check if the branch exists on the remote
18+
if git ls-remote --heads origin "$TARGET_BRANCH" | grep -q "$TARGET_BRANCH"; then
19+
echo "Branch $TARGET_BRANCH exists. Switching..."
20+
git checkout "$TARGET_BRANCH"
21+
else
22+
echo "Branch $TARGET_BRANCH not found. Creating from default..."
23+
git checkout -b "$TARGET_BRANCH"
24+
fi
2225
2326
- name: Sync and update submodules
2427
run: |
2528
git submodule sync
2629
git submodule update --init --remote
2730
28-
- name: Commit submodule changes
31+
- name: Commit and Push
2932
run: |
30-
git add .
3133
git config user.name "GitHub Action"
3234
git config user.email "action@github.com"
33-
git diff --cached --quiet || git commit -m "Update submodules from ${{ github.event.client_payload.repo }}"
34-
git push
35+
git add .
36+
37+
# Only commit and push if there are changes
38+
if ! git diff --cached --quiet; then
39+
git commit -m "Update submodules from ${{ github.event.client_payload.repo }} on branch ${{ github.event.client_payload.branch }}"
40+
# Use -u to set up tracking for newly created branches
41+
git push -u origin HEAD:"${{ github.event.client_payload.branch }}"
42+
else
43+
echo "No changes to commit."
44+
fi

0 commit comments

Comments
 (0)