From e8cd5205e89993df357410c245f99ebb7703958d Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Thu, 31 Aug 2023 15:53:56 -0400
Subject: [PATCH] SL-19243: Try to run Windows BugSplat uploads as a separate
 GH job.

Upload a new Windows-exe artifact containing just the executable (needed by
BugSplat) separately from the artifact containing the whole NSIS installer.
This requires a new viewer_exe step output set by viewer_manifest.py.

Define viewer_channel and viewer_version as build job outputs.

Set viewer_channel in build.yaml when tag is interpreted.

Set viewer_version in build.sh at the point when it would have posted
viewer_version.txt to codeticket.

Add a post-windows-symbols job dependent on the build job that engages
secondlife/viewer-post-bugsplat-windows, which in turn engages
secondlife/post-bugsplat-windows. We keep the actual upload code in a separate
repo in case we need to modify that code before rerunning to resolve upload
errors. If we kept the upload code in the viewer repo itself, rerunning the
upload with modifications would necessarily require rerunning the viewer
build, which would defeat the purpose of SL-19243.

Because of that new upload job in build.yaml, skip Windows symbol uploads
in build.sh.

Use a simple (platform name) artifact name for metadata because of
flatten_files.py's filename collision resolution.

Use hyphens, not spaces, in remaining artifact names: apparently
download-artifact doesn't much like artifacts with spaces in their names.

Only run the release job when in fact there's a tag. Without that, we get
errors. We need not create flatten_files.py's output directory beforehand
because it will do that implicitly.
---
 .github/workflows/build.yaml     | 45 ++++++++++++++++++++++++--------
 build.sh                         | 24 ++++++++++-------
 indra/newview/viewer_manifest.py |  6 +++++
 3 files changed, 55 insertions(+), 20 deletions(-)

diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index d62b6403694..ad5925d2663 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -19,9 +19,8 @@ jobs:
             developer_dir: "/Applications/Xcode_14.0.1.app/Contents/Developer"
     runs-on: ${{ matrix.runner }}
     outputs:
-      # pass these from build job to release job
-      installer: ${{ steps.build.outputs.installer }}
-      metadata: ${{ steps.build.outputs.metadata }}
+      viewer_channel: ${{ steps.build.outputs.viewer_channel }}
+      viewer_version: ${{ steps.build.outputs.viewer_version }}
     env:
       AUTOBUILD_ADDRSIZE: 64
       AUTOBUILD_BUILD_ID: ${{ github.run_id }}
@@ -175,6 +174,7 @@ jobs:
                export viewer_channel="${viewer_channel//_/ }"
           else export viewer_channel="Second Life Test"
           fi
+          echo "viewer_channel=$viewer_channel" >> "$GITHUB_OUTPUT"
 
           # On windows we need to point the build to the correct python
           # as neither CMake's FindPython nor our custom Python.cmake module
@@ -207,24 +207,37 @@ jobs:
       - name: Upload installer
         uses: actions/upload-artifact@v3
         with:
-          name: "${{ steps.build.outputs.artifact }} installer"
+          name: "${{ steps.build.outputs.artifact }}-installer"
           # emitted by build.sh, possibly multiple lines
           path: |
             ${{ steps.build.outputs.installer }}
 
+      - name: Upload executable
+        uses: actions/upload-artifact@v3
+        with:
+          name: "${{ steps.build.outputs.artifact }}-exe
+          if: steps.build.outputs.viewer_exe
+          path: ${{ steps.build.outputs.viewer_exe }}
+
       # The other upload of nontrivial size is the symbol file. Use a distinct
       # artifact for that too.
       - name: Upload symbol file
         uses: actions/upload-artifact@v3
         with:
-          name: "${{ steps.build.outputs.artifact }} symbols"
+          name: "${{ steps.build.outputs.artifact }}-symbols"
           path: |
             ${{ steps.build.outputs.symbolfile }}
 
       - name: Upload metadata
         uses: actions/upload-artifact@v3
         with:
-          name: "${{ steps.build.outputs.artifact }} metadata"
+          # Call this artifact just "Windows" or "macOS" because it's the only
+          # artifact in which we expect files from both platforms with
+          # colliding names (e.g. autobuild-package.xml). Our flatten_files.py
+          # (see release step) resolves collisions by prepending the artifact
+          # name, so when we anticipate collisions, it's good to keep the
+          # artifact name short and sweet.
+          name: "${{ steps.build.outputs.artifact }}"
           # emitted by build.sh, possibly multiple lines
           path: |
             ${{ steps.build.outputs.metadata }}
@@ -234,15 +247,28 @@ jobs:
         # should only be set for viewer-private
         if: steps.build.outputs.physicstpv
         with:
-          name: "${{ steps.build.outputs.artifact }} physics"
+          name: "${{ steps.build.outputs.artifact }}-physics"
           # emitted by build.sh, zero or one lines
           path: |
             ${{ steps.build.outputs.physicstpv }}
 
+  post-windows-symbols:
+    needs: build
+    runs-on: ubuntu-latest
+    steps:
+      - name: Post windows symbols
+        uses: secondlife/viewer-post-bugsplat-windows
+        with:
+          username: ${{ secrets.BUGSPLAT_USER }}
+          password: ${{ secrets.BUGSPLAT_PASS }}
+          database: "SecondLife_Viewer_2018"
+          channel: ${{ needs.build.outputs.viewer_channel }}
+          version: ${{ needs.build.outputs.viewer_version }}
+
   release:
     needs: build
     runs-on: ubuntu-latest
-    ##if: github.ref_type == 'tag' && startsWith(github.ref_name, 'Second_Life_')
+    if: github.ref_type == 'tag' && startsWith(github.ref_name, 'Second_Life_')
     steps:
       - name: Checkout code
         uses: actions/checkout@v3
@@ -269,9 +295,6 @@ jobs:
       - name: Show what we downloaded
         run: ls -R artifacts
 
-      - name: Make output dir
-        run: mkdir assets
-
       - name: Reshuffle artifact files
         run: .github/workflows/flatten_files.py assets artifacts
 
diff --git a/build.sh b/build.sh
index 38f0a59fd54..4dda0800b65 100755
--- a/build.sh
+++ b/build.sh
@@ -420,9 +420,11 @@ do
               if [ -r "$build_dir/newview/viewer_version.txt" ]
               then
                   begin_section "Viewer Version"
-                  python_cmd "$helpers/codeticket.py" addoutput "Viewer Version" "$(<"$build_dir/newview/viewer_version.txt")" --mimetype inline-text \
+                  viewer_version="$(<"$build_dir/newview/viewer_version.txt")"
+                  python_cmd "$helpers/codeticket.py" addoutput "Viewer Version" "$viewer_version" --mimetype inline-text \
                       || fatal "Upload of viewer version failed"
                   metadata+=("$build_dir/newview/viewer_version.txt")
+                  echo "viewer_version=$viewer_version" >> "$GITHUB_OUTPUT"
                   end_section "Viewer Version"
               fi
               ;;
@@ -599,14 +601,18 @@ then
 
       # Run upload extensions
       # Ex: bugsplat
-      if [ -d ${build_dir}/packages/upload-extensions ]; then
-          for extension in ${build_dir}/packages/upload-extensions/*.sh; do
-              begin_section "Upload Extension $extension"
-              . $extension
-              [ $? -eq 0 ] || fatal "Upload of extension $extension failed"
-              wait_for_codeticket
-              end_section "Upload Extension $extension"
-          done
+      ## SL-19243 HACK: testing separate GH upload job on Windows
+      if [[ "$arch" != "CYGWIN" ]]
+      then
+          if [ -d ${build_dir}/packages/upload-extensions ]; then
+              for extension in ${build_dir}/packages/upload-extensions/*.sh; do
+                  begin_section "Upload Extension $extension"
+                  . $extension
+                  [ $? -eq 0 ] || fatal "Upload of extension $extension failed"
+                  wait_for_codeticket
+                  end_section "Upload Extension $extension"
+              done
+          fi
       fi
     fi
     end_section "Uploads"
diff --git a/indra/newview/viewer_manifest.py b/indra/newview/viewer_manifest.py
index 1e43485b9c1..6c4f8cb2d4d 100755
--- a/indra/newview/viewer_manifest.py
+++ b/indra/newview/viewer_manifest.py
@@ -480,6 +480,12 @@ def construct(self):
         if self.is_packaging_viewer():
             # Find secondlife-bin.exe in the 'configuration' dir, then rename it to the result of final_exe.
             self.path(src='%s/secondlife-bin.exe' % self.args['configuration'], dst=self.final_exe())
+            # emit that as one of the GitHub step outputs
+            GITHUB_OUTPUT = os.getenv('GITHUB_OUTPUT')
+            if GITHUB_OUTPUT:
+                exepath = os.path.join(self.get_dst_prefix(), self.final_exe())
+                with open(GITHUB_OUTPUT, 'a') as outf:
+                    print(f'viewer_exe={exepath}', file=outf)
 
             with self.prefix(src=os.path.join(pkgdir, "VMP")):
                 # include the compiled launcher scripts so that it gets included in the file_list
-- 
GitLab