diff --git a/config/16.0/.gitea/workflows/test.yml b/config/16.0/.gitea/workflows/test.yml index a41ff78..e6c94bb 100644 --- a/config/16.0/.gitea/workflows/test.yml +++ b/config/16.0/.gitea/workflows/test.yml @@ -19,25 +19,60 @@ jobs: POSTGRES_PASSWORD: odoopassword POSTGRES_DB: postgres steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 + # 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: | - base="${{ gitea.base_ref }}" - base="${base:-${{ gitea.event.pull_request.base.ref }}}" - git fetch origin "$base" - modules="$( - git diff --name-only "origin/$base...HEAD" | - awk -F/ '{print $1}' | sort -u | - while read -r dir; do + 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 "Changed installable modules: ${modules:-}" + echo "Modules to test ($scope): ${modules:-}" - name: Run Odoo tests if: steps.changed.outputs.modules != '' diff --git a/config/18.0/.gitea/workflows/test.yml b/config/18.0/.gitea/workflows/test.yml index 526ce60..6864da3 100644 --- a/config/18.0/.gitea/workflows/test.yml +++ b/config/18.0/.gitea/workflows/test.yml @@ -19,25 +19,60 @@ jobs: POSTGRES_PASSWORD: odoopassword POSTGRES_DB: postgres steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 + # 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: | - base="${{ gitea.base_ref }}" - base="${base:-${{ gitea.event.pull_request.base.ref }}}" - git fetch origin "$base" - modules="$( - git diff --name-only "origin/$base...HEAD" | - awk -F/ '{print $1}' | sort -u | - while read -r dir; do + 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 "Changed installable modules: ${modules:-}" + echo "Modules to test ($scope): ${modules:-}" - name: Run Odoo tests if: steps.changed.outputs.modules != ''