From adbb3fc1e6638afc7dbd30d12a1b927c307a587a Mon Sep 17 00:00:00 2001
From: Hugo Trentesaux <hugo@trentesaux.fr>
Date: Tue, 11 Jul 2023 11:54:10 +0200
Subject: [PATCH] WIP try to release with CI

---
 .gitlab-ci.yml | 39 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index fa06a4d..60a680a 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -4,9 +4,19 @@ image: "rust:latest"
 
 stages:
   - build
+  - upload
+  - release
 
+variables:
+  # url for package registry
+  PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/gcli/${CI_COMMIT_TAG}"
+
+# build gcli binary
 build:
   stage: build
+  # only build gcli when adding a tag (does it really work?)
+  only:
+    - tags
   # image used for this build
   image: rust
   # build script
@@ -23,6 +33,29 @@ build:
           - Cargo.lock
       paths:
         - target/release
-  # only build gcli when adding a tag
-  only:
-    - tags
\ No newline at end of file
+
+# upload gcli binary to gitlab
+upload:
+  stage: upload
+  image: curlimages/curl:latest
+  rules:
+    - if: $CI_COMMIT_TAG
+  script:
+    - |
+      curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file target/release/gcli "${PACKAGE_REGISTRY_URL}" --fail
+
+# create a gitlab release pointing to this binary
+release:
+  stage: release
+  image: registry.gitlab.com/gitlab-org/release-cli:latest
+  script:
+    - echo "Running the release job."
+  release:
+    tag_name: $CI_COMMIT_TAG
+    name: 'Release $CI_COMMIT_TAG'
+    description: 'Automated release for $CI_COMMIT_TAG'
+    assets:
+      links:
+        - name: 'gcli'
+          link_type: other # binary
+          url: "${PACKAGE_REGISTRY_URL}"
\ No newline at end of file
-- 
GitLab