From a96a923ebd5135ab45cb14b5bca64e21a2471a9a Mon Sep 17 00:00:00 2001
From: Tim Jaacks <tim.jaacks@seco.com>
Date: Mon, 21 Nov 2022 17:38:30 +0100
Subject: [PATCH] CI-test: add deploy stages for SoftwareStore and FTP

Rename all stages to uppercase on this occasion, since we're adding
stages with names containing multiple words.
---
 build-common.yml              | 19 +++++++
 build-jobs-ci-test.yml.jinja2 | 94 +++++++++++++++++++++++++++++------
 scripts/package_release.py    |  1 +
 3 files changed, 100 insertions(+), 14 deletions(-)

diff --git a/build-common.yml b/build-common.yml
index 491ad846..72826c1e 100644
--- a/build-common.yml
+++ b/build-common.yml
@@ -161,3 +161,22 @@ workflow:
         --sdk-dir=${BUILD_PATH_SDK} \
         --output-dir=release
         --release-suffix="${RELEASE_SUFFIX}"
+
+# --------------------------------------------------------------------------------------
+# Stage: deploy
+# --------------------------------------------------------------------------------------
+.deploy:
+  tags:
+    - deploy
+  rules:
+    - when: manual
+      allow_failure: true
+  image: instrumentisto/rsync-ssh:alpine3.16-r4
+  variables:
+    DEPLOY_SOURCE:
+    DEPLOY_TARGET:
+    DEPLOY_TARGET_LINK:
+  script:
+    - rsync -rvhP --mkpath ${DEPLOY_SOURCE} ${DEPLOY_TARGET}
+    - printf "Sucessfully deployed to:\n%s" "${DEPLOY_TARGET_LINK}"
+  timeout: 60m
diff --git a/build-jobs-ci-test.yml.jinja2 b/build-jobs-ci-test.yml.jinja2
index adce5478..f1403b4d 100644
--- a/build-jobs-ci-test.yml.jinja2
+++ b/build-jobs-ci-test.yml.jinja2
@@ -12,12 +12,14 @@ include:
       - common.yml
 
 stages:
-  - build
-  - test
-  - package
+  - Build
+  - Test
+  - Package
+  - Deploy SoftwareStore
+  - Deploy FTP
 
 # --------------------------------------------------------------------------------------
-# Stage: build
+# Stage: Build
 # --------------------------------------------------------------------------------------
 .build: &build
   - cd ${CI_PROJECT_DIR}
@@ -33,7 +35,7 @@ stages:
   - (($DIFF >= -1 && $DIFF <= 1))
 
 build:files:
-  stage: build
+  stage: Build
   extends:
     - .buildbase
   tags:
@@ -53,7 +55,7 @@ build:files:
       - files-*
 
 build:echo:
-  stage: build
+  stage: Build
   tags:
     - infrastructure
   timeout: 2m
@@ -63,7 +65,7 @@ build:echo:
     - echo "Build successful"
 
 build:check-foo-branch:
-  stage: build
+  stage: Build
   extends:
     - .buildbase
   tags:
@@ -84,7 +86,7 @@ build:check-foo-branch:
     fi
 
 .simulate-build:
-  stage: build
+  stage: Build
   extends:
     - .buildbase
   tags:
@@ -128,10 +130,10 @@ simulate-buildsdk-seco-mx6:
       - build.env
 
 # --------------------------------------------------------------------------------------
-# Stage: test
+# Stage: Test
 # --------------------------------------------------------------------------------------
 .test_simple:
-  stage: test
+  stage: Test
   rules:
     - when: manual
       allow_failure: true
@@ -156,7 +158,7 @@ test:fail:
 smoketest:seco-mx6:
   extends:
     - .test
-  stage: test
+  stage: Test
   needs: [simulate-build-seco-mx6]
   variables:
     TEST_REPO_BRANCH: dunfell
@@ -166,16 +168,80 @@ smoketest:seco-mx6:
     CI_PARAM_BUILDJOB: simulate-build-seco-mx6
 
 # --------------------------------------------------------------------------------------
-# Stage: package
+# Stage: Package
 # --------------------------------------------------------------------------------------
 package-seco-mx6:
   extends: .package-release
-  stage: package
+  stage: Package
   needs:
     - simulate-build-seco-mx6
 
 package-sdk-seco-mx6:
   extends: .package-sdk
-  stage: package
+  stage: Package
   needs:
     - simulate-buildsdk-seco-mx6
+
+# --------------------------------------------------------------------------------------
+# Stage: Deploy SoftwareStore
+# --------------------------------------------------------------------------------------
+.deploy-software-store:
+  extends: .deploy
+  stage: Deploy SoftwareStore
+  variables:
+    # env variables are available via package.env from package job
+    DEPLOY_SOURCE: release/${RELEASE_NAME}
+    DEPLOY_TARGET: /artifacts-yocto/Test
+    DEPLOY_TARGET_LINK: Z:\Development\SoftwareStore\Linux-Yocto\Test\${RELEASE_NAME}
+
+deploy-files:
+  extends: .deploy-software-store
+  variables:
+    GIT_STRATEGY: none
+    DEPLOY_SOURCE: .
+    DEPLOY_TARGET: /artifacts-yocto/Test/${CI_JOB_ID}
+    DEPLOY_TARGET_LINK: Z:\Development\SoftwareStore\Linux-Yocto\Test\${CI_JOB_ID}
+  needs:
+    - build:files
+
+deploy-seco-mx6:
+  extends: .deploy-software-store
+  needs:
+    - package-seco-mx6
+
+deploy-sdk-seco-mx6:
+  extends: .deploy-software-store
+  needs:
+    - package-sdk-seco-mx6
+
+# --------------------------------------------------------------------------------------
+# Stage: Deploy FTP
+# --------------------------------------------------------------------------------------
+.deploy-ftp:
+  extends: .deploy
+  stage: Deploy FTP
+  variables:
+    # env variables are available via package.env from package job
+    DEPLOY_SOURCE: release/${RELEASE_NAME}
+    DEPLOY_TARGET: /artifacts-ftp-yocto/Test
+    DEPLOY_TARGET_LINK: http://support.garz-fricke.com/projects/Linux-Yocto/Test/${RELEASE_NAME}
+
+ftp-files:
+  extends: .deploy-ftp
+  variables:
+    GIT_STRATEGY: none
+    DEPLOY_SOURCE: .
+    DEPLOY_TARGET: /artifacts-ftp-yocto/Test/${CI_JOB_ID}
+    DEPLOY_TARGET_LINK: http://support.garz-fricke.com/projects/Linux-Yocto/Test/${CI_JOB_ID}
+  needs:
+    - build:files
+
+ftp-seco-mx6:
+  extends: .deploy-ftp
+  needs:
+    - package-seco-mx6
+
+ftp-sdk-seco-mx6:
+  extends: .deploy-ftp
+  needs:
+    - package-sdk-seco-mx6
diff --git a/scripts/package_release.py b/scripts/package_release.py
index e9df558d..8978a847 100755
--- a/scripts/package_release.py
+++ b/scripts/package_release.py
@@ -220,6 +220,7 @@ def main():
 
     # Store pathes and other stuff in environment variable file
     with open("package.env", "w", encoding="utf-8") as env_file:
+        env_file.write("RELEASE_NAME={}\n".format(release_name))
         env_file.write("VERSION={}\n".format(version))
         env_file.write("MACHINE={}\n".format(machine))
 
-- 
GitLab