11name : CPU tests
22
33on :
4+ workflow_dispatch :
45 pull_request :
5- # Trigger on pull requests to master or develop
6+ # Trigger on pull requests to master or develop that are
7+ # marked as "ready for review" (non-draft PRs)
8+ types :
9+ - opened
10+ - synchronize
11+ - reopened
12+ - ready_for_review
613 branches :
714 - master
815 - develop
2128
2229jobs :
2330 build-docker-image-cpu :
31+ # do not trigger on draft PRs
32+ if : ${{ ! github.event.pull_request.draft }}
2433 # Build and push temporary Docker image to GitHub's container registry
2534 runs-on : ubuntu-22.04
2635 steps :
2736 - name : Check out repository
28- uses : actions/checkout@v3
37+ uses : actions/checkout@v4
38+ with :
39+ fetch-depth : ' 1'
2940
3041 - name : Set environment variables
3142 run : |
3748 echo "IMAGE_REPO=$IMAGE_REPO"
3849
3950 - name : Restore cache
40- uses : actions/cache@v3
51+ uses : actions/cache@v4
4152 id : cache-docker
4253 with :
4354 path : ${{ env.DOCKER_CACHE_PATH }}
5364 fi
5465
5566 - name : Pull latest image from container registry
56- run : docker pull $IMAGE_REPO/$IMAGE_NAME || true
67+ run : docker pull $IMAGE_REPO/$IMAGE_NAME --quiet || true
5768
5869 - name : Build temporary Docker image
5970 run : |
6576 CACHE=$IMAGE_REPO/$IMAGE_NAME:latest
6677 fi
6778
68- docker build . --file Dockerfile --tag $IMAGE_NAME:local --cache-from=$CACHE --build-arg DEVICE=cpu
79+ DOCKER_BUILDKIT=0 docker build . --file Dockerfile --tag $IMAGE_NAME:local --cache-from=$CACHE --build-arg DEVICE=cpu
6980
7081 # Show images
7182 docker images --filter=reference=$IMAGE_NAME --filter=reference=$IMAGE_REPO/$IMAGE_NAME
@@ -114,20 +125,20 @@ jobs:
114125 steps :
115126 - name : " Prepare environment: Restore cache"
116127 if : env.DOCKER_TAG != 'latest'
117- uses : actions/cache@v3
128+ uses : actions/cache@v4
118129 id : cache-docker
119130 with :
120131 path : ${{ env.DOCKER_CACHE_PATH }}
121132 key : ${{ github.run_id }}
122133
123134 - name : " Prepare environment: Load Docker image from cache"
124135 if : env.DOCKER_TAG != 'latest'
125- run : docker load -i $DOCKER_CACHE_PATH/docker-image.tar.gz
136+ run : docker load -i $DOCKER_CACHE_PATH/docker-image.tar.gz --quiet
126137
127138 - name : " Prepare environment: Pull latest image from container registry"
128139 if : env.DOCKER_TAG == 'latest'
129140 run : |
130- docker pull $IMAGE_REPO/$IMAGE_NAME:latest
141+ docker pull $IMAGE_REPO/$IMAGE_NAME:latest --quiet
131142 docker image tag $IMAGE_REPO/$IMAGE_NAME:latest $IMAGE_NAME:latest
132143
133144 - name : " Prepare environment: Run Docker container"
@@ -145,39 +156,81 @@ jobs:
145156 [[ $(docker inspect --format '{{json .State.Running}}' mala-cpu) == 'true' ]]
146157
147158 - name : Check out repository (mala)
148- uses : actions/checkout@v3
159+ uses : actions/checkout@v4
160+ with :
161+ fetch-depth : ' 1'
149162
150163 - name : Install mala package
151164 # Exec all commands inside the mala-cpu container
152165 shell : ' bash -c "docker exec -i mala-cpu bash < {0}"'
153166 run : |
154- # epxort Docker image Conda environment for a later comparison
155- conda env export -n mala-cpu > env_1 .yml
167+ # export Docker image Conda environment for a later comparison
168+ conda env export -n mala-cpu > env_before .yml
156169
157170 # install mala package
158- pip --no-cache-dir install -e .[opt,test]
171+ pip --no-cache-dir install -e .[opt,test] --no-build-isolation
172+
159173
160174 - name : Check if Conda environment meets the specified requirements
161175 shell : ' bash -c "docker exec -i mala-cpu bash < {0}"'
162176 run : |
163177 # export Conda environment _with_ mala package installed in it (and extra dependencies)
164- conda env export -n mala-cpu > env_2.yml
178+ conda env export -n mala-cpu > env_after.yml
179+
180+ # This command is necessary because conda includes even editable
181+ # packages in an export, at least in the versions we recently used.
182+ # That of course leads to the diff failing, since MALA can never
183+ # be there before it has been installed.
184+ sed -i '/materials-learning-algorithms/d' ./env_after.yml
165185
166186 # if comparison fails, `install/mala_cpu_[base]_environment.yml` needs to be aligned with
167187 # `requirements.txt` and/or extra dependencies are missing in the Docker Conda environment
168- diff env_1.yml env_2.yml
169188
170- - name : Check out repository (data)
171- uses : actions/checkout@v3
172- with :
173- repository : mala-project/test-data
174- path : mala_data
175- ref : v1.7.0
176- lfs : true
189+ if diff --brief env_before.yml env_after.yml
190+ then
191+ echo "Files env_before.yml and env_after.yml do not differ."
192+ else
193+ diff --side-by-side env_before.yml env_after.yml
194+ fi
195+
196+ - name : Download test data repository from RODARE
197+ shell : ' bash -c "docker exec -i mala-cpu python < {0}"'
198+ run : |
199+ import requests, shutil, zipfile
200+
201+ # This DOI represents all versions, and will always resolve to the latest one
202+ DOI = "https://doi.org/10.14278/rodare.2900"
203+
204+ # Resolve DOI and get record ID and the associated API URL
205+ response = requests.get(DOI)
206+ *_, record_id = response.url.split("/")
207+ api_url = f"https://rodare.hzdr.de/api/records/{record_id}"
208+
209+ # Download record from API and get the first file
210+ response = requests.get(api_url)
211+ record = response.json()
212+ size = record["files"][0]["size"]
213+ download_link = record["files"][0]["links"]["self"]
214+
215+ print(size, "bytes", "--", download_link)
216+
217+ # TODO: implement some sort of auto retry for failed HTTP requests
218+ response = requests.get(download_link)
219+
220+ # Saving downloaded content to a file
221+ with open("test-data.zip", mode="wb") as file:
222+ file.write(response.content)
223+
224+ # Get top level directory name
225+ dir_name = zipfile.ZipFile("test-data.zip").namelist()[0]
226+ shutil.unpack_archive("test-data.zip", ".")
227+
228+ print(f"Rename {dir_name} to mala_data")
229+ shutil.move(dir_name, "mala_data")
177230
178231 - name : Test mala
179232 shell : ' bash -c "docker exec -i mala-cpu bash < {0}"'
180- run : MALA_DATA_REPO=$(pwd)/mala_data pytest -m "not examples" --disable-warnings
233+ run : MALA_DATA_REPO=$(pwd)/mala_data pytest --cov=mala --cov-fail-under=60 - m "not examples" --disable-warnings
181234
182235 retag-docker-image-cpu :
183236 needs : [cpu-tests, build-docker-image-cpu]
@@ -193,34 +246,29 @@ jobs:
193246 ((contains(github.ref_name, 'develop') || contains(github.ref_name, 'master')) && needs.build-docker-image-cpu.outputs.docker-tag != 'latest')
194247 || startsWith(github.ref, 'refs/tags/')
195248 steps :
196- - name : Check out repository
197- uses : actions/checkout@v3
198-
199249 - name : " Prepare environment: Restore cache"
200250 if : env.DOCKER_TAG != 'latest'
201- uses : actions/cache@v3
251+ uses : actions/cache@v4
202252 id : cache-docker
203253 with :
204254 path : ${{ env.DOCKER_CACHE_PATH }}
205255 key : ${{ github.run_id }}
206256
207257 - name : " Prepare environment: Load Docker image from cache"
208258 if : env.DOCKER_TAG != 'latest'
209- run : docker load -i $DOCKER_CACHE_PATH/docker-image.tar.gz
259+ run : docker load -i $DOCKER_CACHE_PATH/docker-image.tar.gz --quiet
210260
211261 - name : " Prepare environment: Pull latest image from container registry"
212262 if : env.DOCKER_TAG == 'latest'
213- run : docker pull $IMAGE_REPO/$IMAGE_NAME:latest
263+ run : docker pull $IMAGE_REPO/$IMAGE_NAME:latest --quiet
214264
215265 - name : Tag Docker image
216266 run : |
217267 # Execute on change of Docker image
218268 if [[ "$DOCKER_TAG" != 'latest' ]]; then
219- GIT_SHA=${GITHUB_REF_NAME}-$(git rev-parse --short "$GITHUB_SHA")
220- echo "GIT_SHA=$GIT_SHA"
221269
222270 docker tag $IMAGE_NAME:$GITHUB_RUN_ID $IMAGE_REPO/$IMAGE_NAME:latest
223- docker tag $IMAGE_NAME:$GITHUB_RUN_ID $IMAGE_REPO/$IMAGE_NAME:$GIT_SHA
271+ docker tag $IMAGE_NAME:$GITHUB_RUN_ID $IMAGE_REPO/$IMAGE_NAME:${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}
224272 fi
225273
226274 # Execute on push of git tag
@@ -236,5 +284,4 @@ jobs:
236284 run : echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
237285
238286 - name : Push Docker image
239- run : docker push $IMAGE_REPO/$IMAGE_NAME --all-tags
240-
287+ run : docker push $IMAGE_REPO/$IMAGE_NAME --all-tags | grep -v -E 'Waiting|Layer already|Preparing|Pushed'
0 commit comments