From 38e9eeaa7d5790ef4f66cd25b537ef89fb31dd48 Mon Sep 17 00:00:00 2001
From: Geoffrey Arthaud <geoffrey.arthaud@developpement-durable.gouv.fr>
Date: Tue, 27 Feb 2024 23:37:41 +0100
Subject: [PATCH] Refactor .gitlab-ci.yml for releases

---
 .gitlab-ci.yml | 55 +++++++++++++++++++++-----------------------------
 1 file changed, 23 insertions(+), 32 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 97141b7..8a13499 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -28,55 +28,46 @@ test-rust-nightly:
   tags:
     - buildonly
 
-release-linux:
+.rust-release:
   stage: release
-  image: rust:latest
   variables:
-    TARGET: target/x86_64-unknown-linux-musl/release/gitlab-project-doctor
+    TARGET: target/$TARGET_ARCH/release/gitlab-project-doctor
   script:
-    - apt update -y
-    - apt install -y musl-dev musl-tools build-essential
-    - rustup target add x86_64-unknown-linux-musl
-    - cargo build --target x86_64-unknown-linux-musl --release
+    - rustup target add $TARGET_ARCH
+    - cargo build --target $TARGET_ARCH --release
     - strip $TARGET
-    - ldd $TARGET
+    - $LDD_CMD $TARGET
     - $TARGET --help
   artifacts:
     paths:
       - $TARGET
+
+release-linux:
+  extends: .rust-release
+  image: rust:latest
+  variables:
+    TARGET_ARCH: x86_64-unknown-linux-musl
+    LDD_CMD: ldd
+  before_script:
+    - apt update -y
+    - apt install -y musl-dev musl-tools build-essential
   tags:
     - buildonly
 
 release-macos-silicon:
-  stage: release
+  extends: .rust-release
   variables:
-    TARGET: target/aarch64-apple-darwin/release/gitlab-project-doctor
-  script:
-    - rustup target add aarch64-apple-darwin
-    - cargo build --target aarch64-apple-darwin --release
-    - strip $TARGET
-    - otool -L $TARGET
-    - $TARGET --help
-  artifacts:
-    paths:
-      - $TARGET
+    TARGET_ARCH: aarch64-apple-darwin
+    LDD_CMD: otool -L
   tags:
     - macos_mx
-  retry: 1
+  retry: 1 # First-time OpenSSL build will fail rust build
 
 release-macos-x86:
-  stage: release
+  extends: .rust-release
   variables:
-    TARGET: target/x86_64-apple-darwin/release/gitlab-project-doctor
-  script:
-    - rustup target add x86_64-apple-darwin
-    - cargo build --target x86_64-apple-darwin --release
-    - strip $TARGET
-    - otool -L $TARGET
-    - $TARGET --help
-  artifacts:
-    paths:
-      - $TARGET
+    TARGET_ARCH: x86_64-apple-darwin
+    LDD_CMD: otool -L
   tags:
     - macos_mx
-  retry: 1
\ No newline at end of file
+  retry: 1 # First-time OpenSSL build will fail rust build
\ No newline at end of file
-- 
GitLab