[IMP] add action to deploy config on all Elabore's Odoo addons repos
This commit is contained in:
124
.gitea/workflows/deploy-config.yml
Normal file
124
.gitea/workflows/deploy-config.yml
Normal file
@@ -0,0 +1,124 @@
|
||||
name: Sync Config to All Odoo Repositories
|
||||
run-name: ${{ gitea.actor }} is deploying new pre-commit config 🚀
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 16.0
|
||||
- 18.0
|
||||
paths:
|
||||
- config/**
|
||||
|
||||
jobs:
|
||||
sync:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y jq git rsync
|
||||
|
||||
- name: Determine source branch
|
||||
id: branch_vars
|
||||
run: |
|
||||
# Set SOURCE_BRANCH to the branch/tag that triggered this workflow
|
||||
echo "SOURCE_BRANCH=${GITEA_REF_NAME}" >> $GITEA_ENV
|
||||
env:
|
||||
GITEA_REF_NAME: ${{ gitea.ref_name }}
|
||||
|
||||
- name: Checkout config repository
|
||||
env:
|
||||
GITEA_SERVER: "https://git.elabore.coop" # Base URL of Gitea instance, e.g. https://gitea.example.com
|
||||
ORG_NAME: "Elabore"
|
||||
CONFIG_REPO: "odoo-elabore-ci"
|
||||
SOURCE_BRANCH: ${{ env.SOURCE_BRANCH }}
|
||||
run: |
|
||||
echo "test"
|
||||
# Clone the config repo to local directory
|
||||
git clone --single-branch --branch "$SOURCE_BRANCH" "${GITEA_SERVER}/${ORG_NAME}/${CONFIG_REPO}.git" config-repo
|
||||
# Path where configs are stored in config repo
|
||||
CONFIG_PATH="config"
|
||||
|
||||
- name: Get list of all repos in organization
|
||||
env:
|
||||
GITEA_SERVER: "https://git.elabore.coop"
|
||||
ORG_NAME: "Elabore"
|
||||
GITEA_TOKEN: ${{ secrets.ELABORE_ORG_TOKEN }} # token must have read + write permissions on all repos
|
||||
run: |
|
||||
page=1
|
||||
per_page=50
|
||||
REPO_LIST="repos.txt"
|
||||
> $REPO_LIST
|
||||
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
|
||||
# Append each repo name to file
|
||||
echo "$response" | jq -r '.[].name' >> $REPO_LIST
|
||||
page=$((page + 1))
|
||||
done
|
||||
echo "Repositories found:"
|
||||
cat $REPO_LIST
|
||||
|
||||
- name: Sync config to each repo
|
||||
env:
|
||||
GITEA_SERVER: "https://git.elabore.coop"
|
||||
ORG_NAME: "Elabore"
|
||||
SOURCE_BRANCH: ${{ env.SOURCE_BRANCH }}
|
||||
CONFIG_REPO: "odoo-elabore-ci"
|
||||
GITEA_TOKEN: ${{ secrets.ELABORE_ORG_TOKEN }}
|
||||
CONFIG_PATH: "config"
|
||||
run: |
|
||||
REPO_LIST="repos.txt"
|
||||
while read repo; do
|
||||
# Skip the config repo itself
|
||||
if [ "$repo" = "$CONFIG_REPO" ]; then
|
||||
echo "Skipping config repo: $repo"
|
||||
continue
|
||||
fi
|
||||
|
||||
# XXXSte - work only on event-tools for test purposes - TO BE DELETER
|
||||
if [ "$repo" != "event-tools" ]; then
|
||||
echo "Skipping config repo: $repo"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Skip repos not matching suffixes -addons and -tools
|
||||
if ! [[ "$repo" == *-addons ]] && ! [[ "$repo" == *-tools ]]; then
|
||||
echo "Skipping $repo (does not end with -addons or -tools)"
|
||||
continue
|
||||
fi
|
||||
|
||||
echo "Processing repo: $repo"
|
||||
|
||||
# Clone the target repo
|
||||
git clone --single-branch --branch "$SOURCE_BRANCH" "${GITEA_SERVER}/${ORG_NAME}/${repo}.git" target-$repo
|
||||
cd target-$repo || { echo "Failed to enter target-$repo"; exit 1; }
|
||||
|
||||
# Copy files from config repo
|
||||
rsync -av --delete ../config-repo/$CONFIG_PATH/ .
|
||||
|
||||
# If there are no changes, skip
|
||||
if git diff --quiet; then
|
||||
echo "No changes for $repo"
|
||||
else
|
||||
echo "Changes detected for $repo – committing & pushing"
|
||||
# Set user identity for commit
|
||||
git config user.name "config-sync-bot"
|
||||
git config user.email "maintenance@elabore.coop"
|
||||
|
||||
git add .
|
||||
git commit -m "Sync config from ${CONFIG_REPO}:${SOURCE_BRANCH}"
|
||||
git push origin "$SOURCE_BRANCH"
|
||||
fi
|
||||
|
||||
cd .. # go back to workflow root
|
||||
# Clean up clone
|
||||
rm -rf target-$repo
|
||||
|
||||
done < $REPO_LIST
|
Reference in New Issue
Block a user