From 50a4f7725d04a4fe11ff4a2e7ad57c24481b4b20 Mon Sep 17 00:00:00 2001 From: forbes-0023 Date: Tue, 17 Feb 2026 08:43:41 -0600 Subject: [PATCH] ci: add workflow to auto-update downstream submodule repos Opens PRs in kindred/silo-mod and kindred/silo-calc when main is pushed, updating their silo-client submodule pointer to the new SHA. Includes duplicate PR detection and no-op skip when already current. --- .gitea/workflows/notify-dependents.yml | 92 ++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 .gitea/workflows/notify-dependents.yml diff --git a/.gitea/workflows/notify-dependents.yml b/.gitea/workflows/notify-dependents.yml new file mode 100644 index 0000000..dd07edd --- /dev/null +++ b/.gitea/workflows/notify-dependents.yml @@ -0,0 +1,92 @@ +name: Update Downstream Submodules + +on: + push: + branches: [main] + +jobs: + update-dependents: + runs-on: ubuntu-latest + strategy: + matrix: + include: + - downstream: kindred/silo-mod + submodule_path: silo-client + - downstream: kindred/silo-calc + submodule_path: silo-client + steps: + - name: Update submodule in ${{ matrix.downstream }} + env: + GITEA_TOKEN: ${{ secrets.BOT_TOKEN }} + GITEA_URL: https://git.kindred-systems.com + DOWNSTREAM: ${{ matrix.downstream }} + SUBMODULE_PATH: ${{ matrix.submodule_path }} + UPSTREAM_SHA: ${{ github.sha }} + UPSTREAM_REPO: ${{ github.repository }} + run: | + set -euo pipefail + + SUBMODULE_NAME=$(basename "$SUBMODULE_PATH") + BRANCH="auto/update-${SUBMODULE_NAME}-${UPSTREAM_SHA:0:8}" + API="$GITEA_URL/api/v1" + AUTH="Authorization: token $GITEA_TOKEN" + + # Get default branch + DEFAULT_BRANCH=$(curl -sf -H "$AUTH" "$API/repos/$DOWNSTREAM" | jq -r .default_branch) + + # Check for existing open PRs for this submodule to avoid duplicates + EXISTING=$(curl -sf -H "$AUTH" \ + "$API/repos/$DOWNSTREAM/pulls?state=open&limit=50" \ + | jq -r "[.[] | select(.head.label | startswith(\"auto/update-${SUBMODULE_NAME}-\"))] | length") + + if [ "$EXISTING" -gt 0 ]; then + echo "Open PR already exists for $SUBMODULE_NAME update in $DOWNSTREAM — skipping" + exit 0 + fi + + # Create branch from default + curl -sf -X POST -H "$AUTH" -H "Content-Type: application/json" \ + "$API/repos/$DOWNSTREAM/branches" \ + -d "{\"new_branch_name\": \"$BRANCH\", \"old_branch_name\": \"$DEFAULT_BRANCH\"}" + + # Configure git auth + git config --global url."https://bot:${GITEA_TOKEN}@git.kindred-systems.com/".insteadOf "https://git.kindred-systems.com/" + git config --global user.name "kindred-bot" + git config --global user.email "bot@kindred-systems.com" + + # Clone downstream, update submodule, push + git clone --depth 1 -b "$BRANCH" \ + "$GITEA_URL/$DOWNSTREAM.git" downstream + cd downstream + + git submodule update --init "$SUBMODULE_PATH" + cd "$SUBMODULE_PATH" + git fetch origin main + git checkout "$UPSTREAM_SHA" + cd - > /dev/null + + git add "$SUBMODULE_PATH" + + # Only proceed if there are actual changes + if git diff --cached --quiet; then + echo "Submodule already at $UPSTREAM_SHA — nothing to do" + exit 0 + fi + + git commit -m "chore(deps): update ${SUBMODULE_NAME} to ${UPSTREAM_SHA:0:8} + + Upstream: $GITEA_URL/$UPSTREAM_REPO/commit/$UPSTREAM_SHA" + + git push origin "$BRANCH" + + # Create PR + curl -sf -X POST -H "$AUTH" -H "Content-Type: application/json" \ + "$API/repos/$DOWNSTREAM/pulls" \ + -d "{ + \"title\": \"chore(deps): update ${SUBMODULE_NAME} to ${UPSTREAM_SHA:0:8}\", + \"body\": \"Automated submodule update.\\n\\nUpstream commit: $GITEA_URL/$UPSTREAM_REPO/commit/$UPSTREAM_SHA\\nUpstream repo: $UPSTREAM_REPO\\nNew SHA: \`$UPSTREAM_SHA\`\", + \"head\": \"$BRANCH\", + \"base\": \"$DEFAULT_BRANCH\" + }" + + echo "PR created in $DOWNSTREAM" -- 2.49.1