From c11a12aa45c004061809e51b5702c08dc97ba334 Mon Sep 17 00:00:00 2001 From: elabore_bot Date: Wed, 23 Sep 2026 13:13:00 +0000 Subject: [PATCH] [CI] sync config from odoo-elabore-ci --- .gitea/scripts/odoo-tests.sh | 42 ++++++++++++++++++ .gitea/workflows/pre-commit.yml | 10 ++--- .gitea/workflows/test.yml | 79 +++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 6 deletions(-) create mode 100755 .gitea/scripts/odoo-tests.sh create mode 100644 .gitea/workflows/test.yml diff --git a/.gitea/scripts/odoo-tests.sh b/.gitea/scripts/odoo-tests.sh new file mode 100755 index 0000000..56e1f97 --- /dev/null +++ b/.gitea/scripts/odoo-tests.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# +# Run the Python tests of the given Odoo modules. +# +# This script is meant to be executed *inside* an Elabore doodba image +# (docker.0k.io/mirror/odoo:rc_-ELABORE-LIGHT), with a +# PostgreSQL service reachable at $PGHOST. The modules under test are +# read from the current working directory (the checked-out repository), +# which is prepended to the addons path so that the PR's code takes +# precedence over the modules already baked in the image. +# +# Usage: odoo-tests.sh + +set -euo pipefail + +modules="${1:?usage: odoo-tests.sh }" + +export PGHOST=postgres +export PGUSER=odoo +export PGPASSWORD=odoopassword +export PGDATABASE="test_$(basename "$PWD" | tr '.-' '__')" +export WITHOUT_DEMO=all +export DB_FILTER='.*' + +# Generate /opt/odoo/auto/odoo.conf from the environment and wait for +# the database to accept connections. +/opt/odoo/common/entrypoint + +# Odoo test-tags format: "/module1,/module2" (one leading slash). +tags="/$(echo "$modules" | tr ',' ',/')" + +exec odoo \ + --config=/opt/odoo/auto/odoo.conf \ + --max-cron-threads=0 \ + --limit-time-real=10000 \ + --workers=0 \ + --test-enable \ + --stop-after-init \ + --addons-path="$PWD,/opt/odoo/auto/addons" \ + -d "$PGDATABASE" \ + -i "$modules" \ + --test-tags "$tags" diff --git a/.gitea/workflows/pre-commit.yml b/.gitea/workflows/pre-commit.yml index 61d456b..dacf086 100644 --- a/.gitea/workflows/pre-commit.yml +++ b/.gitea/workflows/pre-commit.yml @@ -2,8 +2,6 @@ name: pre-commit on: pull_request: - branches: - - "16.0*" jobs: pre-commit: @@ -15,10 +13,10 @@ jobs: python-version: "3.11" - name: Get python version run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV - # - uses: actions/cache@v4 - # with: - # path: ~/.cache/pre-commit - # key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} + - uses: https://gitea.com/actions/cache@v3 + with: + path: ~/.cache/pre-commit + key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} - name: Install pre-commit run: pip install pre-commit - name: Run pre-commit diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml new file mode 100644 index 0000000..e6c94bb --- /dev/null +++ b/.gitea/workflows/test.yml @@ -0,0 +1,79 @@ +name: tests + +on: + pull_request: + branches: + - "16.0*" + workflow_dispatch: + +jobs: + test: + runs-on: odoo-ci + container: + image: docker.0k.io/mirror/odoo:rc_16.0-ELABORE-LIGHT + services: + postgres: + image: docker.0k.io/postgres:17.2.0-myc + env: + POSTGRES_USER: odoo + POSTGRES_PASSWORD: odoopassword + POSTGRES_DB: postgres + steps: + # The doodba image ships no Node.js, so actions/checkout@v4 cannot + # run here. The repository is private, so the job token is required. + - name: Checkout + env: + SECRET_GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + SECRET_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -eu + token="${GITEA_TOKEN:-${GITHUB_TOKEN:-${SECRET_GITEA_TOKEN:-${SECRET_GITHUB_TOKEN:-}}}}" + if [ -z "$token" ]; then + echo "::error::No job token available to clone the repository" + exit 1 + fi + server="${GITHUB_SERVER_URL:-https://git.elabore.coop}" + repo="${GITHUB_REPOSITORY:?GITHUB_REPOSITORY is not set}" + ref="${GITHUB_REF:-${GITHUB_SHA:?neither GITHUB_REF nor GITHUB_SHA is set}}" + auth_url="$(printf '%s' "${server%/}/${repo}.git" | + sed -E "s#^https://#https://${token}@#")" + git init -q . + git config --global --add safe.directory "$PWD" + git remote add origin "$auth_url" + git fetch -q --depth=1 origin "$ref" + git checkout -q FETCH_HEAD + + - name: Detect changed modules + id: changed + run: | + set -eu + if [ -n "${GITHUB_BASE_REF:-}" ]; then + git fetch -q --depth=1 origin "refs/heads/$GITHUB_BASE_REF" + base_rev="FETCH_HEAD" + scope="diff against $GITHUB_BASE_REF" + else + base_rev="" + scope="all installable modules (manual run)" + fi + if [ -n "$base_rev" ]; then + modules="$( + git diff --name-only "$base_rev" HEAD | + awk -F/ '{print $1}' | sort -u | + while read -r dir; do + [ -f "$dir/__manifest__.py" ] && echo "$dir" + done | paste -sd, - + )" + else + modules="$( + for dir in */; do + dir="${dir%/}" + [ -f "$dir/__manifest__.py" ] && echo "$dir" + done | paste -sd, - + )" + fi + echo "modules=$modules" >> "$GITHUB_OUTPUT" + echo "Modules to test ($scope): ${modules:-}" + + - name: Run Odoo tests + if: steps.changed.outputs.modules != '' + run: bash .gitea/scripts/odoo-tests.sh "${{ steps.changed.outputs.modules }}"