Merge pull request 'ci: add workflow to auto-update downstream submodule repos' (#17) from ci/submodule-notify into main
Reviewed-on: #17
This commit was merged in pull request #17.
This commit is contained in:
92
.gitea/workflows/notify-dependents.yml
Normal file
92
.gitea/workflows/notify-dependents.yml
Normal file
@@ -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"
|
||||
Reference in New Issue
Block a user