Skip to content

Commit

Permalink
[Add] powershell script to create Version file
Browse files Browse the repository at this point in the history
  • Loading branch information
samatstarion committed Aug 16, 2024
1 parent e848df0 commit 9c275c5
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 228 deletions.
6 changes: 0 additions & 6 deletions COMET-WebServices.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CDP4Authentication.Tests", "CDP4Authentication.Tests\CDP4Authentication.Tests.csproj", "{551D1D98-92D6-4391-ADB8-448BC9219330}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VersionFileCreator", "VersionFileCreator\VersionFileCreator.csproj", "{E941F9C0-139A-4DB7-9C98-32A320378DDB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -77,10 +75,6 @@ Global
{551D1D98-92D6-4391-ADB8-448BC9219330}.Debug|Any CPU.Build.0 = Debug|Any CPU
{551D1D98-92D6-4391-ADB8-448BC9219330}.Release|Any CPU.ActiveCfg = Release|Any CPU
{551D1D98-92D6-4391-ADB8-448BC9219330}.Release|Any CPU.Build.0 = Release|Any CPU
{E941F9C0-139A-4DB7-9C98-32A320378DDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E941F9C0-139A-4DB7-9C98-32A320378DDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E941F9C0-139A-4DB7-9C98-32A320378DDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E941F9C0-139A-4DB7-9C98-32A320378DDB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
42 changes: 12 additions & 30 deletions CometServer/CometServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<Company>Starion Group S.A.</Company>
<Title>CometServer-CE</Title>
<Version>8.0.0-rc38</Version>
<AssemblyInformationalVersion>8.0.0-rc38</AssemblyInformationalVersion>
<Description>CDP4-COMET Services API</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<PackageLicenseExpression>AGPL-3.0-only</PackageLicenseExpression>
Expand Down Expand Up @@ -56,34 +57,15 @@
<Copy SourceFiles="@(CDP4DatabaseAuthentication)" DestinationFolder="$(TargetDir)\Authentication\CDP4Database" />
<Copy SourceFiles="@(CDP4WspDatabaseAuthentication)" DestinationFolder="$(TargetDir)\Authentication\CDP4WspDatabase" />
</Target>
<ItemGroup>
<_StaticWebAssetEmbeddedProjectConfigurationCanonicalMetadata Remove="VERSION" />
</ItemGroup>
<ItemGroup>
<_StaticWebAssetProjectConfigurationCanonicalMetadata Remove="VERSION" />
</ItemGroup>
<ItemGroup>
<None Update="VERSION">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<PropertyGroup>
<VersionFileCreatorDll>../VersionFileCreator/bin/$(Configuration)/$(TargetFramework)/VersionFileCreator.dll</VersionFileCreatorDll>
<IsVersionFileCreatorCompiled>False</IsVersionFileCreatorCompiled>
<IsVersionFileCreatorCompiled Condition="Exists('$(VersionFileCreatorDll)')">True</IsVersionFileCreatorCompiled>
</PropertyGroup>
<Target Name="CustomAfterBuild" AfterTargets="Build">
<!-- Debug information on the tool being present -->
<Message Importance="High" Condition="!$(IsVersionFileCreatorCompiled)" Text="------ VersionFileCreator tool is not present --dotnet build-- running ------ " />
<Message Importance="High" Condition="$(IsVersionFileCreatorCompiled)" Text="------ VersionFileCreator tool is present ------ " />
<!-- Compile tool if not already -->
<Exec Condition="!$(IsVersionFileCreatorCompiled)" Command="dotnet build ../VersionFileCreator/VersionFileCreator.csproj -c $(Configuration)" YieldDuringToolExecution="True" ConsoleToMSBuild="False" EchoOff="True" />
<ConvertToAbsolutePath Paths="$(VersionFileCreatorDll)">
<Output TaskParameter="AbsolutePaths" PropertyName="VersionFileCreatorDllPath" />
</ConvertToAbsolutePath>
<!-- at last running the tool -->
<Message Importance="High" Text="------ VersionFileCreator tool Started ------ " />
<Exec Command="dotnet $(VersionFileCreatorDllPath) path:$(OutDir) " YieldDuringToolExecution="True" ConsoleToMSBuild="True" />
<Message Importance="High" Text="------ VersionFileCreator tool Finished ------ " />
</Target>

<!-- create the VERSION file in a PostBuildEvent -->
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="powershell -ExecutionPolicy Bypass -File &quot;$(ProjectDir)Scripts/versionfilecreator.ps1&quot; -buildTarget &quot;$(Configuration)&quot;" />
</Target>

<!-- Create the VERSION file after publishing to the publish directory -->
<Target Name="CreateVersionFileInPublishDirectory" AfterTargets="Publish">
<Exec Command="powershell -ExecutionPolicy Bypass -File &quot;$(ProjectDir)Scripts/versionfilecreator.ps1&quot; -buildTarget &quot;$(Configuration)&quot; -publishDir &quot;$(PublishDir)&quot;" />
</Target>

</Project>
70 changes: 70 additions & 0 deletions CometServer/Scripts/versionfilecreator.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
param (
[string]$buildTarget,
[string]$publishDir
)

# Ensure the build target is provided
if (-not $buildTarget) {
Write-Host "No build target provided. Exiting."
exit 1
}

# Set the path based on the build target
$binPath = if ($publishDir) { $publishDir } else { Join-Path -Path "bin" -ChildPath $buildTarget }

# Path to the output file in the target build directory
$outputFile = Join-Path -Path $binPath -ChildPath "VERSION"

# Echo the path of the VERSION file
Write-Host "The VERSION file will be created at: $outputFile"

# Clear the content of the output file or create it if it doesn't exist
if (Test-Path $outputFile) {
Clear-Content $outputFile
} else {
New-Item -Path $outputFile -ItemType File | Out-Null
}

# Normalize the bin path by ensuring it ends with a backslash
$binPath = [System.IO.Path]::GetFullPath($binPath) + [System.IO.Path]::DirectorySeparatorChar

# Get the list of DLLs in the output directory and all subdirectories
$dlls = Get-ChildItem -Path $binPath -Filter *.dll -Recurse

# Initialize lists for categorized DLLs
$cdp4CometDlls = @()
$otherDlls = @()

foreach ($dll in $dlls) {
# Get the version information
$versionInfo = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($dll.FullName)

# Get the relative path of the DLL starting from the output directory
$relativeDllPath = $dll.FullName.Substring($binPath.Length)

# Prepare the output line
$outputLine = "$relativeDllPath $($versionInfo.FileVersion)"

# Categorize DLLs
if ($dll.Name -match "(?i)cdp4|comet") {
$cdp4CometDlls += $outputLine
} else {
$otherDlls += $outputLine
}
}

# Sort the other DLLs alphabetically
$otherDlls = $otherDlls | Sort-Object

# Write the categorized DLLs to the VERSION file
Add-Content -Path $outputFile -Value "CDP4-COMET:"
Add-Content -Path $outputFile -Value "----------------"
$cdp4CometDlls | ForEach-Object { Add-Content -Path $outputFile -Value $_ }

Add-Content -Path $outputFile -Value ""
Add-Content -Path $outputFile -Value "Dependencies:"
Add-Content -Path $outputFile -Value "----------------"
$otherDlls | ForEach-Object { Add-Content -Path $outputFile -Value $_ }

# Confirm the creation of the VERSION file
Write-Host "Version information written to $outputFile in $binPath"
5 changes: 0 additions & 5 deletions CometServer/VERSION

This file was deleted.

13 changes: 10 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env

# Install PowerShell as a .NET Global Tool
RUN dotnet tool install --global PowerShell

# Ensure that the global tools are in the PATH
ENV PATH="$PATH:/root/.dotnet/tools"

# Create a symbolic link for 'powershell' to point to 'pwsh'
RUN ln -s /root/.dotnet/tools/pwsh /usr/bin/powershell

WORKDIR /app
COPY CDP4Authentication CDP4Authentication
COPY CDP4DatabaseAuthentication CDP4DatabaseAuthentication
COPY CDP4WspDatabaseAuthentication CDP4WspDatabaseAuthentication
COPY CDP4Orm CDP4Orm
COPY VersionFileCreator VersionFileCreator
COPY CometServer CometServer

RUN dotnet build CDP4DatabaseAuthentication -c Release
RUN dotnet build CDP4WspDatabaseAuthentication -c Release
RUN dotnet publish -r linux-x64 CometServer -c Release -o /app/CometServer/bin/Release/publish

COPY CometServer/bin/Release/linux-x64/VERSION /app/CometServer/bin/Release/publish/VERSION

FROM mcr.microsoft.com/dotnet/aspnet:8.0.7-alpine3.20
WORKDIR /app
RUN mkdir /app/logs
Expand Down
165 changes: 0 additions & 165 deletions VersionFileCreator/Program.cs

This file was deleted.

19 changes: 0 additions & 19 deletions VersionFileCreator/VersionFileCreator.csproj

This file was deleted.

0 comments on commit 9c275c5

Please sign in to comment.