diff --git a/.gitea/workflows/deploy-config.yml b/.gitea/workflows/deploy-config.yml index 2258d28..a27e058 100644 --- a/.gitea/workflows/deploy-config.yml +++ b/.gitea/workflows/deploy-config.yml @@ -3,7 +3,7 @@ run-name: ${{ gitea.actor }} is deploying new pre-commit config 🚀 on: push: branches: - - 16.0 + - main jobs: sync: @@ -16,31 +16,27 @@ jobs: 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 + GITEA_SERVER: "https://git.elabore.coop" 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" + git clone --single-branch --branch main "${GITEA_SERVER}/${ORG_NAME}/${CONFIG_REPO}.git" config-repo + + - name: Detect available Odoo versions + id: versions + run: | + # List directories in config/ that are not "common" (these are version directories) + VERSIONS=$(ls -d config-repo/config/*/ | xargs -n1 basename | grep -v common | tr '\n' ' ') + echo "Available versions: $VERSIONS" + echo "VERSIONS=$VERSIONS" >> $GITEA_ENV - 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 + GITEA_TOKEN: ${{ secrets.ELABORE_BOT_TOKEN }} run: | page=1 per_page=50 @@ -54,9 +50,6 @@ jobs: 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 @@ -67,10 +60,9 @@ jobs: 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" + VERSIONS: ${{ env.VERSIONS }} run: | REPO_LIST="repos.txt" while read repo; do @@ -86,41 +78,58 @@ jobs: continue fi + echo "==========================================" echo "Processing repo: $repo" + echo "==========================================" - # 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; } + # Try each Odoo version + for VERSION in $VERSIONS; do + echo "--- Trying version $VERSION for $repo ---" - # Copy files from config repo - echo "Copy config to target repo $repo" - rsync -av ../config-repo/$CONFIG_PATH/ . - git add -N . + # 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, skipping" + continue + fi - # 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}" + cd "target-${repo}-${VERSION}" || { echo "Failed to enter target-${repo}-${VERSION}"; exit 1; } - 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 + # Copy common files first + echo "Copying common config files..." + rsync -av ../config-repo/config/common/ . - cd .. # go back to workflow root - # Clean up clone - echo "Cleaning up $repo" - rm -rf target-$repo - echo "Cleanup done for $repo" + # Copy version-specific files (overwrites common if conflict) + echo "Copying $VERSION-specific config files..." + rsync -av ../config-repo/config/${VERSION}/ . + + git add -N . + + # If there are no changes, skip + if git diff --quiet; then + echo "No changes for $repo on branch $VERSION" + else + echo "Changes detected for $repo:$VERSION – committing & pushing" + git config user.name "elabore_bot" + git config user.email "gitea.bot@elabore.coop" + git checkout -b "${VERSION}-config_deployment" + git add . + git commit -m "Sync config from ${CONFIG_REPO} (version ${VERSION})" + + echo "Pushing to $repo on branch $VERSION" + git push --quiet origin "${VERSION}-config_deployment":refs/for/"${VERSION}" \ + -o topic="${VERSION}-config_deployment" \ + -o title="Sync config from ${CONFIG_REPO} (version ${VERSION})" \ + -o force-push || { echo "Push failed for $repo:$VERSION"; exit 1; } + echo "Push done for $repo:$VERSION" + fi + + cd .. + rm -rf "target-${repo}-${VERSION}" + echo "Cleanup done for $repo:$VERSION" + + done echo "Moving to next repo" + echo "" done < $REPO_LIST diff --git a/config/.pre-commit-config.yaml b/config/16.0/.pre-commit-config.yaml similarity index 100% rename from config/.pre-commit-config.yaml rename to config/16.0/.pre-commit-config.yaml diff --git a/config/.pylintrc b/config/16.0/.pylintrc similarity index 100% rename from config/.pylintrc rename to config/16.0/.pylintrc diff --git a/config/.pylintrc-mandatory b/config/16.0/.pylintrc-mandatory similarity index 100% rename from config/.pylintrc-mandatory rename to config/16.0/.pylintrc-mandatory diff --git a/config/.ruff.toml b/config/16.0/.ruff.toml similarity index 100% rename from config/.ruff.toml rename to config/16.0/.ruff.toml diff --git a/config/.editorconfig b/config/common/.editorconfig similarity index 100% rename from config/.editorconfig rename to config/common/.editorconfig diff --git a/config/.eslintrc.yml b/config/common/.eslintrc.yml similarity index 100% rename from config/.eslintrc.yml rename to config/common/.eslintrc.yml diff --git a/config/.gitea/workflows/pre-commit.yml b/config/common/.gitea/workflows/pre-commit.yml similarity index 96% rename from config/.gitea/workflows/pre-commit.yml rename to config/common/.gitea/workflows/pre-commit.yml index 37d6128..dacf086 100644 --- a/config/.gitea/workflows/pre-commit.yml +++ b/config/common/.gitea/workflows/pre-commit.yml @@ -2,8 +2,6 @@ name: pre-commit on: pull_request: - branches: - - "16.0*" jobs: pre-commit: @@ -15,7 +13,7 @@ jobs: python-version: "3.11" - name: Get python version run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV - - uses: actions/cache@v4 + - uses: https://gitea.com/actions/cache@v3 with: path: ~/.cache/pre-commit key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} diff --git a/config/.prettierrc.yml b/config/common/.prettierrc.yml similarity index 100% rename from config/.prettierrc.yml rename to config/common/.prettierrc.yml