ci #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: ci | |
| on: | |
| pull_request: | |
| push: | |
| branches: | |
| - master | |
| schedule: | |
| # See https://crontab.guru/weekly | |
| - cron: 0 0 * * 0 | |
| jobs: | |
| pre-commit: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v4 | |
| with: | |
| python-version: "3.11" | |
| - name: Set PY | |
| run: | | |
| echo "PY=$(python -c 'import hashlib, | |
| sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_ENV | |
| - uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pre-commit | |
| key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} | |
| - uses: pre-commit/action@v3.0.1 | |
| build-push-pr: | |
| # Build & push PR images so tests and local dev can pull them | |
| if: github.event_name == 'pull_request' | |
| runs-on: ubuntu-24.04 | |
| needs: pre-commit | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| # Test modern Odoo versions with latest Postgres version | |
| odoo_version: ["19.0"] | |
| platforms: ["linux/amd64,linux/arm64"] | |
| include: | |
| # Older odoo versions don't support latest postgres and Python versions | |
| - odoo_version: "18.0" | |
| platforms: "linux/amd64,linux/arm64" | |
| - odoo_version: "17.0" | |
| platforms: "linux/amd64,linux/arm64" | |
| - odoo_version: "16.0" | |
| platforms: "linux/amd64,linux/arm64" | |
| - odoo_version: "15.0" | |
| platforms: "linux/amd64,linux/arm64" | |
| - odoo_version: "14.0" | |
| platforms: "linux/amd64,linux/arm64" | |
| - odoo_version: "13.0" | |
| platforms: "linux/amd64" | |
| env: | |
| # Indicates what's the equivalent to tecnativa/doodba:latest image | |
| LATEST_RELEASE: "19.0" | |
| DOCKER_REPO: tecnativa/doodba | |
| GHCR_HOST: ghcr.io | |
| steps: | |
| - name: Clean Docker system before build | |
| run: | | |
| docker system prune -af --volumes || true | |
| docker builder prune -af || true | |
| # Set build date as env variable to be used later | |
| - name: Set build date | |
| run: echo "BUILD_DATE=$(date '+%Y-%m-%dT%H:%M:%S.%N%:z')" >> $GITHUB_ENV | |
| # Prepare | |
| - uses: actions/checkout@v4 | |
| # Setup QEMU | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Reset QEMU | |
| if: ${{ matrix.odoo_version == '15.0' }} | |
| run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes | |
| # Setup buildx | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| if: | |
| github.repository == 'tecnativa/doodba' && | |
| github.event.pull_request.head.repo.full_name == github.repository | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_LOGIN }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Login to GitHub Container Registry | |
| if: | |
| github.repository == 'tecnativa/doodba' && | |
| github.event.pull_request.head.repo.full_name == github.repository | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ secrets.BOT_LOGIN }} | |
| password: ${{ secrets.BOT_TOKEN }} | |
| - name: Build base image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./${{ matrix.odoo_version }}.Dockerfile | |
| platforms: ${{ matrix.platforms }} | |
| push: | |
| ${{ github.repository == 'tecnativa/doodba' && | |
| github.event.pull_request.head.repo.full_name == github.repository }} | |
| tags: | | |
| ${{ env.DOCKER_REPO }}:${{ matrix.odoo_version }}-pr-${{ github.event.pull_request.number }}-test | |
| ${{ env.GHCR_HOST }}/${{ env.DOCKER_REPO }}${{ env.DOCKER_REPO_SUFFIX }}:${{ matrix.odoo_version }}-pr-${{ github.event.pull_request.number }}-test | |
| target: base | |
| build-args: | | |
| VCS_REF=${{ github.sha }} | |
| BUILD_DATE=${{ env.BUILD_DATE }} | |
| ODOO_VERSION=${{ matrix.odoo_version }} | |
| - name: Build onbuild image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./${{ matrix.odoo_version }}.Dockerfile | |
| platforms: ${{ matrix.platforms }} | |
| push: | |
| ${{ github.repository == 'tecnativa/doodba' && | |
| github.event.pull_request.head.repo.full_name == github.repository }} | |
| tags: | | |
| ${{ env.DOCKER_REPO }}:${{ matrix.odoo_version }}-pr-${{ github.event.pull_request.number }}-test-onbuild | |
| ${{ env.GHCR_HOST }}/${{ env.DOCKER_REPO }}${{ env.DOCKER_REPO_SUFFIX }}:${{ matrix.odoo_version }}-pr-${{ github.event.pull_request.number }}-test-onbuild | |
| target: onbuild | |
| build-args: | | |
| VCS_REF=${{ github.sha }} | |
| BUILD_DATE=${{ env.BUILD_DATE }} | |
| ODOO_VERSION=${{ matrix.odoo_version }} | |
| - name: Clean Docker system after build | |
| run: | | |
| docker system prune -af --volumes || true | |
| docker builder prune -af || true | |
| test-pr: | |
| # Run tests in PR using the freshly pushed images | |
| if: github.event_name == 'pull_request' | |
| runs-on: ubuntu-24.04 | |
| needs: build-push-pr | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| odoo_version: ["19.0"] | |
| pg_version: ["17"] | |
| python_version: ["3.12"] | |
| include: | |
| - odoo_version: "18.0" | |
| pg_version: "16" | |
| python_version: "3.10" | |
| - odoo_version: "17.0" | |
| pg_version: "15" | |
| python_version: "3.10" | |
| - odoo_version: "16.0" | |
| pg_version: "14" | |
| python_version: "3.10" | |
| - odoo_version: "15.0" | |
| pg_version: "14" | |
| python_version: "3.9" | |
| - odoo_version: "14.0" | |
| pg_version: "14" | |
| python_version: "3.9" | |
| - odoo_version: "13.0" | |
| pg_version: "14" | |
| python_version: "3.9" | |
| env: | |
| DOCKER_BUILDKIT: 1 | |
| DOCKER_TAG: | |
| ${{ matrix.odoo_version }}-pr-${{ github.event.pull_request.number }}-test | |
| PG_VERSIONS: ${{ matrix.pg_version }} | |
| ODOO_MINOR: ${{ matrix.odoo_version }} | |
| # signal to tests that they can use the prebuilt images from registries and do not need to build the image in setupClass | |
| USE_PREBUILT_IMAGES: | |
| ${{ github.repository == 'tecnativa/doodba' && | |
| github.event.pull_request.head.repo.full_name == github.repository }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python_version }} | |
| - uses: docker/setup-compose-action@v1 | |
| with: | |
| version: latest | |
| - run: pip install poetry | |
| - name: Patch $PATH | |
| run: echo "$HOME/.local/bin" >> $GITHUB_PATH | |
| - run: poetry install | |
| - run: poetry run python -m unittest -v tests | |
| test: | |
| if: github.event_name != 'pull_request' | |
| runs-on: ubuntu-24.04 | |
| needs: pre-commit | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| odoo_version: ["19.0"] | |
| pg_version: ["17"] | |
| python_version: ["3.12"] | |
| include: | |
| - odoo_version: "18.0" | |
| pg_version: "16" | |
| python_version: "3.10" | |
| - odoo_version: "17.0" | |
| pg_version: "15" | |
| python_version: "3.10" | |
| - odoo_version: "16.0" | |
| pg_version: "14" | |
| python_version: "3.10" | |
| - odoo_version: "15.0" | |
| pg_version: "14" | |
| python_version: "3.9" | |
| - odoo_version: "14.0" | |
| pg_version: "14" | |
| python_version: "3.9" | |
| - odoo_version: "13.0" | |
| pg_version: "14" | |
| python_version: "3.9" | |
| env: | |
| DOCKER_BUILDKIT: 1 | |
| PG_VERSIONS: ${{ matrix.pg_version }} | |
| ODOO_MINOR: ${{ matrix.odoo_version }} | |
| DOCKER_TAG: ${{ matrix.odoo_version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python_version }} | |
| - uses: docker/setup-compose-action@v1 | |
| with: | |
| version: latest | |
| - run: pip install poetry | |
| - name: Patch $PATH | |
| run: echo "$HOME/.local/bin" >> $GITHUB_PATH | |
| - run: poetry install | |
| - run: poetry run python -m unittest -v tests | |
| build-push-official: | |
| # Only publish final images from master after tests pass | |
| if: github.repository == 'tecnativa/doodba' && github.ref == 'refs/heads/master' | |
| runs-on: ubuntu-24.04 | |
| needs: test | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| # Test modern Odoo versions with latest Postgres version | |
| odoo_version: ["19.0"] | |
| platforms: ["linux/amd64,linux/arm64"] | |
| include: | |
| # Older odoo versions don't support latest postgres and Python versions | |
| - odoo_version: "18.0" | |
| platforms: "linux/amd64,linux/arm64" | |
| - odoo_version: "17.0" | |
| platforms: "linux/amd64,linux/arm64" | |
| - odoo_version: "16.0" | |
| platforms: "linux/amd64,linux/arm64" | |
| - odoo_version: "15.0" | |
| platforms: "linux/amd64,linux/arm64" | |
| - odoo_version: "14.0" | |
| platforms: "linux/amd64,linux/arm64" | |
| - odoo_version: "13.0" | |
| platforms: "linux/amd64" | |
| env: | |
| # Indicates what tag matches tecnativa/doodba:latest | |
| LATEST_RELEASE: "19.0" | |
| # Define the docker hub repository location and github container registry host | |
| DOCKER_REPO: tecnativa/doodba | |
| GHCR_HOST: ghcr.io | |
| steps: | |
| - name: Clean Docker system before build | |
| run: | | |
| docker system prune -af --volumes || true | |
| docker builder prune -af || true | |
| # Set build date as env variable to be used later | |
| - name: Set build date | |
| run: echo "BUILD_DATE=$(date '+%Y-%m-%dT%H:%M:%S.%N%:z')" >> $GITHUB_ENV | |
| # Prepare | |
| - uses: actions/checkout@v4 | |
| # Setup QEMU | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Reset QEMU | |
| if: ${{ matrix.odoo_version == '15.0' }} | |
| run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes | |
| # Setup buildx | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_LOGIN }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ secrets.BOT_LOGIN }} | |
| password: ${{ secrets.BOT_TOKEN }} | |
| - name: Build base image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./${{ matrix.odoo_version }}.Dockerfile | |
| platforms: ${{ matrix.platforms }} | |
| push: | |
| ${{ github.repository == 'tecnativa/doodba' && github.ref == | |
| 'refs/heads/master' }} | |
| tags: | | |
| ${{ env.DOCKER_REPO }}:${{ matrix.odoo_version }} | |
| ${{ env.GHCR_HOST }}/${{ env.DOCKER_REPO }}${{ env.DOCKER_REPO_SUFFIX }}:${{ matrix.odoo_version }} | |
| ${{ matrix.odoo_version == env.LATEST_RELEASE && format('{0}:latest', env.DOCKER_REPO) || '' }} | |
| ${{ matrix.odoo_version == env.LATEST_RELEASE && format('{0}/{1}{2}:latest', env.GHCR_HOST, env.DOCKER_REPO, env.DOCKER_REPO_SUFFIX) || '' }} | |
| target: base | |
| build-args: | | |
| VCS_REF=${{ github.sha }} | |
| BUILD_DATE=${{ env.BUILD_DATE }} | |
| ODOO_VERSION=${{ matrix.odoo_version }} | |
| - name: Build onbuild image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./${{ matrix.odoo_version }}.Dockerfile | |
| platforms: ${{ matrix.platforms }} | |
| push: | |
| ${{ github.repository == 'tecnativa/doodba' && github.ref == | |
| 'refs/heads/master' }} | |
| tags: | | |
| ${{ env.DOCKER_REPO }}:${{ matrix.odoo_version }}-onbuild | |
| ${{ env.GHCR_HOST }}/${{ env.DOCKER_REPO }}${{ env.DOCKER_REPO_SUFFIX }}:${{ matrix.odoo_version }}-onbuild | |
| ${{ matrix.odoo_version == env.LATEST_RELEASE && format('{0}:latest-onbuild', env.DOCKER_REPO) || '' }} | |
| ${{ matrix.odoo_version == env.LATEST_RELEASE && format('{0}/{1}{2}:latest-onbuild', env.GHCR_HOST, env.DOCKER_REPO, env.DOCKER_REPO_SUFFIX) || '' }} | |
| target: onbuild | |
| build-args: | | |
| VCS_REF=${{ github.sha }} | |
| BUILD_DATE=${{ env.BUILD_DATE }} | |
| ODOO_VERSION=${{ matrix.odoo_version }} | |
| - name: Clean Docker system after build | |
| run: | | |
| docker system prune -af --volumes || true | |
| docker builder prune -af || true |