diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index ae4549a63c8f4..a4fcc78bd76ac 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -58,10 +58,31 @@ 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: | + 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 -it -v ./build-cache:/from -v po_off_build_cache:/to alpine ash -c 'cd /from ; cp -av . /to' + 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 -it -v ./build-cache:/from -v po_off_test_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 +97,10 @@ 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: | + mkdir -p build-cache + docker container run --rm -it -v po_off_build_cache:/from -v ./build-cache:/to alpine ash -c 'cd /from ; cp -av . /to' check_perl: name: 🐪 Check Perl @@ -96,8 +121,29 @@ 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 -it -v ./build-cache:/from -v po_off_build_cache:/to alpine ash -c 'cd /from ; cp -av . /to' + 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 -it -v ./build-cache:/from -v po_off_test_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 with: image: "openfoodfacts-server/backend:dev" - name: build taxonomies (should use cache) @@ -119,6 +165,27 @@ 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 -it -v ./build-cache:/from -v po_off_build_cache:/to alpine ash -c 'cd /from ; cp -av . /to' + 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 -it -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 +197,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 with: image: "openfoodfacts-server/backend:dev" - name: tests @@ -157,8 +224,29 @@ 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 -it -v ./build-cache:/from -v po_off_build_cache:/to alpine ash -c 'cd /from ; cp -av . /to' + 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 -it -v ./build-cache:/from -v po_off_test_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 with: image: "openfoodfacts-server/backend:dev" - name: set right UID and GID in .envrc