From dc2e8de31382a8dd7a59d654b927582306469983 Mon Sep 17 00:00:00 2001 From: "Brett V. Forsgren" Date: Sat, 24 Aug 2024 09:46:34 -0600 Subject: [PATCH] make date-based version easier to read --- .github/workflows/ci.yml | 13 ++++------- build-and-test.ps1 | 7 ++++-- build/make-version.ps1 | 45 +++++++++++++++++++++++++++++++++++++++ src/Directory.Build.props | 4 ++-- version.txt | 2 +- 5 files changed, 57 insertions(+), 14 deletions(-) create mode 100755 build/make-version.ps1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f139b86b..3e6fedcb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,13 +9,10 @@ jobs: outputs: version-suffix: ${{ steps.create-version-suffix.outputs.VERSION_SUFFIX }} steps: + - uses: actions/checkout@v4 - 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 + run: ./build/make-version.ps1 -suffix beta -ci build: runs-on: ${{ matrix.value.os }} @@ -34,13 +31,11 @@ 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 }} + env: + VERSION_SUFFIX=${{ needs.create-version-suffix.outputs.version-suffix }} - name: publish artifact uses: actions/upload-artifact@v4 with: diff --git a/build-and-test.ps1 b/build-and-test.ps1 index ad0193b0..1fc88c0d 100755 --- a/build-and-test.ps1 +++ b/build-and-test.ps1 @@ -119,8 +119,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" diff --git a/build/make-version.ps1 b/build/make-version.ps1 new file mode 100755 index 00000000..d43c0a5e --- /dev/null +++ b/build/make-version.ps1 @@ -0,0 +1,45 @@ +#!/usr/bin/pwsh + +[CmdletBinding(PositionalBinding = $false)] +param ( + [string]$suffix = "dev", + [switch]$ci +) + +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" + $versionSet = "VERSION_SUFFIX=$version" + Write-Host $versionSet + if ($ci) { + Write-Output $versionSet | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + } + +} +catch { + Write-Host $_ + Write-Host $_.Exception + Write-Host $_.ScriptStackTrace + exit 1 +} diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 04b8b436..4be2596f 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -7,8 +7,8 @@ {HintPathFromItem};{TargetFrameworkDirectory};{RawFileName} $(MSBuildThisFileDirectory).. <_VersionSuffix>$(VERSION_SUFFIX) - <_VersionSuffix Condition="'$(_VersionSuffix)' == ''">0 - $([System.IO.File]::ReadAllText('$(RepoRoot)\version.txt').Trim()).0-beta.$(_VersionSuffix) + <_VersionSuffix Condition="'$(_VersionSuffix)' == ''">dev + $([System.IO.File]::ReadAllText('$(RepoRoot)\version.txt').Trim())-$(_VersionSuffix) $(RepoRoot)\artifacts $(ArtifactsDir)\packages $(ArtifactsDir)\bin\$(MSBuildProjectName) diff --git a/version.txt b/version.txt index 3b04cfb6..0ea3a944 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.2 +0.2.0