Skip to content

Commit

Permalink
manage latest python version more elegantly
Browse files Browse the repository at this point in the history
  • Loading branch information
aperrin66 committed Dec 12, 2023
1 parent ca20f0a commit e9e173b
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions .github/workflows/tests_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit e9e173b

Please sign in to comment.