From 8d0240a4bf57ff5576aa6a4e5a8fe63f9b2e753d Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Tue, 18 Jul 2023 14:38:36 +0200
Subject: [PATCH] ci: Add windows release.

---
 .gitlab-ci.yml   | 43 ++++++++++++++++++++++++++++++++++++++++---
 packages/wine.sh | 10 ++++++++++
 2 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 9bb95f85..4de491db 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -33,8 +33,13 @@ test:
 
 linux-package:
   stage: release
+  tags:
+    - release
+    - linux
   rules:
     - if: $CI_COMMIT_BRANCH == 'master'
+    - if: $CI_COMMIT_TAG
+      when: never
   artifacts:
     paths:
       # - packages/pamhyr-src.tar.gz
@@ -43,16 +48,40 @@ linux-package:
     - cd packages
     - ./linux.sh
 
-tag-linux-release:
+windows-package:
+  stage: release
+  tags:
+    - release
+    - wine
+  rules:
+    - if: $CI_COMMIT_BRANCH == 'master'
+    - if: $CI_COMMIT_TAG
+      when: never
+  artifacts:
+    paths:
+      - packages/pamhyr-win-amd64.zip
+      - packages/pamhyr-win-amd64.exe
+  script:
+    - cd packages
+    - ./wine.sh ci
+
+tag-release:
   stage: release
+  tags:
+    - release
+    - linux
+    - wine
   rules:
     - if: $CI_COMMIT_TAG
   artifacts:
     paths:
       - packages/pamhyr-gnulinux-amd64.tar.xz
+      - packages/pamhyr-win-amd64.zip
+      - packages/pamhyr-win-amd64.exe
   script:
     - cd packages
     - ./linux.sh
+    - ./wine.sh ci
   release:
     name: '$CI_COMMIT_TAG-release'
     description: 'Automatic release from tag $CI_COMMIT_TAG'
@@ -60,7 +89,15 @@ tag-linux-release:
     ref: '$CI_COMMIT_SHA'
     assets:
       links:
-        - name: 'pamhyr-gnulinux-amd64'
+        - name: 'GNU/Linux amd64 (tar.xz)'
           url: '${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/raw/packages/pamhyr-gnulinux-amd64.tar.xz'
           filepath: '/packages/pamhyr-gnulinux-amd64.tar.xz'
-          link_type: 'other'
+          link_type: 'Packages'
+        - name: 'Windows amd64 (zip)'
+          url: '${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/raw/packages/pamhyr-win-amd64.zip'
+          filepath: '/packages/pamhyr-win-amd64.zip'
+          link_type: 'Packages'
+        - name: 'Windows amd64 (exe)'
+          url: '${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/raw/packages/pamhyr-win-amd64.exe'
+          filepath: '/packages/pamhyr-win-amd64.exe'
+          link_type: 'Packages'
diff --git a/packages/wine.sh b/packages/wine.sh
index 7febf68e..561716f7 100755
--- a/packages/wine.sh
+++ b/packages/wine.sh
@@ -4,6 +4,16 @@ echo " *** SETUP ENV"
 
 export WINARCH=win64
 
+if [ "$1" = "ci" ];
+then
+    # HACK: Set wine prefix for gitlab-ci runner
+    cp -rfv /home/parouby/git/pamhyr/packages/wine-pamhyr-build $PWD/wine-pamhyr-build
+    chown $USER -R $PWD/wine-pamhyr-build
+    chmod 755 $PWD/wine-pamhyr-build
+    export WINEPREFIX=$PWD/wine-pamhyr-build
+fi
+
+
 if [ -z $WINEPREFIX ];
 then
     # FIXME Not tested yet...
-- 
GitLab