From 665da1488ce58f45a9a7d96eb578c6f4a22afae7 Mon Sep 17 00:00:00 2001
From: Thomas Lambert <t.lambert@uliege.be>
Date: Sun, 27 Nov 2022 01:46:57 +0100
Subject: [PATCH] ci: automate releases

---
 .gitlab-ci.yml | 38 ++++++++++++++++++++++++++++++++++----
 .gitmodules    |  4 ++--
 CHANGELOG.md   |  8 +++++++-
 RELEASE.md     | 12 ++++++++++++
 4 files changed, 55 insertions(+), 7 deletions(-)
 create mode 100644 RELEASE.md

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 304b6e6..6f41afb 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -3,42 +3,72 @@
 #   1. Ensure code quality
 #   2. Generate releases automatically
 
+variables:
+  GIT_SUBMODULE_STRATEGY: normal
+  PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}"
 
 # Using the official Python Docker image as default
 default:
   image: python
+
+# Install miss_hit
+.miss_hit: &miss_hit
   before_script:
     - pip install miss_hit
 
 # Pipeline stages
 stages:
   - static analysis
+  - package
   - release
 
 # Static code analysis jobs via MISS_HIT
 style_check:
+  <<: *miss_hit
   stage: static analysis
   script:
     - mh_style . --fix
 
 metric_check:
+  <<: *miss_hit
   stage: static analysis
   script:
     - mh_metric . --ci
 
 lint_check:
+  <<: *miss_hit
   stage: static analysis
   script:
     - mh_lint .
 
-# TODO: Use git-archive-all and bake an archive that includes submodules
-release_job:
+# Create an archive of the code and its submodules
+archive_all:
+  stage: package
+  rules:
+    - if: $CI_COMMIT_TAG
+  before_script:
+    - pip install git-archive-all
+  script:
+    - echo "Packaging source with submodules"
+    - git-archive-all --force-submodules "${CI_PROJECT_NAME}-${CI_COMMIT_TAG}.zip"
+    - 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file "${CI_PROJECT_NAME}-${CI_COMMIT_TAG}.zip" "${PACKAGE_REGISTRY_URL}/${CI_COMMIT_TAG}/${CI_PROJECT_NAME}-${CI_COMMIT_TAG}.zip"'
+    - git-archive-all --force-submodules "${CI_PROJECT_NAME}-${CI_COMMIT_TAG}.tar.gz"
+    - 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file "${CI_PROJECT_NAME}-${CI_COMMIT_TAG}.tar.gz" "${PACKAGE_REGISTRY_URL}/${CI_COMMIT_TAG}/${CI_PROJECT_NAME}-${CI_COMMIT_TAG}.tar.gz"'
+
+make_release:
   stage: release
   image: registry.gitlab.com/gitlab-org/release-cli:latest
+  needs: ["archive_all"]
   rules:
-    - if: $CI_COMMIT_TAG  # Run when we create a new tag
+    - if: $CI_COMMIT_TAG
   script:
     - echo "Running release_job for $TAG"
   release:
     tag_name: '$CI_COMMIT_TAG'
-    description: 'Automatic release for version $CI_COMMIT_TAG'
+    description: ./RELEASE.md
+    assets:
+      links:
+        - name: 'COMPLETE CODE: ${CI_PROJECT_NAME}-${CI_COMMIT_TAG}.zip'
+          url: "${PACKAGE_REGISTRY_URL}/${CI_COMMIT_TAG}/${CI_PROJECT_NAME}-${CI_COMMIT_TAG}.zip"
+        - name: 'COMPLETE CODE: ${CI_PROJECT_NAME}-${CI_COMMIT_TAG}.tar.gz'
+          url: "${PACKAGE_REGISTRY_URL}/${CI_COMMIT_TAG}/${CI_PROJECT_NAME}-${CI_COMMIT_TAG}.tar.gz"
diff --git a/.gitmodules b/.gitmodules
index 2b337fa..d6a9b88 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,6 +1,6 @@
 [submodule "validation/rotor-db"]
 	path = validation/rotor-db
-	url = git@gitlab.uliege.be:thlamb/rotor-db.git
+	url = ../rotor-db.git
 [submodule "src/libs/matlab_airfoil_toolbox"]
 	path = src/libs/matlab_airfoil_toolbox
-	url = git@gitlab.uliege.be:am-dept/matlab_airfoil_toolbox
+	url = ../../am-dept/matlab_airfoil_toolbox
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0effe60..f65bade 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,12 @@ _Initial commit_: single rotor in hover/axial flows
 
 ### Fixed
 
+## [0.0.0] - 2022-11-27
+
+_Initial commit_: single rotor in hover/axial flows
+
 [sem_ver]:<https://semver.org/spec/v2.0.0.html>
 [keep_chglog]: <https://keepachangelog.com/en/1.0.0/>
-[Unreleased]: https://gitlab.uliege.be/thlamb/rotare
+
+[Unreleased]: https://gitlab.uliege.be/thlamb/rotare/compare/0.0.0...main
+[0.0.0]: https://gitlab.uliege.be/thlamb/rotare/releases/tag/0.0.0
diff --git a/RELEASE.md b/RELEASE.md
new file mode 100644
index 0000000..5a3660a
--- /dev/null
+++ b/RELEASE.md
@@ -0,0 +1,12 @@
+## Download
+
+**WARNING**: Download the archive titled `COMPLETE CODE: rotare-<version>`
+linked above, not the _source code_ ones. The latter are automatically generated
+and do not contain all dependencies.
+
+## About this release
+
+_Initial commit_.
+
+- Single rotor in hover/axial flows
+- NOT YET VALIDATED
-- 
GitLab