File 0721-gh-Upload-Windows-build-zip-to-GitHub-releases.patch of Package erlang

From 60129fd2a9ebb197cef51d6f78403ea9fc94b6bb Mon Sep 17 00:00:00 2001
From: Wojtek Mach <wojtek@wojtekmach.pl>
Date: Thu, 5 Sep 2024 15:08:31 +0200
Subject: [PATCH] gh: Upload Windows build zip to GitHub releases

---
 .github/scripts/sync-github-releases.sh   | 15 +++++
 .github/workflows/upload-windows-zip.yaml | 71 +++++++++++++++++++++++
 erts/etc/win32/INSTALL.txt                | 10 ++++
 3 files changed, 96 insertions(+)
 create mode 100644 .github/workflows/upload-windows-zip.yaml
 create mode 100644 erts/etc/win32/INSTALL.txt

diff --git a/.github/scripts/sync-github-releases.sh b/.github/scripts/sync-github-releases.sh
index d43857a938..c6dc35f999 100755
--- a/.github/scripts/sync-github-releases.sh
+++ b/.github/scripts/sync-github-releases.sh
@@ -137,6 +137,8 @@ while [ "${TAG_URL}" != "" ]; do
                     *)
                         _asset "otp_win32_${stripped_name}.exe"
                         _asset "otp_win64_${stripped_name}.exe"
+                        _asset "otp_win32_${stripped_name}.zip"
+                        _asset "otp_win64_${stripped_name}.zip"
                         ;;
                 esac
             fi
@@ -218,6 +220,9 @@ UPLOADED=false
 ## Array of all tags that do not have a pre-build
 MISSING_PREBUILD=()
 
+## Array of zip files that have been triggered this sync
+MISSING_WIN_ZIP=()
+
 _upload_artifacts() {
     local name=${1};
     local stripped_name=""
@@ -235,6 +240,14 @@ _upload_artifacts() {
                        "${UPLOAD_URL}?name=${1}" \
                        --data-binary "@downloads/${1}"
         else
+            ## See if we need to trigger any .exe to .zip convertions
+            if echo "${RI[@]}" | grep "otp_${2}_${stripped_name}.zip" > /dev/null; then
+                if [ ${#MISSING_WIN_ZIP[@]} -lt 20 ]; then
+                    MISSING_WIN_ZIP=("${MISSING_WIN_ZIP[@]}" "${stripped_name}")
+                    _curl_post "${REPO}/actions/workflows/upload-windows-zip.yaml/dispatches" -d '{"version":"'"${stripped_name}"'", "target":"'"${2}"'"}'
+                fi
+            fi
+            ## See if we need to re-build any prebuilds
             if echo "${RI[@]}" | grep "${stripped_name}.tar.gz" > /dev/null; then
                 MISSING_PREBUILD=("${MISSING_PREBUILD[@]}" "${name}")
             fi
@@ -247,6 +260,8 @@ _upload_artifacts() {
     _upload "otp_doc_man_${stripped_name}.tar.gz" "application/gzip"
     _upload "otp_win32_${stripped_name}.exe" "application/x-msdownload"
     _upload "otp_win64_${stripped_name}.exe" "application/x-msdownload"
+    _upload "otp_win32_${stripped_name}.zip" "win32"
+    _upload "otp_win64_${stripped_name}.zip" "win64"
     }
 
 ## Upload all assets for tags
diff --git a/.github/workflows/upload-windows-zip.yaml b/.github/workflows/upload-windows-zip.yaml
new file mode 100644
index 0000000000..701423b785
--- /dev/null
+++ b/.github/workflows/upload-windows-zip.yaml
@@ -0,0 +1,71 @@
+name: Upload windows .zip
+
+on:
+  workflow_dispatch:
+    inputs:
+      version:
+        required: true
+      target:
+        required: true
+
+## Needed to upload assets to releases
+permissions:
+  contents: write
+
+jobs:
+  upload-windows-zip:
+    runs-on: windows-2022
+    env:
+      basename: otp_${{ inputs.target }}_${{ inputs.version }}
+    steps:
+      - uses: actions/checkout@v4.1.7
+
+      - name: Install OTP
+        shell: cmd
+        run: |
+          curl.exe --fail -Lo otp.exe https://github.com/erlang/otp/releases/download/OTP-${{ inputs.version }}/${{ env.basename }}.exe
+          otp.exe /S /D=%CD%\${{ env.basename }}
+
+      - name: Download vc_redist.exe
+        shell: bash
+        run: |
+          case "${{ inputs.target }}" in
+            win32)
+              vc_redist_target=x86
+              ;;
+            win64)
+              vc_redist_target=x64
+              ;;
+            *)
+              echo "invalid target $target"
+              exit 1
+              ;;
+          esac
+          curl --fail -Lo vc_redist.exe "https://aka.ms/vs/17/release/vc_redist.$vc_redist_target.exe"
+
+      - name: Create .zip
+        shell: pwsh
+        run: |
+          $root = Get-Location
+
+          cd ${{ env.basename }}
+          rm bin\erl.ini
+          rm Install.exe
+          rm Install.ini
+          rm Uninstall.exe
+          $sha256 = Get-FileHash $root\otp.exe -Algorithm SHA256
+          $sha256.Hash.ToLower() | Out-File -FilePath installer.sha256
+          cp $root/vc_redist.exe .
+          cp $root/erts/etc/win32/INSTALL.txt .
+          Compress-Archive -Path * -DestinationPath $root\${{ env.basename }}.zip
+
+          cd $root
+          Expand-Archive -Path ${{ env.basename }}.zip -DestinationPath .\otp_test
+          .\otp_test\bin\erl.exe +V
+
+      - name: Upload
+        shell: pwsh
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        run: |
+          gh release upload -R $env:GITHUB_REPOSITORY --clobber OTP-${{ inputs.version }} ${{ env.basename }}.zip
diff --git a/erts/etc/win32/INSTALL.txt b/erts/etc/win32/INSTALL.txt
new file mode 100644
index 0000000000..2ad9c53929
--- /dev/null
+++ b/erts/etc/win32/INSTALL.txt
@@ -0,0 +1,10 @@
+Welcome to Erlang/OTP!
+
+This Erlang installation requires "Microsoft Visual C++ Redistributable". Unless it is already
+present on your system, you can install vc_redist.exe that is included with this installation.
+For scripts, CIs, etc you may want to install it in "passive" mode:
+
+    .\vc_redist.exe /install /quiet /norestart
+
+For an installation that is more integrated with Windows (Adds Erlang to Start menu, Add/Remove
+Programs, etc), download a "Windows installer" from https://www.erlang.org/downloads.
-- 
2.43.0

openSUSE Build Service is sponsored by