Skip to content

Commit

Permalink
[Build/CI] Integrate version patcher into build script
Browse files Browse the repository at this point in the history
Ditched the shell script version in favour of using PowerShell - definitely not rewriting the version patcher just for the sake of it.
  • Loading branch information
hyperbx committed Mar 7, 2022
1 parent 7b43c3b commit f51298f
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 171 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
*.ps1 linguist-vendored
*.sh linguist-vendored
*.ps1 linguist-vendored
10 changes: 2 additions & 8 deletions .github/workflows/Marathon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,11 @@ jobs:
run: |
$version = "${{env.VERSION}}." + (45 + ${{github.run_number}})
echo "VERSION_RESOLVE=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
# Patches the assembly information stored in 'Marathon.csproj' and 'Marathon.CLI.csproj' to use the current workflow version.
- name: Patch Version Information
run: |
./.github/workflows/VersionPatcher.ps1 -ProjectPath "${{env.MARATHON_PROJECT}}" -Version ${{env.VERSION_RESOLVE}} -CommitID ${{github.sha}}
./.github/workflows/VersionPatcher.ps1 -ProjectPath "${{env.MARATHON_CLI_PROJECT}}" -Version ${{env.VERSION_RESOLVE}} -CommitID ${{github.sha}}
# Builds Marathon using the PowerShell script.
- name: Build Marathon
working-directory: ${{github.workspace}}
run: ./Build.ps1 -BuildAll -Clean -Configuration ${{matrix.configuration}}
run: ./Build.ps1 -BuildAll -Clean -CommitID ${{github.sha}} -Configuration ${{matrix.configuration}} -Version ${{env.VERSION_RESOLVE}}

# Uploads the compiled Marathon artifacts.
- name: Upload Marathon Artifacts
Expand Down
15 changes: 11 additions & 4 deletions .github/workflows/VersionPatcher.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
param
(
[String]$ProjectPath,
[String]$Version,
[String]$CommitID,
[Switch]$UseFullCommitID
[String]$ProjectPath,
[Switch]$UseFullCommitID,
[String]$Version
)

$project = [System.IO.File]::ReadAllLines($ProjectPath)
Expand All @@ -24,7 +24,14 @@ foreach ($line in $project)
}
elseif ($lineSplit[0].Contains("<InformationalVersion"))
{
$lineSplit[1] = "${Version}-${CommitID}</InformationalVersion"
if ([System.String]::IsNullOrEmpty($CommitID))
{
$lineSplit[1] = "${Version}</InformationalVersion"
}
else
{
$lineSplit[1] = "${Version}-${CommitID}</InformationalVersion"
}
}

$project[$i] = [System.String]::Join(">", $lineSplit)
Expand Down
4 changes: 0 additions & 4 deletions .profiles

This file was deleted.

68 changes: 49 additions & 19 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
param
(
[Alias("a")][Switch]$BuildAll,
[Alias("c")][String]$Configuration = "Release",
[Alias("d")][Switch]$Clean,
[Alias("h")][Switch]$Help,
[Alias("p")][String]$Profile
[Switch]$BuildAll,
[String]$CommitID,
[String]$Configuration = "Release",
[Switch]$Clean,
[Switch]$Help,
[String]$Profile,
[Switch]$UseFullCommitID,
[String]$Version
)

$profileData = ".profiles"
$profiles = @("win-x86", "win-x64", "linux-x64", "osx-x64")
$versionPatcher = ".github\workflows\VersionPatcher.ps1"

if ($Help)
{
Expand All @@ -16,11 +20,14 @@ if ($Help)
echo "All your platforms are belong to us."
echo ""
echo "Usage:"
echo "-a|-BuildAll - build Marathon with all available profiles."
echo "-c|-Configuration [name] - build Marathon with a specific configuration."
echo "-d|-Clean - cleans the solution before building Marathon."
echo "-h|-Help - display help."
echo "-p|-Profile [name] - build Marathon with a specific profile."
echo "-BuildAll - build Marathon with all available profiles."
echo "-CommitID [id] - set the commit ID to use from GitHub for the version number."
echo "-Configuration [name] - build Marathon with a specific configuration."
echo "-Clean - cleans the solution before building Marathon."
echo "-Help - display help."
echo "-Profile [name] - build Marathon with a specific profile."
echo "-UseFullCommitID - use the full 40 character commit ID for the version number."
echo "-Version [major].[minor].[revision] - set the version number for this build of Marathon."
exit
}

Expand All @@ -37,15 +44,38 @@ if ($Clean)
dotnet clean
}

function PatchVersionInformation([String]$commitID, [Boolean]$useFullCommitID, [String]$version)
{
# Patch the version number for all projects.
if (![System.String]::IsNullOrEmpty($version))
{
foreach ($project in [System.IO.Directory]::EnumerateFiles(".", "*.csproj", [System.IO.SearchOption]::AllDirectories))
{
& "${versionPatcher}" -CommitID $commitID -ProjectPath "${project}" -Version $version
}
}
}

function Build([String]$configuration, [String]$profile)
{
# Patch version number before building.
PatchVersionInformation $CommitID $UseFullCommitID $Version

dotnet publish /p:Configuration="${configuration}" /p:PublishProfile="${profile}"

# Restore default version number.
PatchVersionInformation "" $false "1.0.0"
}

if (![System.String]::IsNullOrEmpty($Profile))
{
if ([System.Array]::IndexOf([System.IO.File]::ReadAllLines($profileData), $Profile) -eq -1)
if ([System.Array]::IndexOf($profiles, $Profile) -eq -1)
{
echo "No such profile exists: $Profile"
echo "No such profile exists: ${Profile}"
exit
}

dotnet publish /p:Configuration="$Configuration" /p:PublishProfile="$Profile"
Build $Configuration $Profile

if (!$BuildAll)
{
Expand All @@ -55,19 +85,19 @@ if (![System.String]::IsNullOrEmpty($Profile))

if ($BuildAll)
{
foreach ($line in [System.IO.File]::ReadAllLines($profileData))
foreach ($currentProfile in $profiles)
{
# Skip profile if it was already specified and built.
if ($line -eq $Profile)
if ($currentProfile -eq $Profile)
{
continue
}

dotnet publish /p:Configuration="$Configuration" /p:PublishProfile="$line"
Build $Configuration $currentProfile
}
}
else
{
dotnet publish /p:Configuration="$Configuration" /p:PublishProfile="win-x86"
dotnet publish /p:Configuration="$Configuration" /p:PublishProfile="win-x64"
Build $Configuration "win-x86"
Build $Configuration "win-x64"
}
134 changes: 0 additions & 134 deletions Build.sh

This file was deleted.

0 comments on commit f51298f

Please sign in to comment.