|
| 1 | +name: Dev Submodule Sync |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [ main ] |
| 6 | + push: |
| 7 | + branches: [ main ] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + verify-dev-submodule: |
| 14 | + if: github.event_name == 'pull_request' |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout (no submodules) |
| 18 | + uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
| 21 | + - name: Read submodule config |
| 22 | + id: cfg |
| 23 | + run: | |
| 24 | + url=$(git config -f .gitmodules --get submodule.dev.url) |
| 25 | + branch=$(git config -f .gitmodules --get submodule.dev.branch || echo main) |
| 26 | + echo "url=$url" >> $GITHUB_OUTPUT |
| 27 | + echo "branch=$branch" >> $GITHUB_OUTPUT |
| 28 | + - name: Get recorded submodule SHA |
| 29 | + id: recorded |
| 30 | + run: | |
| 31 | + rec=$(git ls-tree HEAD dev | awk '{print $3}') |
| 32 | + echo "sha=$rec" >> $GITHUB_OUTPUT |
| 33 | + - name: Get latest upstream SHA for dev submodule |
| 34 | + id: upstream |
| 35 | + run: | |
| 36 | + set -e |
| 37 | + url="${{ steps.cfg.outputs.url }}" |
| 38 | + branch="${{ steps.cfg.outputs.branch }}" |
| 39 | + latest=$(git ls-remote "$url" "refs/heads/$branch" | awk '{print $1}') |
| 40 | + echo "sha=$latest" >> $GITHUB_OUTPUT |
| 41 | + - name: Compare and fail if behind |
| 42 | + run: | |
| 43 | + echo "Recorded: ${{ steps.recorded.outputs.sha }}" |
| 44 | + echo "Upstream: ${{ steps.upstream.outputs.sha }}" |
| 45 | + if [ -z "${{ steps.upstream.outputs.sha }}" ]; then |
| 46 | + echo "Could not resolve upstream dev submodule SHA. Skipping check."; |
| 47 | + exit 0; |
| 48 | + fi |
| 49 | + if [ "${{ steps.recorded.outputs.sha }}" != "${{ steps.upstream.outputs.sha }}" ]; then |
| 50 | + echo "::error::dev/ submodule is behind. Please bump dev to ${{ steps.upstream.outputs.sha }} (branch ${{ steps.cfg.outputs.branch }})."; |
| 51 | + echo "Tip: git -C dev fetch origin && git -C dev checkout ${{ steps.cfg.outputs.branch }} && git add dev && git commit -m 'chore(submodule): bump dev'"; |
| 52 | + exit 1; |
| 53 | + fi |
| 54 | + echo "dev/ submodule is up-to-date. ✅" |
| 55 | +
|
| 56 | + sync-dev-submodule-on-main: |
| 57 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 58 | + runs-on: ubuntu-latest |
| 59 | + steps: |
| 60 | + - name: Checkout with token |
| 61 | + uses: actions/checkout@v4 |
| 62 | + with: |
| 63 | + fetch-depth: 0 |
| 64 | + - name: Initialize and update submodule to latest configured branch |
| 65 | + run: | |
| 66 | + git submodule sync --recursive |
| 67 | + git submodule update --init --remote dev |
| 68 | + - name: Commit submodule pointer if changed |
| 69 | + run: | |
| 70 | + set -e |
| 71 | + if ! git diff --quiet -- dev; then |
| 72 | + new_sha=$(git ls-tree HEAD dev | awk '{print $3}') |
| 73 | + # The above SHA is from HEAD; we need the updated working tree's target |
| 74 | + # Refresh index and compute the updated SHA from the working tree |
| 75 | + git add dev |
| 76 | + new_sha=$(git ls-tree :dev | awk '{print $3}') || true |
| 77 | + git config user.name "github-actions[bot]" |
| 78 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 79 | + git commit -m "chore(submodule): bump dev to latest" |
| 80 | + git push |
| 81 | + else |
| 82 | + echo "No submodule changes to commit." |
| 83 | + fi |
0 commit comments