From e9e173b036e6e6fdbc5fdacbfc393080e0e92f36 Mon Sep 17 00:00:00 2001 From: Adrien Perrin Date: Tue, 12 Dec 2023 08:34:12 +0100 Subject: [PATCH] manage latest python version more elegantly --- .github/workflows/tests_build.yml | 34 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/.github/workflows/tests_build.yml b/.github/workflows/tests_build.yml index cec4ce75..62ee7895 100644 --- a/.github/workflows/tests_build.yml +++ b/.github/workflows/tests_build.yml @@ -13,14 +13,16 @@ jobs: tests_and_docker_build: name: 'Run unit tests and build docker image' runs-on: 'ubuntu-20.04' + env: + latest: ${{ matrix.python_version == '3.11' && 'true' || '' }} strategy: matrix: - version: - - {'python': '3.7', 'latest': false} - - {'python': '3.8', 'latest': false} - - {'python': '3.9', 'latest': false} - - {'python': '3.10', 'latest': false} - - {'python': '3.11', 'latest': true} + python_version: + - '3.7' + - '3.8' + - '3.9' + - '3.10' + - '3.11' steps: - name: 'Checkout repository' uses: actions/checkout@v4 @@ -32,9 +34,9 @@ jobs: uses: actions/cache@v3 with: path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-python${{ matrix.version.python }}-${{ github.sha }} + key: ${{ runner.os }}-buildx-python${{ matrix.python_version }}-${{ github.sha }} restore-keys: | - ${{ runner.os }}-buildx-python${{ matrix.version.python }}- + ${{ runner.os }}-buildx-python${{ matrix.python_version }}- - name: Login to DockerHub uses: docker/login-action@v3 @@ -55,19 +57,19 @@ jobs: -e "GITHUB_REPOSITORY=$GITHUB_REPOSITORY" -e "GITHUB_RUN_ID=$GITHUB_RUN_ID" -e "GITHUB_TOKEN=$GITHUB_TOKEN" - "${BASE_IMAGE_NAME}:${BASE_IMAGE_TAG}-python${{ matrix.version.python }}" + "${BASE_IMAGE_NAME}:${BASE_IMAGE_TAG}-python${{ matrix.python_version }}" bash -c " python setup.py sdist && coverage run --omit=nansat/mappers/*,nansat/tests/*,nansat/nansatmap.py --source=nansat setup.py test" - name: 'Install Python 3.11' - if: ${{ matrix.version.latest }} + if: ${{ env.latest }} uses: actions/setup-python@v4 with: python-version: '3.11' - name: 'Upload coverage to coveralls.io' - if: ${{ matrix.version.latest }} + if: ${{ env.latest }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: pip install coveralls && coveralls --service=github @@ -77,14 +79,14 @@ jobs: with: context: . build-args: | - BASE_IMAGE=${{ env.BASE_IMAGE_NAME }}:${{ env.BASE_IMAGE_TAG }}-python${{ matrix.version.python }} + BASE_IMAGE=${{ env.BASE_IMAGE_NAME }}:${{ env.BASE_IMAGE_TAG }}-python${{ matrix.python_version }} NANSAT_RELEASE=${{ github.ref_type == 'tag' && github.ref_name || '0.0.0' }} push: ${{ github.ref_type == 'tag' }} tags: | - ${{ env.IMAGE_NAME }}:${{ github.ref_name }}-python${{ matrix.version.python }} - ${{ matrix.version.latest && format('{0}:{1}', env.IMAGE_NAME, github.ref_name) || '' }} - ${{ env.IMAGE_NAME }}:latest-python${{ matrix.version.python }} - ${{ matrix.version.latest && format('{0}:latest', env.IMAGE_NAME) || '' }} + ${{ env.IMAGE_NAME }}:${{ github.ref_name }}-python${{ matrix.python_version }} + ${{ env.latest && format('{0}:{1}', env.IMAGE_NAME, github.ref_name) || '' }} + ${{ env.IMAGE_NAME }}:latest-python${{ matrix.python_version }} + ${{ env.latest && format('{0}:latest', env.IMAGE_NAME) || '' }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache-new