You've already forked go-template-container-webserver
63 lines
1.5 KiB
Bash
Executable File
63 lines
1.5 KiB
Bash
Executable File
#!/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!"
|