From f7a08c4ac87440804c2d18171f2d5627366c2130 Mon Sep 17 00:00:00 2001
From: siimav <siim.aaver@gmail.com>
Date: Tue, 18 Jun 2024 02:31:49 +0300
Subject: [PATCH] Add automatic assembly versioning

---
 .github/workflows/build.yml                        |  8 +++++++-
 src/RealAntennasProject/Properties/AssemblyInfo.cs | 12 +++++++++---
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 87cf88a..c788ba7 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -2,7 +2,7 @@ name: build
 
 on:
   push:
-    branches: [ master ]
+    branches: [ master, CI ]
   pull_request:
     branches: [ master ]
   workflow_dispatch:
@@ -49,6 +49,12 @@ jobs:
           7z.exe x "-p${env:KSP_ZIP_PASSWORD}" 'KSP_Assemblies.zip' "-o${KSP_DLL_PATH}"
           rm 'KSP_Assemblies.zip'
 
+      - name: Update AssemblyInfo
+        uses: KSP-RO/BuildTools/update-assembly-info@master
+        with:
+          path: ${GITHUB_WORKSPACE}/src/RealAntennasProject/Properties/AssemblyInfo.cs
+          tag: ${{ github.event.release.tag_name }}
+
       - name: Add msbuild to PATH
         uses: microsoft/setup-msbuild@v2
 
diff --git a/src/RealAntennasProject/Properties/AssemblyInfo.cs b/src/RealAntennasProject/Properties/AssemblyInfo.cs
index fb01dc1..e22535f 100644
--- a/src/RealAntennasProject/Properties/AssemblyInfo.cs
+++ b/src/RealAntennasProject/Properties/AssemblyInfo.cs
@@ -1,5 +1,5 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
+#define CIBUILD_disabled
+using System.Reflection;
 using System.Runtime.InteropServices;
 
 // General Information about an assembly is controlled through the following
@@ -33,4 +33,10 @@
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
 [assembly: AssemblyVersion("2.1.0.0")]
-[assembly: AssemblyFileVersion("2.1.1.0")]
+#if CIBUILD
+[assembly: AssemblyFileVersion("@MAJOR@.@MINOR@.@PATCH@.@BUILD@")]
+[assembly: KSPAssembly("RealAntennas", @MAJOR@, @MINOR@)]
+#else
+[assembly: AssemblyFileVersion("2.99.0.0")]
+[assembly: KSPAssembly("RealAntennas", 2, 99)]
+#endif