Skip to content

Commit

Permalink
Add automatic assembly versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav committed Jul 14, 2024
1 parent ef45ee1 commit 317ae17
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 48 deletions.
47 changes: 34 additions & 13 deletions .github/workflows/attach-release-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -55,24 +77,23 @@ jobs:
echo "::set-output name=release-dir::${RELEASE_DIR}"
cp -v -R "${GITHUB_WORKSPACE}/GameData" "${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 GameData/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

- name: Setup git config
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
- name: Commit changes
shell: bash
env:
Expand Down
60 changes: 33 additions & 27 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -28,45 +22,57 @@ 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:
- name: Checkout
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 }}
path: ${{ steps.assemble-release.outputs.release-dir }}
13 changes: 9 additions & 4 deletions src/RealAntennasProject/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)]
8 changes: 4 additions & 4 deletions src/RealAntennasProject/RealAntennas.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<OutputPath>..\..\GameData\RealAntennas\Plugins\</OutputPath>
<DefineConstants>TRACE;DEBUG;ENABLE_PROFILER; ENABLE_MORE_CONTAINER_SUPPORT</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand All @@ -29,7 +29,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<OutputPath>..\..\GameData\RealAntennas\Plugins\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand Down Expand Up @@ -108,7 +108,7 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy /Y "$(TargetDir)$(TargetName).*" "$(TargetDir)..\..\..\..\GameData\RealAntennas\Plugins\"
</PostBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>

0 comments on commit 317ae17

Please sign in to comment.