auto update workflow

This commit is contained in:
2025-12-17 10:00:38 +01:00
parent 1e82f16216
commit 3044f9cc24
3 changed files with 81 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
---
name: Update Child Repos
concurrency: 1
on:
push:
branches:
- main
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: chmod +x update.sh
- run: |
export GITEA_TOKEN=${{ secrets.GITEA_TOKEN }}
./update.sh

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.sql

62
update.sh Executable file
View File

@@ -0,0 +1,62 @@
#!/usr/bin/env bash
set -euo pipefail
N8N_HOST="https://n8n.bjphoster.com"
WEBHOOK_ID="7c3cf611-e700-4bc0-b108-7d6be458dae6"
WEBHOOK_URL="${N8N_HOST}/webhook/${WEBHOOK_ID}"
TEMPLATE_REPO_DIR=$(pwd)
TEMPLATE_BRANCH="main"
COMMIT_ID=$(git log HEAD --oneline | awk '{print $1}' | head -n1)
COMMIT_MESSAGE="Template updates (commit: $COMMIT_ID)"
echo "Fetching repository list from ${WEBHOOK_URL}..."
JSON_RESPONSE=$(curl -s -f "${WEBHOOK_URL}")
echo "Parsing repository URLs..."
CLONE_URLS=$(echo "${JSON_RESPONSE}" | jq -r '.clone_url[]?')
if [ -z "${CLONE_URLS}" ]; then
echo "Error: No clone_url found in response or array is empty"
echo "Response: ${JSON_RESPONSE}"
exit 1
fi
while IFS= read -r clone_url; do
if [ -z "${clone_url}" ]; then
continue
fi
echo ""
echo "Processing repository: ${clone_url}"
repo_name=$(basename "${clone_url}" .git)
git clone "${clone_url}" "${repo_name}"
pushd "${repo_name}"
TEMPLATE_REMOTE_NAME="template"
git remote add "${TEMPLATE_REMOTE_NAME}" "${TEMPLATE_REPO_DIR}"
git fetch "${TEMPLATE_REMOTE_NAME}" "${TEMPLATE_BRANCH}"
current_branch=$(git rev-parse --abbrev-ref HEAD)
if git merge "${TEMPLATE_REMOTE_NAME}/${TEMPLATE_BRANCH}" \
--no-edit \
--no-ff \
--message "${COMMIT_MESSAGE}"; then
echo "Template merge successful for ${repo_name}"
git push
else
echo "Warning: Merge conflicts detected in ${repo_name}"
popd
continue
fi
popd
done <<< "${CLONE_URLS}"
echo ""
echo "All repositories processed successfully!"