Skip to content

Commit

Permalink
make date-based version easier to read
Browse files Browse the repository at this point in the history
  • Loading branch information
brettfo committed Aug 24, 2024
1 parent adb06ba commit ca31b55
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 26 deletions.
29 changes: 8 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,8 @@ on: [push, pull_request]

jobs:

create-version-suffix:
runs-on: ubuntu-latest
outputs:
version-suffix: ${{ steps.create-version-suffix.outputs.VERSION_SUFFIX }}
steps:
- id: create-version-suffix
shell: pwsh
run: |
$versionSuffix = [System.DateTime]::UtcNow.ToString("yyyyMMddHHmmss")
$versionString = "VERSION_SUFFIX=$versionSuffix"
Write-Host $versionString
Write-Output $versionString | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
build:
runs-on: ${{ matrix.value.os }}
needs: create-version-suffix
strategy:
matrix:
value: [{ os: windows-latest, architecture: x64 }, { os: windows-latest, architecture: arm64 }, { os: ubuntu-latest, architecture: x64 }]
Expand All @@ -34,13 +20,9 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: 1.19
- name: promote version suffix
shell: pwsh
run: |
Write-Output "VERSION_SUFFIX=${{ needs.create-version-suffix.outputs.version-suffix }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Build and test
shell: pwsh
run: ./build-and-test.ps1 -configuration Release -architecture ${{ matrix.value.architecture }}
run: ./build-and-test.ps1 -configuration Release -architecture ${{ matrix.value.architecture }} -ci
- name: publish artifact
uses: actions/upload-artifact@v4
with:
Expand All @@ -55,17 +37,22 @@ jobs:

cross_compile:
runs-on: ubuntu-latest
needs: create-version-suffix
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Calculate version
shell: bash
run: echo "VERSION_SUFFIX=$(pwsh ./build/make-version.ps1 -suffix beta)" | tee -a $GITHUB_OUTPUT
- uses: devcontainers/[email protected]
with:
push: never
runCmd: ./build-and-test.ps1 -configuration Release -architecture arm64
env: |
VERSION_SUFFIX=${{ needs.create-version-suffix.outputs.version-suffix }}
DOTNET_NOLOGO=true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
DOTNET_CLI_TELEMETRY_OPTOUT=true
VERSION_SUFFIX
- name: re-map path variables from container
shell: pwsh
run: |
Expand Down
14 changes: 12 additions & 2 deletions build-and-test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
param (
[string][Alias('c')]$configuration = "Debug",
[string][Alias('a')]$architecture,
[switch]$ci,
[switch]$noTest,
[string]$deployTo
)
Expand All @@ -21,6 +22,12 @@ function Set-EnvironmentVariable([string]$name, [string]$value) {
try {
$runTests = -Not $noTest

if ($ci) {
$env:VERSION_SUFFIX = ./build/make-version.ps1 -suffix beta
}

Write-Host "Using VERSION_SUFFIX=$env:VERSION_SUFFIX"

# assign architecture
if ($architecture -eq '') {
if ($IsWindows) {
Expand Down Expand Up @@ -119,8 +126,11 @@ try {
}
else {
$packageVersionPrefix = (Get-Content "$PSScriptRoot/version.txt" | Out-String).Trim()
$packageVersionSuffix = if ("$env:VERSION_SUFFIX" -eq "") { "0" } else { $env:VERSION_SUFFIX }
$packageVersion = "$packageVersionPrefix.$packageVersionSuffix"
$packageVersionSuffix = "$env:VERSION_SUFFIX"
if ($packageVersionSuffix -ne "") {
$packageVersionSuffix = ".$packageVersionSuffix"
}
$packageVersion = "$packageVersionPrefix$packageVersionSuffix"
$packageArchitecture = if ($architecture -eq "x64") { "amd64" } else { "arm64" }
$packageName = "bcad_${packageVersion}_$packageArchitecture.deb"
Set-EnvironmentVariable "secondary_artifact_name" "deb-$architecture"
Expand Down
40 changes: 40 additions & 0 deletions build/make-version.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/pwsh

[CmdletBinding(PositionalBinding = $false)]
param (
[string]$suffix = "dev"
)

Set-StrictMode -version 2.0
$ErrorActionPreference = "Stop"

try {
# get date of latest commit
$date = git show --no-patch --format=%cs HEAD

# count commits with that same date
$lines = git log '--pretty=%cs' -n 99
$count = 0
foreach ($line in $lines) {
if ($line -ne $date) {
break
}

$count++
}

# format date as version
$parts = $date -Split '-'
$year = $parts[0] # e.g., 2024 from '2024-12-25'
$month = $parts[1] # e.g., 12 from '2024-12-25'
$day = $parts[2] # e.g., 25 from '2024-12-25'
$version = "$suffix.$year-$month-$day.$count"
Write-Output $version

}
catch {
Write-Host $_
Write-Host $_.Exception
Write-Host $_.ScriptStackTrace
exit 1
}
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<AssemblySearchPaths>{HintPathFromItem};{TargetFrameworkDirectory};{RawFileName}</AssemblySearchPaths>
<RepoRoot>$(MSBuildThisFileDirectory)..</RepoRoot>
<_VersionSuffix>$(VERSION_SUFFIX)</_VersionSuffix>
<_VersionSuffix Condition="'$(_VersionSuffix)' == ''">0</_VersionSuffix>
<VersionPrefix>$([System.IO.File]::ReadAllText('$(RepoRoot)\version.txt').Trim()).0-beta.$(_VersionSuffix)</VersionPrefix>
<_VersionSuffix Condition="'$(_VersionSuffix)' == ''">dev</_VersionSuffix>
<VersionPrefix>$([System.IO.File]::ReadAllText('$(RepoRoot)\version.txt').Trim())-$(_VersionSuffix)</VersionPrefix>
<ArtifactsDir>$(RepoRoot)\artifacts</ArtifactsDir>
<ArtifactsPackagesDir>$(ArtifactsDir)\packages</ArtifactsPackagesDir>
<BaseOutputPath>$(ArtifactsDir)\bin\$(MSBuildProjectName)</BaseOutputPath>
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2
0.2.0

0 comments on commit ca31b55

Please sign in to comment.