From 4a58ab0858635b2556d03dc840157bd672c67f82 Mon Sep 17 00:00:00 2001
From: Geoffrey Arthaud <geoffrey.arthaud@developpement-durable.gouv.fr>
Date: Tue, 27 Feb 2024 23:13:09 +0100
Subject: [PATCH] Release executables in artifacts

---
 .gitlab-ci.yml | 61 +++++++++++++++++++++++++++++++++-----------------
 1 file changed, 40 insertions(+), 21 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 8ded4ae..97141b7 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,8 +1,9 @@
 stages:
-  - build
+  - build_test
+  - release
 
 check-format:
-  stage: build
+  stage: build_test
   image: rust:latest
   script:
     - rustup component add rustfmt
@@ -10,54 +11,72 @@ check-format:
   tags:
     - buildonly
 
-rust-latest:
-  stage: build
+test-rust-latest:
+  stage: build_test
   image: rust:latest
   script:
-    - cargo build --verbose
     - cargo test --verbose
   tags:
     - buildonly
 
-rust-nightly:
-  stage: build
+test-rust-nightly:
+  stage: build_test
   image: rustlang/rust:nightly
   script:
-    - cargo build --verbose
     - cargo test --verbose
   allow_failure: true
   tags:
     - buildonly
 
-rust-alpine:
-  stage: build
+release-linux:
+  stage: release
   image: rust:latest
+  variables:
+    TARGET: target/x86_64-unknown-linux-musl/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
-    - target/x86_64-unknown-linux-musl/release/gitlab-project-doctor --help
+    - strip $TARGET
+    - ldd $TARGET
+    - $TARGET --help
+  artifacts:
+    paths:
+      - $TARGET
   tags:
     - buildonly
 
-rust-macos:
-  stage: build
+release-macos-silicon:
+  stage: 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/aarch64-apple-darwin/release/gitlab-project-doctor
-    - target/aarch64-apple-darwin/release/gitlab-project-doctor --help
+    - strip $TARGET
+    - otool -L $TARGET
+    - $TARGET --help
+  artifacts:
+    paths:
+      - $TARGET
   tags:
     - macos_mx
+  retry: 1
 
-rust-macos-x86:
-  stage: build
-  image: joseluisq/rust-linux-darwin-builder:1.76.0
+release-macos-x86:
+  stage: 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/x86_64-apple-darwin/release/gitlab-project-doctor
-    - target/x86_64-apple-darwin/release/gitlab-project-doctor --help
+    - strip $TARGET
+    - otool -L $TARGET
+    - $TARGET --help
+  artifacts:
+    paths:
+      - $TARGET
   tags:
-    - macos_mx
\ No newline at end of file
+    - macos_mx
+  retry: 1
\ No newline at end of file
-- 
GitLab