CI config changes are low-risk and don't affect business code. Direct push eliminates the need to manually validate 50+ PRs. Changes: - Push commits directly to target branches (no AGit PR flow) - Simplified commit message: '[CI] sync config from odoo-elabore-ci' - Update README to reflect direct push behavior
231 lines
7.5 KiB
YAML
231 lines
7.5 KiB
YAML
name: Deploy CI Config
|
|
run-name: "${{ gitea.actor }} deploying config [${{ inputs.version }}] to [${{ inputs.repos || 'all repos' }}]${{ inputs.dry_run && ' (DRY-RUN)' || '' }}"
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
version:
|
|
description: 'Odoo version to deploy'
|
|
required: true
|
|
type: choice
|
|
options:
|
|
- all
|
|
- '16.0'
|
|
- '18.0'
|
|
default: 'all'
|
|
repos:
|
|
description: 'Target repos (comma-separated, empty = all *-addons/*-tools)'
|
|
required: false
|
|
type: string
|
|
default: ''
|
|
dry_run:
|
|
description: 'Dry run (preview changes without creating PRs)'
|
|
required: true
|
|
type: boolean
|
|
default: true
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- name: Show deployment parameters
|
|
run: |
|
|
echo "============================================"
|
|
echo " DEPLOYMENT PARAMETERS"
|
|
echo "============================================"
|
|
echo "Version: ${{ inputs.version }}"
|
|
echo "Repos: ${{ inputs.repos || '(all)' }}"
|
|
echo "Dry-run: ${{ inputs.dry_run }}"
|
|
echo "============================================"
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y jq git rsync
|
|
|
|
- name: Checkout config repository
|
|
env:
|
|
GITEA_SERVER: "https://git.elabore.coop"
|
|
ORG_NAME: "Elabore"
|
|
CONFIG_REPO: "odoo-elabore-ci"
|
|
run: |
|
|
git clone --single-branch --branch main "${GITEA_SERVER}/${ORG_NAME}/${CONFIG_REPO}.git" config-repo
|
|
|
|
- name: Determine versions to deploy
|
|
run: |
|
|
# List all available versions
|
|
ALL_VERSIONS=$(ls -d config-repo/config/*/ | xargs -n1 basename | grep -v common | tr '\n' ' ')
|
|
echo "Available versions: $ALL_VERSIONS"
|
|
|
|
# Filter based on input
|
|
if [ "${{ inputs.version }}" = "all" ]; then
|
|
VERSIONS="$ALL_VERSIONS"
|
|
else
|
|
VERSIONS="${{ inputs.version }}"
|
|
fi
|
|
|
|
echo "Versions to deploy: $VERSIONS"
|
|
echo "VERSIONS=$VERSIONS" >> $GITEA_ENV
|
|
|
|
- name: Build target repos list
|
|
env:
|
|
GITEA_SERVER: "https://git.elabore.coop"
|
|
ORG_NAME: "Elabore"
|
|
GITEA_TOKEN: ${{ secrets.ELABORE_BOT_TOKEN }}
|
|
INPUT_REPOS: ${{ inputs.repos }}
|
|
run: |
|
|
REPO_LIST="repos.txt"
|
|
> $REPO_LIST
|
|
|
|
if [ -n "$INPUT_REPOS" ]; then
|
|
# User specified repos - use them directly
|
|
echo "Using user-specified repos: $INPUT_REPOS"
|
|
echo "$INPUT_REPOS" | tr ',' '\n' | sed 's/^ *//;s/ *$//' > $REPO_LIST
|
|
else
|
|
# Fetch all repos from organization
|
|
page=1
|
|
per_page=50
|
|
while true; do
|
|
echo "Fetching page $page"
|
|
response=$(curl -s -H "Authorization: token $GITEA_TOKEN" \
|
|
"${GITEA_SERVER}/api/v1/orgs/${ORG_NAME}/repos?page=${page}&limit=${per_page}")
|
|
count=$(echo "$response" | jq 'length')
|
|
if [ "$count" -eq 0 ]; then
|
|
break
|
|
fi
|
|
# Filter for *-addons and *-tools repos only
|
|
echo "$response" | jq -r '.[].name | select(endswith("-addons") or endswith("-tools"))' >> $REPO_LIST
|
|
page=$((page + 1))
|
|
done
|
|
fi
|
|
|
|
echo ""
|
|
echo "Target repositories:"
|
|
cat $REPO_LIST
|
|
echo ""
|
|
echo "Total: $(wc -l < $REPO_LIST) repos"
|
|
|
|
- name: Deploy config to repos
|
|
env:
|
|
GITEA_SERVER: "git.elabore.coop"
|
|
ORG_NAME: "Elabore"
|
|
CONFIG_REPO: "odoo-elabore-ci"
|
|
GITEA_TOKEN: ${{ secrets.ELABORE_BOT_TOKEN }}
|
|
VERSIONS: ${{ env.VERSIONS }}
|
|
DRY_RUN: ${{ inputs.dry_run }}
|
|
run: |
|
|
REPO_LIST="repos.txt"
|
|
SUMMARY_FILE="deployment_summary.txt"
|
|
> $SUMMARY_FILE
|
|
|
|
pr_created=0
|
|
pr_skipped_no_changes=0
|
|
pr_skipped_no_branch=0
|
|
errors=0
|
|
|
|
while read repo; do
|
|
# Skip empty lines
|
|
[ -z "$repo" ] && continue
|
|
|
|
# Skip the config repo itself
|
|
if [ "$repo" = "$CONFIG_REPO" ]; then
|
|
echo "⏭️ Skipping config repo: $repo"
|
|
continue
|
|
fi
|
|
|
|
echo ""
|
|
echo "=========================================="
|
|
echo "📦 Processing: $repo"
|
|
echo "=========================================="
|
|
|
|
for VERSION in $VERSIONS; do
|
|
echo ""
|
|
echo "--- Version $VERSION ---"
|
|
|
|
# Try to clone the target repo at this version branch
|
|
if ! git clone --quiet --single-branch --branch "$VERSION" "https://elabore_bot:${GITEA_TOKEN}@${GITEA_SERVER}/${ORG_NAME}/${repo}.git" "target-${repo}-${VERSION}" 2>/dev/null; then
|
|
echo "⚠️ Branch $VERSION does not exist in $repo"
|
|
pr_skipped_no_branch=$((pr_skipped_no_branch + 1))
|
|
continue
|
|
fi
|
|
|
|
cd "target-${repo}-${VERSION}" || { echo "❌ Failed to enter directory"; errors=$((errors + 1)); continue; }
|
|
|
|
# Copy common files first
|
|
rsync -a ../config-repo/config/common/ .
|
|
|
|
# Copy version-specific files (overwrites common if conflict)
|
|
rsync -a ../config-repo/config/${VERSION}/ .
|
|
|
|
git add -N .
|
|
|
|
# Check for changes
|
|
if git diff --quiet; then
|
|
echo "✅ No changes needed for $repo:$VERSION"
|
|
pr_skipped_no_changes=$((pr_skipped_no_changes + 1))
|
|
else
|
|
echo "📝 Changes detected for $repo:$VERSION"
|
|
echo ""
|
|
echo "Changed files:"
|
|
git diff --stat
|
|
echo ""
|
|
|
|
if [ "$DRY_RUN" = "true" ]; then
|
|
echo "🔍 DRY-RUN: Would push to $repo:$VERSION"
|
|
echo "[DRY-RUN] $repo:$VERSION - would be updated" >> ../$SUMMARY_FILE
|
|
else
|
|
echo "🚀 Pushing to $repo:$VERSION"
|
|
git config user.name "elabore_bot"
|
|
git config user.email "gitea.bot@elabore.coop"
|
|
git add .
|
|
git commit -m "[CI] sync config from ${CONFIG_REPO}"
|
|
|
|
if git push --quiet origin HEAD:"${VERSION}"; then
|
|
echo "✅ Pushed to $repo:$VERSION"
|
|
echo "[PUSHED] $repo:$VERSION" >> ../$SUMMARY_FILE
|
|
pr_created=$((pr_created + 1))
|
|
else
|
|
echo "❌ Push failed for $repo:$VERSION"
|
|
echo "[ERROR] $repo:$VERSION - Push failed" >> ../$SUMMARY_FILE
|
|
errors=$((errors + 1))
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
cd ..
|
|
rm -rf "target-${repo}-${VERSION}"
|
|
|
|
done
|
|
|
|
done < $REPO_LIST
|
|
|
|
echo ""
|
|
echo "============================================"
|
|
echo " DEPLOYMENT SUMMARY"
|
|
echo "============================================"
|
|
if [ "$DRY_RUN" = "true" ]; then
|
|
echo "Mode: DRY-RUN (no changes pushed)"
|
|
else
|
|
echo "Mode: LIVE (direct push to branches)"
|
|
fi
|
|
echo ""
|
|
echo "Branches updated: $pr_created"
|
|
echo "Skipped (no changes): $pr_skipped_no_changes"
|
|
echo "Skipped (branch missing): $pr_skipped_no_branch"
|
|
echo "Errors: $errors"
|
|
echo ""
|
|
|
|
if [ -s $SUMMARY_FILE ]; then
|
|
echo "Details:"
|
|
cat $SUMMARY_FILE
|
|
fi
|
|
|
|
echo "============================================"
|
|
|
|
# Exit with error if there were failures
|
|
if [ $errors -gt 0 ]; then
|
|
exit 1
|
|
fi
|