From 14f3efaa3a667b21904e5437e0707e4454a419dd Mon Sep 17 00:00:00 2001
From: Moul <moul@moul.re>
Date: Tue, 14 Feb 2023 08:52:24 +0100
Subject: [PATCH] (ci) Set up cache among jobs of the same pipeline

Among jobs downloading and compiling dependencies as debug type
fmt_and_clippy, build_debug, test_debug

Delete not very used build_debug_with_cache job
Delete lines cleaning cargo artifacts and moving target directory
preventing the cache to work
---
 .gitlab-ci.yml | 37 ++++++++++---------------------------
 1 file changed, 10 insertions(+), 27 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 12aa2a85b..5d30a9869 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -56,26 +56,6 @@ fmt_and_clippy:
     - cargo fmt -- --check
     - cargo clippy -- -V
     - cargo clippy --all --tests -- -D warnings
-
-build_debug:
-  extends: .env
-  rules:
-    - if: $CI_COMMIT_TAG
-      when: never
-    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_BRANCH == "master"'
-      changes:
-      - Cargo.lock
-    - when: never
-  stage: build
-  script:
-    - cargo clean -p duniter
-    - cargo build --locked
-    - mkdir build
-    - mv target/debug/duniter build/duniter
-  artifacts:
-    paths:
-      - build/
-    expire_in: 3 day
   cache:
     - key:
         files:
@@ -84,22 +64,18 @@ build_debug:
         - target/debug
       policy: push
 
-build_debug_with_cache:
+build_debug:
   extends: .env
   rules:
-    - changes:
-      - Cargo.lock
-      when: never
     - if: $CI_COMMIT_TAG
       when: never
     - if: '$CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_BRANCH == "master"'
+      changes:
+      - Cargo.lock
     - when: never
   stage: build
   script:
-    - cargo clean -p duniter
     - cargo build --locked
-    - mkdir build
-    - mv target/debug/duniter build/duniter
   artifacts:
     paths:
       - build/
@@ -169,6 +145,13 @@ tests_debug:
     - cd target/debug/deps/
     - rm cucumber_tests-*.d
     - mv cucumber_tests* ../../../build/duniter-cucumber
+  cache:
+    - key:
+        files:
+          - Cargo.lock
+      paths:
+        - target/debug
+      policy: pull
   artifacts:
     paths:
       - build/
-- 
GitLab