From 0827b107e0f2e8cdb03810358945941c8c079ff2 Mon Sep 17 00:00:00 2001 From: Marco Ciotola <848222@stud.unive.it> Date: Wed, 30 Oct 2024 13:45:21 +0100 Subject: [PATCH] ci: cache taxonomies --- .github/workflows/pull_request.yml | 72 ++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index ae4549a63c8f4..b4851f1e640c1 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -58,10 +58,26 @@ jobs: with: # needs depth to run git log below fetch-depth: 50 + - uses: actions/cache@v4 + id: cache + with: + path: ./build-cache + key: taxonomies-${{ hashFiles('taxonomies/**') }} + restore-keys: taxonomies- + - if: steps.cache.outputs.cache-hit == 'true' + name: Prepare build_cache volumes + run: | + proj=po_off + docker volume create \ + --label com.docker.compose.project=$proj \ + --label com.docker.compose.version=2.29.7 \ + --label com.docker.compose.volume=build_cache \ + ${proj}_build_cache + docker container run --rm -v ./build-cache:/from -v ${proj}_build_cache:/to alpine ash -c 'cd /from ; cp -av . /to' - name: build run: make build container=backend - name: push backend image as artifact - uses: ishworkh/docker-image-artifact-upload@v1 + uses: ishworkh/container-image-artifact-upload@v2.0.0 with: image: "openfoodfacts-server/backend:dev" - name: Fetch origin/main @@ -76,6 +92,9 @@ jobs: git ls-files taxonomies/ | xargs -I{} git log -1 --date=format:%Y%m%d%H%M.%S --format='touch -t %ad "{}"' "{}" | bash - name: Rebuild taxonomies run: make build_taxonomies GITHUB_TOKEN="${{ secrets.TAXONOMY_CACHE_GITHUB_TOKEN }}" + - name: Prepare taxonomies for cache + run: | + docker container run --rm -v po_off_build_cache:/from -v "$(pwd)"/build-cache:/to alpine ash -c 'cd /from ; cp -av . /to' check_perl: name: 🐪 Check Perl @@ -96,8 +115,23 @@ jobs: # see https://stackoverflow.com/a/60984318/2886726 run: | git ls-files taxonomies/ | xargs -I{} git log -1 --date=format:%Y%m%d%H%M.%S --format='touch -t %ad "{}"' "{}" | bash + - uses: actions/cache/restore@v4 + id: cache + with: + path: ./build-cache + key: taxonomies-${{ hashFiles('taxonomies/**') }} + restore-keys: taxonomies- + - if: steps.cache.outputs.cache-hit == 'true' + name: Prepare build_cache volumes + run: | + docker volume create \ + --label com.docker.compose.project=po_off \ + --label com.docker.compose.version=2.29.7 \ + --label com.docker.compose.volume=build_cache \ + po_off_build_cache + docker container run --rm -v ./build-cache:/from -v po_off_build_cache:/to alpine ash -c 'cd /from ; cp -av . /to' - name: Download backend image from artifacts - uses: ishworkh/docker-image-artifact-download@v1 + uses: ishworkh/container-image-artifact-download@v2.0.0 with: image: "openfoodfacts-server/backend:dev" - name: build taxonomies (should use cache) @@ -119,6 +153,21 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 1 + - uses: actions/cache/restore@v4 + id: cache + with: + path: ./build-cache + key: taxonomies-${{ hashFiles('taxonomies/**') }} + restore-keys: taxonomies- + - if: steps.cache.outputs.cache-hit == 'true' + name: Prepare build_cache volumes + run: | + docker volume create \ + --label com.docker.compose.project=po_off_test \ + --label com.docker.compose.version=2.29.7 \ + --label com.docker.compose.volume=build_cache \ + po_off_test_build_cache + docker container run --rm -v ./build-cache:/from -v po_off_test_build_cache:/to alpine ash -c 'cd /from ; cp -av . /to' - name: Fetch origin/main # we need origin/main to have comparison linting work run: | @@ -130,7 +179,7 @@ jobs: run: | git ls-files taxonomies/ | xargs -I{} git log -1 --date=format:%Y%m%d%H%M.%S --format='touch -t %ad "{}"' "{}" | bash - name: Download backend image from artifacts - uses: ishworkh/docker-image-artifact-download@v1 + uses: ishworkh/container-image-artifact-download@v2.0.0 with: image: "openfoodfacts-server/backend:dev" - name: tests @@ -157,8 +206,23 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 1 + - uses: actions/cache/restore@v4 + id: cache + with: + path: ./build-cache + key: taxonomies-${{ hashFiles('taxonomies/**') }} + restore-keys: taxonomies- + - if: steps.cache.outputs.cache-hit == 'true' + name: Prepare build_cache volumes + run: | + docker volume create \ + --label com.docker.compose.project=po_off \ + --label com.docker.compose.version=2.29.7 \ + --label com.docker.compose.volume=build_cache \ + po_off_build_cache + docker container run --rm -v ./build-cache:/from -v po_off_build_cache:/to alpine ash -c 'cd /from ; cp -av . /to' - name: Download backend image from artifacts - uses: ishworkh/docker-image-artifact-download@v1 + uses: ishworkh/container-image-artifact-download@v2.0.0 with: image: "openfoodfacts-server/backend:dev" - name: set right UID and GID in .envrc