From d18f5688090bbe1bbb5910f06022b89c05e7f1b4 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nicolas.pope@utu.fi>
Date: Wed, 11 May 2022 11:39:15 +0100
Subject: [PATCH] Try automated releases

---
 .gitignore            |  5 ++++-
 .gitlab-ci.yml        | 25 +++++++++++++++++++++++--
 CMakeLists.txt        |  2 +-
 cmake/ftl_CPack.cmake |  1 +
 4 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/.gitignore b/.gitignore
index 3721ede..09a73bb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
 build
+*.deb
+*.zip
 **/config.cpp
-**/config.h
\ No newline at end of file
+**/config.h
+_CPack_Packages
\ No newline at end of file
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 18bd6da..8359363 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -11,6 +11,7 @@ stages:
   - build
   - test
   - pack
+  - release
 
 flawfinder-sast:
   stage: static
@@ -129,7 +130,7 @@ linux:pack:
   artifacts:
     when: always
     paths:
-      - build/*.deb
+      - *.deb
     expire_in: 1 week
 
 ### Windows
@@ -207,5 +208,25 @@ windows:pack:
   artifacts:
     when: always
     paths:
-      - build/*.zip
+      - *.zip
     expire_in: 1 week
+
+# Release
+
+release_job:
+  stage: release
+  rules:
+    - if: $CI_COMMIT_TAG                  # Run this job when a tag is created manually
+  script:
+    - echo "running release_job"
+  needs:
+    - job: windows:pack
+      artifacts: true
+    - job: linux:pack
+      artifacts: true
+  
+  release:
+    name: 'Release $CI_COMMIT_TAG'
+    description: 'Automatic CI Release'
+    tag_name: '$CI_COMMIT_TAG'                                       # elsewhere in the pipeline.
+    ref: '$CI_COMMIT_TAG'
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 03b0a70..14523cb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,7 +3,7 @@ include (CheckIncludeFile)
 include (CheckIncludeFileCXX)
 include (CheckFunctionExists)
 
-if (NOT FTL_VERSION OR FTL_VERSION STREQUAL "$Env:CI_COMMIT_TAG")
+if (NOT FTL_VERSION)
 	set(FTL_VERSION 0.0.1)
 endif()
 
diff --git a/cmake/ftl_CPack.cmake b/cmake/ftl_CPack.cmake
index 4726155..e340a26 100644
--- a/cmake/ftl_CPack.cmake
+++ b/cmake/ftl_CPack.cmake
@@ -2,6 +2,7 @@
 string(TIMESTAMP BUILD_TIME "%Y%m%d")
 set(CPACK_PACKAGE_VERSION_PATCH "${BUILD_TIME}")
 set(CPACK_PACKAGE_NAME "libftl-protocol")
+set(CPACK_PACKAGE_DIRECTORY "${CMAKE_SOURCE_DIR}")
 set(CPACK_DEBIAN_PACKAGE_NAME "FTL Protocol Library")
 set(CPACK_PACKAGE_VENDOR "University of Turku")
 set(CPACK_PACKAGE_DESCRIPTION "Networking and streaming library for FTL data")
-- 
GitLab