Skip to content

Commit c34e64e

Browse files
committed
manage latest python version more elegantly
1 parent 8a8f532 commit c34e64e

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

.github/workflows/build_images.yml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ env:
1111
jobs:
1212
build_docker_images:
1313
runs-on: 'ubuntu-20.04'
14+
env:
15+
latest_python: '3.11'
1416
strategy:
1517
matrix:
16-
version:
17-
- {'python': '3.7', 'latest': false}
18-
- {'python': '3.8', 'latest': false}
19-
- {'python': '3.9', 'latest': false}
20-
- {'python': '3.10', 'latest': false}
21-
- {'python': '3.11', 'latest': true}
18+
python_version:
19+
- '3.7'
20+
- '3.8'
21+
- '3.9'
22+
- '3.10'
23+
- '3.11'
2224
steps:
2325
- name: 'Checkout repository'
2426
uses: actions/checkout@v4
@@ -30,9 +32,9 @@ jobs:
3032
uses: actions/cache@v3
3133
with:
3234
path: /tmp/.buildx-cache
33-
key: ${{ runner.os }}-buildx-python${{ matrix.version.python }}-${{ github.sha }}
35+
key: ${{ runner.os }}-buildx-python${{ matrix.python_version }}-${{ github.sha }}
3436
restore-keys: |
35-
${{ runner.os }}-buildx-python${{ matrix.version.python }}-
37+
${{ runner.os }}-buildx-python${{ matrix.python_version }}-
3638
3739
- name: Login to DockerHub
3840
uses: docker/login-action@v3
@@ -45,13 +47,13 @@ jobs:
4547
with:
4648
context: .
4749
file: Dockerfile
48-
build-args: 'PYTHON_VERSION=${{ matrix.version.python }}'
50+
build-args: 'PYTHON_VERSION=${{ matrix.python_version }}'
4951
push: ${{ github.ref_type == 'tag' }}
5052
tags: |
51-
${{ env.IMAGE_NAME }}:latest-python${{ matrix.version.python }}
52-
${{ env.IMAGE_NAME }}:${{ github.ref_name }}-python${{ matrix.version.python }}
53-
${{ matrix.version.latest && format('{0}:{1}', env.IMAGE_NAME, github.ref_name) || '' }}
54-
${{ matrix.version.latest && format('{0}:latest', env.IMAGE_NAME) || '' }}
53+
${{ env.IMAGE_NAME }}:latest-python${{ matrix.python_version }}
54+
${{ env.IMAGE_NAME }}:${{ github.ref_name }}-python${{ matrix.python_version }}
55+
${{ (matrix.python_version == env.latest_python) && format('{0}:{1}', env.IMAGE_NAME, github.ref_name) || '' }}
56+
${{ (matrix.python_version == env.latest_python) && format('{0}:latest', env.IMAGE_NAME) || '' }}
5557
cache-from: |
5658
type=local,src=/tmp/.buildx-cache
5759
cache-to: type=local,dest=/tmp/.buildx-cache-new

0 commit comments

Comments
 (0)