From f9dd6b643770e70d3adb44b54a611d5db9bf74a6 Mon Sep 17 00:00:00 2001
From: stevereis <stevereis93@gmail.com>
Date: Thu, 23 Dec 2021 15:23:53 +0100
Subject: [PATCH] feat: Add release process in gitlab pipeline

Build and  release a new version along with a new docker image
---
 .gitlab-ci.yml | 41 +++++++++++++++++++++++++++++++----------
 1 file changed, 31 insertions(+), 10 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index a99622b..5581121 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,24 +1,45 @@
-image: docker:20
-services:
-  - docker:20-dind
-
 stages:
   - build
   - release
-  - deploy
 
-variables:
-  CONTAINER_BASE_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
+services:
+  - docker:dind
 
 before_script:
   - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
 
 build:
+  image: docker:dind
   stage: build
+  only:
+    refs:
+    - main
+    - develop
+    - rc
+    # This matches maintenance branches
+    - /^(([0-9]+)\.)?([0-9]+)\.x/
+    # This matches pre-releases
+    - /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/
   script:
-    - docker build -t $CONTAINER_BASE_IMAGE ./api
-    - docker push $CONTAINER_BASE_IMAGE
+    - docker build -t $CI_REGISTRY/$CI_PROJECT_PATH:pipeline-$CI_PIPELINE_ID ./api
+    - docker push $CI_REGISTRY/$CI_PROJECT_PATH:pipeline-$CI_PIPELINE_ID
+
+release:
+  image: docker:dind
+  stage: release
   only:
+    refs:
     - main
     - develop
-    - /^release-.*$/
+    - rc
+    # This matches maintenance branches
+    - /^(([0-9]+)\.)?([0-9]+)\.x/
+    # This matches pre-releases
+    - /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/
+  script:
+    - apk add --no-cache nodejs npm py3-pip python2 git
+    - docker pull $CI_REGISTRY/$CI_PROJECT_PATH:pipeline-$CI_PIPELINE_ID
+    - docker tag $CI_REGISTRY/$CI_PROJECT_PATH:pipeline-$CI_PIPELINE_ID gateway-semantic:latest
+    - cd ./api
+    - npm install @semantic-release/gitlab @semantic-release/changelog @eclass/semantic-release-docker
+    - npx semantic-release
\ No newline at end of file
-- 
GitLab