From 954e119083981bfd7202fb39e1a2944134a5c216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Sainl=C3=A9ger?= Date: Mon, 15 Sep 2025 18:46:41 +0200 Subject: [PATCH] [IMP] add action to deploy config on all Elabore's Odoo addons repos --- .gitea/workflows/deploy-config.yml | 126 ++++++++++++++++++ .editorconfig => config/.editorconfig | 0 .eslintrc.yml => config/.eslintrc.yml | 0 .../.gitea}/workflows/pre-commit.yml | 0 .../.pre-commit-config.yaml | 0 .prettierrc.yml => config/.prettierrc.yml | 0 .pylintrc => config/.pylintrc | 0 .../.pylintrc-mandatory | 0 .ruff.toml => config/.ruff.toml | 0 9 files changed, 126 insertions(+) create mode 100644 .gitea/workflows/deploy-config.yml rename .editorconfig => config/.editorconfig (100%) rename .eslintrc.yml => config/.eslintrc.yml (100%) rename {.gitea => config/.gitea}/workflows/pre-commit.yml (100%) rename .pre-commit-config.yaml => config/.pre-commit-config.yaml (100%) rename .prettierrc.yml => config/.prettierrc.yml (100%) rename .pylintrc => config/.pylintrc (100%) rename .pylintrc-mandatory => config/.pylintrc-mandatory (100%) rename .ruff.toml => config/.ruff.toml (100%) diff --git a/.gitea/workflows/deploy-config.yml b/.gitea/workflows/deploy-config.yml new file mode 100644 index 0000000..2258d28 --- /dev/null +++ b/.gitea/workflows/deploy-config.yml @@ -0,0 +1,126 @@ +name: Sync Config to All Odoo Repositories +run-name: ${{ gitea.actor }} is deploying new pre-commit config 🚀 +on: + push: + branches: + - 16.0 + +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: | + # 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_BOT_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=$response" + echo "$response" | jq . + 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: "git.elabore.coop" + ORG_NAME: "Elabore" + SOURCE_BRANCH: ${{ env.SOURCE_BRANCH }} + CONFIG_REPO: "odoo-elabore-ci" + GITEA_TOKEN: ${{ secrets.ELABORE_BOT_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 + + # 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 + echo "${GITEA_TOKEN}" + git clone --quiet --single-branch --branch "$SOURCE_BRANCH" "https://elabore_bot:${GITEA_TOKEN}@${GITEA_SERVER}/${ORG_NAME}/${repo}.git" target-$repo || { echo "Failed to clone branch $SOURCE_BRANCH from $repo"; continue; } + cd target-$repo || { echo "Failed to enter target-$repo"; exit 1; } + + # Copy files from config repo + echo "Copy config to target repo $repo" + rsync -av ../config-repo/$CONFIG_PATH/ . + git add -N . + + # 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 "elabore_bot" + git config user.email "gitea.bot@elabore.coop" + git checkout -b "$SOURCE_BRANCH-config_deployment" + git add . + git commit -m "Sync config from ${CONFIG_REPO}:${SOURCE_BRANCH}" + + echo "Attempts to push to $repo on branch $SOURCE_BRANCH" + git push --quiet origin "$SOURCE_BRANCH-config_deployment":refs/for/"$SOURCE_BRANCH" -o topic="$SOURCE_BRANCH-config_deployment" -o title="Sync config from ${CONFIG_REPO}:${SOURCE_BRANCH}" -o force-push || { echo "Push failed for $repo"; exit 1; } + echo "Push done for $repo" + fi + + cd .. # go back to workflow root + # Clean up clone + echo "Cleaning up $repo" + rm -rf target-$repo + echo "Cleanup done for $repo" + + echo "Moving to next repo" + + done < $REPO_LIST diff --git a/.editorconfig b/config/.editorconfig similarity index 100% rename from .editorconfig rename to config/.editorconfig diff --git a/.eslintrc.yml b/config/.eslintrc.yml similarity index 100% rename from .eslintrc.yml rename to config/.eslintrc.yml diff --git a/.gitea/workflows/pre-commit.yml b/config/.gitea/workflows/pre-commit.yml similarity index 100% rename from .gitea/workflows/pre-commit.yml rename to config/.gitea/workflows/pre-commit.yml diff --git a/.pre-commit-config.yaml b/config/.pre-commit-config.yaml similarity index 100% rename from .pre-commit-config.yaml rename to config/.pre-commit-config.yaml diff --git a/.prettierrc.yml b/config/.prettierrc.yml similarity index 100% rename from .prettierrc.yml rename to config/.prettierrc.yml diff --git a/.pylintrc b/config/.pylintrc similarity index 100% rename from .pylintrc rename to config/.pylintrc diff --git a/.pylintrc-mandatory b/config/.pylintrc-mandatory similarity index 100% rename from .pylintrc-mandatory rename to config/.pylintrc-mandatory diff --git a/.ruff.toml b/config/.ruff.toml similarity index 100% rename from .ruff.toml rename to config/.ruff.toml