From 98612854408f914353c8664c3b9880b0afd412e7 Mon Sep 17 00:00:00 2001 From: josep-tecnativa Date: Fri, 29 Nov 2024 08:34:10 +0100 Subject: [PATCH] [IMP] Add pushing PR images to be able to test it correctly --- .github/workflows/ci.yaml | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a131748..e35cc29 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,10 +16,8 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v1 - name: Set PY - run: - echo "PY=$(python -c 'import hashlib, - sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" - >> $GITHUB_ENV + run: | + echo "PY=$(python -c 'import hashlib,sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_ENV - uses: actions/cache@v1 with: path: ~/.cache/pre-commit @@ -32,7 +30,6 @@ jobs: strategy: fail-fast: false matrix: - # Test modern Odoo versions with latest Postgres version pg_version: - "16" - "15" @@ -45,29 +42,37 @@ jobs: env: # Indicates what's the equivalent to tecnativa/postgres-autoconf:latest image LATEST_RELEASE: "16-alpine" - # Variables found by default in Docker Hub builder DOCKER_REPO: tecnativa/postgres-autoconf DOCKER_TAG: ${{ matrix.pg_version }}-alpine GIT_SHA1: ${{ github.sha }} + IS_PR: ${{ github.event_name == 'pull_request' }} steps: - # Prepare - uses: actions/checkout@v2 - uses: actions/setup-python@v1 - run: pip install -r tests/ci-requirements.txt + # Build images - run: ./hooks/build # Test - run: python -m unittest tests.test -v - # Push - - name: push to docker hub - if: github.repository == 'Tecnativa/docker-postgres-autoconf' && github.ref == 'refs/heads/master' + - name: Set Docker Tag + run: | + if [ "${{ env.IS_PR }}" = "true" ]; then + echo "DOCKER_TAG=${{ matrix.pg_version }}-test-pr${{ github.event.number }}" >> $GITHUB_ENV + docker tag ${{ env.DOCKER_REPO }}:${{ matrix.pg_version }}-alpine ${{ env.DOCKER_REPO }}:${{ DOCKER_TAG }} + else + echo "DOCKER_TAG=${{ matrix.pg_version }}-alpine" >> $GITHUB_ENV + fi + # Pushh + - name: Push Docker Image to Docker Hub + if: github.repository == 'Tecnativa/docker-postgres-autoconf' && (env.IS_PR || github.ref == 'refs/heads/master') env: REGISTRY_HOST: docker.io REGISTRY_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} REGISTRY_USERNAME: ${{ secrets.DOCKERHUB_LOGIN }} run: ./hooks/push - - name: push to github registry - if: github.repository == 'Tecnativa/docker-postgres-autoconf' && github.ref == 'refs/heads/master' + - name: Push Docker Image to GitHub Registry + if: github.repository == 'Tecnativa/docker-postgres-autoconf' && (env.IS_PR || github.ref == 'refs/heads/master') env: REGISTRY_HOST: ghcr.io REGISTRY_TOKEN: ${{ secrets.BOT_TOKEN }}