From 8083a1fcc37d9819aa92f8c2ad4e9a4be99cd6f1 Mon Sep 17 00:00:00 2001 From: siimav Date: Tue, 18 Jun 2024 02:31:49 +0300 Subject: [PATCH] Add automatic assembly versioning --- .../workflows/attach-release-artifacts.yml | 49 ++++++++++----- .github/workflows/build.yml | 60 ++++++++++--------- GameData/RealAntennas/changelog.cfg | 7 +++ .../Properties/AssemblyInfo.cs | 13 ++-- src/RealAntennasProject/RealAntennas.csproj | 8 +-- 5 files changed, 88 insertions(+), 49 deletions(-) diff --git a/.github/workflows/attach-release-artifacts.yml b/.github/workflows/attach-release-artifacts.yml index 6b0f446..c3f25f3 100644 --- a/.github/workflows/attach-release-artifacts.yml +++ b/.github/workflows/attach-release-artifacts.yml @@ -22,22 +22,44 @@ jobs: with: fetch-depth: 0 ref: ${{ env.tagged_branch }} + + - name: Download required assemblies + id: download-assemblies + uses: KSP-RO/BuildTools/download-assemblies@master + with: + KSP_ZIP_PASSWORD: ${{ secrets.KSP_ZIP_PASSWORD }} - - name: Download artifact - id: download-artifact - uses: dawidd6/action-download-artifact@v5 + # Install .NET SDKs + - name: Setup .NET Core 3.1 + uses: actions/setup-dotnet@v1 with: - commit: ${{ github.sha }} - workflow: build.yml - name: RealAntennas - skip_unpack: true + dotnet-version: 3.1.x + - name: Setup .NET 5.0 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 5.0.x + + - 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: Build mod solution + run: | + msbuild ${GITHUB_WORKSPACE}/src/RealAntennasProject.sln /t:build /restore /p:RestorePackagesConfig=true /p:Configuration=Release /p:ReferencePath="${{ steps.download-assemblies.outputs.ksp-dll-path }}" + - name: Remove excess DLLs + uses: KSP-RO/BuildTools/remove-excess-dlls@master + with: + path: ${GITHUB_WORKSPACE}/GameData/ + - name: Update version file uses: KSP-RO/BuildTools/update-version-file@master with: tag: ${{ github.event.release.tag_name }} path: ${GITHUB_WORKSPACE}/GameData/RealAntennas/RealAntennas.version - + - name: Update changelog file uses: KSP-RO/BuildTools/process-changelog@master with: @@ -53,18 +75,17 @@ jobs: echo "Release zip: ${RELEASE_DIR}/RealAntennas-${{ github.event.release.tag_name }}.zip" mkdir -v "${RELEASE_DIR}" echo "::set-output name=release-dir::${RELEASE_DIR}" - cp -v -R "${GITHUB_WORKSPACE}/GameData" "${RELEASE_DIR}" + cp -v -R "${GITHUB_WORKSPACE}/GameData/RealAntennas" "${RELEASE_DIR}" cd ${RELEASE_DIR} - zip -r RealAntennas-${{ github.event.release.tag_name }}.zip GameData - ls -lrt -d -1 "${RELEASE_DIR}"/{*,.*} - + zip -r RealAntennas-${{ github.event.release.tag_name }}.zip RealAntennas + - name: Upload package to release uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ github.event.release.upload_url }} - asset_path: ./RealAntennas.zip + asset_path: ${{ steps.assemble-release.outputs.release-dir }}/RealAntennas-${{ github.event.release.tag_name }}.zip asset_name: RealAntennas-${{ github.event.release.tag_name }}.zip asset_content_type: application/zip @@ -72,7 +93,7 @@ jobs: run: | git config user.name "GitHub Actions Bot" git config user.email "<>" - + - name: Commit changes shell: bash env: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 87cf88a..ab186bd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,22 +2,16 @@ name: build on: push: - branches: [ master ] + branches: [ master, CI ] pull_request: branches: [ master ] workflow_dispatch: jobs: check-secret: - runs-on: ubuntu-latest - outputs: - has-password: ${{ steps.has-password.outputs.defined }} - steps: - - id: has-password - if: "${{ env.KSP_ZIP_PASSWORD != '' }}" - run: echo "::set-output name=defined::true" - env: - KSP_ZIP_PASSWORD: ${{ secrets.KSP_ZIP_PASSWORD }} + uses: KSP-RO/BuildTools/.github/workflows/check-secret.yml@master + secrets: + KSP_ZIP_PASSWORD: ${{ secrets.KSP_ZIP_PASSWORD }} validate-cfg-files: runs-on: ubuntu-latest steps: @@ -28,7 +22,7 @@ jobs: - name: Validate config files uses: KSP-CKAN/KSPMMCfgParser@master build: - runs-on: windows-latest + runs-on: ubuntu-latest needs: [check-secret] if: needs.check-secret.outputs.has-password == 'true' steps: @@ -36,37 +30,49 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 100 + - name: Download required assemblies id: download-assemblies - shell: pwsh - env: + uses: KSP-RO/BuildTools/download-assemblies@master + with: KSP_ZIP_PASSWORD: ${{ secrets.KSP_ZIP_PASSWORD }} - run: | - Invoke-WebRequest https://ksp-ro.s3-us-west-2.amazonaws.com/KSPAssemblies-1.12.zip -OutFile KSP_Assemblies.zip - $KSP_DLL_PATH="${env:GITHUB_WORKSPACE}/KSP_Assemblies" - echo "::set-output name=ksp-dll-path::${KSP_DLL_PATH}" - mkdir -p "${KSP_DLL_PATH}" - 7z.exe x "-p${env:KSP_ZIP_PASSWORD}" 'KSP_Assemblies.zip' "-o${KSP_DLL_PATH}" - rm 'KSP_Assemblies.zip' + + # Install .NET SDKs + - name: Setup .NET Core 3.1 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 3.1.x + - name: Setup .NET 5.0 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 5.0.x - - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v2 + - name: Update AssemblyInfo + uses: KSP-RO/BuildTools/update-assembly-info@master + with: + path: ${GITHUB_WORKSPACE}/src/RealAntennasProject/Properties/AssemblyInfo.cs + tag: "2.99.0.0" - name: Build mod solution run: | - msbuild /p:Configuration=Release /p:ReferencePath="${{ steps.download-assemblies.outputs.ksp-dll-path }}" ${env:GITHUB_WORKSPACE}/src/RealAntennasProject.sln + msbuild ${GITHUB_WORKSPACE}/src/RealAntennasProject.sln /t:build /restore /p:RestorePackagesConfig=true /p:Configuration=Release /p:ReferencePath="${{ steps.download-assemblies.outputs.ksp-dll-path }}" + + - name: Remove excess DLLs + uses: KSP-RO/BuildTools/remove-excess-dlls@master + with: + path: ${GITHUB_WORKSPACE}/GameData/ - name: Assemble release id: assemble-release run: | - $RELEASE_DIR="${env:RUNNER_TEMP}/release" + RELEASE_DIR="${RUNNER_TEMP}/release" echo "Release dir: ${RELEASE_DIR}" - mkdir "${RELEASE_DIR}" + mkdir -v "${RELEASE_DIR}" echo "::set-output name=release-dir::${RELEASE_DIR}" - cp "${env:GITHUB_WORKSPACE}/GameData/RealAntennas" "${RELEASE_DIR}" -Recurse + cp -v -R "${GITHUB_WORKSPACE}/GameData/RealAntennas" "${RELEASE_DIR}" - name: Upload artifacts uses: actions/upload-artifact@v1 with: name: RealAntennas - path: ${{ steps.assemble-release.outputs.release-dir }} \ No newline at end of file + path: ${{ steps.assemble-release.outputs.release-dir }} diff --git a/GameData/RealAntennas/changelog.cfg b/GameData/RealAntennas/changelog.cfg index e69de29..d812611 100644 --- a/GameData/RealAntennas/changelog.cfg +++ b/GameData/RealAntennas/changelog.cfg @@ -0,0 +1,7 @@ +KERBALCHANGELOG +{ + modName = RealAntennas + license = CC-BY-SA 4.0 + author = DRVeyl, KSP-RO team + website = github.com/KSP-RO/RealAntennas +} \ No newline at end of file diff --git a/src/RealAntennasProject/Properties/AssemblyInfo.cs b/src/RealAntennasProject/Properties/AssemblyInfo.cs index 75a809a..38988fc 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,7 +33,12 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("2.4.0.0")] -[assembly: AssemblyFileVersion("2.4.0.0")] -[assembly: KSPAssembly("RealAntennas", 2, 4)] +#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 [assembly: KSPAssemblyDependency("ClickThroughBlocker", 1, 8)] diff --git a/src/RealAntennasProject/RealAntennas.csproj b/src/RealAntennasProject/RealAntennas.csproj index ae38e54..2822697 100644 --- a/src/RealAntennasProject/RealAntennas.csproj +++ b/src/RealAntennasProject/RealAntennas.csproj @@ -18,7 +18,7 @@ true portable false - bin\Debug\ + ..\..\GameData\RealAntennas\Plugins\ TRACE;DEBUG;ENABLE_PROFILER; ENABLE_MORE_CONTAINER_SUPPORT prompt 4 @@ -29,7 +29,7 @@ pdbonly true - bin\Release\ + ..\..\GameData\RealAntennas\Plugins\ TRACE prompt 4 @@ -108,7 +108,7 @@ - xcopy /Y "$(TargetDir)$(TargetName).*" "$(TargetDir)..\..\..\..\GameData\RealAntennas\Plugins\" - + + \ No newline at end of file