Skip to content

Commit 32f4d22

Browse files
committed
merge test and docker build jobs
1 parent f5ab71d commit 32f4d22

File tree

1 file changed

+44
-69
lines changed

1 file changed

+44
-69
lines changed

.github/workflows/tests_build.yml

Lines changed: 44 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,35 @@ env:
1111
BASE_IMAGE_NAME: "${{ secrets.DOCKER_ORG }}/nansat_base"
1212
BASE_IMAGE_TAG: '0.0.19'
1313
jobs:
14-
tests:
15-
name: 'Run unit tests'
14+
tests_and_docker_build:
15+
name: 'Run unit tests and build docker image'
1616
runs-on: 'ubuntu-20.04'
1717
strategy:
1818
matrix:
1919
tag_suffix:
2020
- ''
2121
- '-slim'
22-
python_version:
23-
- '3.7'
24-
- '3.8'
25-
- '3.9'
26-
- '3.10'
27-
- '3.11'
22+
version:
23+
- {'python': '3.7', 'latest': false}
24+
- {'python': '3.8', 'latest': false}
25+
- {'python': '3.9', 'latest': false}
26+
- {'python': '3.10', 'latest': false}
27+
- {'python': '3.11', 'latest': true}
2828
steps:
2929
- name: 'Checkout repository'
3030
uses: actions/checkout@v4
3131

32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
34+
35+
- name: Cache Docker layers
36+
uses: actions/cache@v3
37+
with:
38+
path: /tmp/.buildx-cache
39+
key: ${{ runner.os }}-buildx${{ matrix.tag_suffix }}-python${{ matrix.version.python }}-${{ github.sha }}
40+
restore-keys: |
41+
${{ runner.os }}-buildx${{ matrix.tag_suffix }}-python${{ matrix.version.python }}-
42+
3243
- name: Login to DockerHub
3344
uses: docker/login-action@v3
3445
with:
@@ -48,7 +59,7 @@ jobs:
4859
-e "GITHUB_REPOSITORY=$GITHUB_REPOSITORY"
4960
-e "GITHUB_RUN_ID=$GITHUB_RUN_ID"
5061
-e "GITHUB_TOKEN=$GITHUB_TOKEN"
51-
"${BASE_IMAGE_NAME}:${BASE_IMAGE_TAG}${{ matrix.tag_suffix }}-python${{ matrix.python_version }}"
62+
"${BASE_IMAGE_NAME}:${BASE_IMAGE_TAG}${{ matrix.tag_suffix }}-python${{ matrix.version.python }}"
5263
bash -c "
5364
apt update && apt install -y g++ &&
5465
python setup.py sdist &&
@@ -64,10 +75,33 @@ jobs:
6475
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6576
run: pip install coveralls && coveralls --service=github
6677

78+
- name: Build docker image
79+
uses: docker/build-push-action@v5
80+
with:
81+
context: .
82+
build-args: |
83+
BASE_IMAGE=${{ env.BASE_IMAGE_NAME }}:${{ env.BASE_IMAGE_TAG }}${{ matrix.tag_suffix }}-python${{ matrix.version.python }}
84+
NANSAT_RELEASE=${{ env.TAG == 'tmp' && '0.0.0' || env.TAG }}
85+
push: ${{ github.ref_type == 'tag' }}
86+
tags: |
87+
${{ env.IMAGE_NAME }}:${{ env.TAG }}${{ matrix.tag_suffix }}-python${{ matrix.version.python }}
88+
${{ env.IMAGE_NAME }}:latest${{ matrix.tag_suffix }}-python${{ matrix.version.python }}
89+
${{ matrix.version.latest && format('latest{0}', matrix.tag_suffix) || '' }}
90+
cache-from: type=local,src=/tmp/.buildx-cache
91+
cache-to: type=local,dest=/tmp/.buildx-cache-new
92+
93+
# Temp fix
94+
# https://github.com/docker/build-push-action/issues/252
95+
# https://github.com/moby/buildkit/issues/1896
96+
- name: Move cache
97+
run: |
98+
rm -rf /tmp/.buildx-cache
99+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
100+
67101
publish_python_package:
68102
name: Publish the Python package to PyPI
69103
runs-on: 'ubuntu-20.04'
70-
needs: 'tests'
104+
needs: 'tests_and_docker_build'
71105
if: github.event_name == 'release'
72106
steps:
73107
- name: 'Checkout repository'
@@ -89,63 +123,4 @@ jobs:
89123
# publishing to the test PyPI from forks easy
90124
repository_url: ${{ secrets.PYPI_REPOSITORY_URL }}
91125
password: ${{ secrets.PYPI_TOKEN }}
92-
93-
94-
build_docker_images:
95-
runs-on: 'ubuntu-20.04'
96-
needs: 'tests'
97-
strategy:
98-
matrix:
99-
tag_suffix:
100-
- ''
101-
- '-slim'
102-
version:
103-
- {'python': '3.7', 'latest': false}
104-
- {'python': '3.8', 'latest': false}
105-
- {'python': '3.9', 'latest': false}
106-
- {'python': '3.10', 'latest': false}
107-
- {'python': '3.11', 'latest': true}
108-
steps:
109-
- name: 'Checkout repository'
110-
uses: actions/checkout@v4
111-
112-
- name: Set up Docker Buildx
113-
uses: docker/setup-buildx-action@v3
114-
115-
- name: Cache Docker layers
116-
uses: actions/cache@v3
117-
with:
118-
path: /tmp/.buildx-cache
119-
key: ${{ runner.os }}-buildx${{ matrix.tag_suffix }}-python${{ matrix.version.python }}-${{ github.sha }}
120-
restore-keys: |
121-
${{ runner.os }}-buildx${{ matrix.tag_suffix }}-python${{ matrix.version.python }}-
122-
123-
- name: Login to DockerHub
124-
uses: docker/login-action@v3
125-
with:
126-
username: ${{ secrets.DOCKER_USER }}
127-
password: ${{ secrets.DOCKER_PASS }}
128-
129-
- name: Build docker image
130-
uses: docker/build-push-action@v5
131-
with:
132-
context: .
133-
build-args: |
134-
BASE_IMAGE=${{ env.BASE_IMAGE_NAME }}:${{ env.BASE_IMAGE_TAG }}${{ matrix.tag_suffix }}-python${{ matrix.version.python }}
135-
NANSAT_RELEASE=${{ env.TAG == 'tmp' && '0.0.0' || env.TAG }}
136-
push: ${{ github.ref_type == 'tag' }}
137-
tags: |
138-
${{ env.IMAGE_NAME }}:${{ env.TAG }}${{ matrix.tag_suffix }}-python${{ matrix.version.python }}
139-
${{ env.IMAGE_NAME }}:latest${{ matrix.tag_suffix }}-python${{ matrix.version.python }}
140-
${{ matrix.version.latest && format('latest{0}', matrix.tag_suffix) || '' }}
141-
cache-from: type=local,src=/tmp/.buildx-cache
142-
cache-to: type=local,dest=/tmp/.buildx-cache-new
143-
144-
# Temp fix
145-
# https://github.com/docker/build-push-action/issues/252
146-
# https://github.com/moby/buildkit/issues/1896
147-
- name: Move cache
148-
run: |
149-
rm -rf /tmp/.buildx-cache
150-
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
151126
...

0 commit comments

Comments
 (0)