Skip to content

Commit

Permalink
👷‍♂️Change to Calendar Versioning (#44)
Browse files Browse the repository at this point in the history
Versions will now be YEAR.MONTH.RELEASE-BUILD
  • Loading branch information
JustinGrote authored Aug 21, 2021
1 parent 5993624 commit 6d03d87
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 11 deletions.
50 changes: 50 additions & 0 deletions .github/Get-CalendarVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#requires -version 7
using namespace System.Management.Automation
Set-StrictMode -Version 3
$ErrorActionPreference = 'Stop'

<#
.SYNOPSIS
Generates a CalendarVersion based on the current commit
#>
function Get-CalendarVersion {
param(
#The branch where releases are produced. Untagged releases will have the "beta" label
[string]$releaseBranchName = 'main',
#Add the build number to the release number. Basically replace the "+" with a "-"
[switch]$MergeBuild
)
$date = [DateTime]::Now
[string]$datePrefix = $date.Year, $date.Month -join '.'

#This version component is zero-based so it should be 0 for the first release of the month, 1 for the second, etc.
$releaseCount = @(& git tag -l "v$DatePrefix*").count

if ($releaseBranchName -eq [string](git describe --tags)) {
return [SemanticVersion]::new($date.Year, $date.Month, $releaseCount)
}

[string]$currentBranchName = & git branch --show-current
if (-not $currentBranchName -and $env:GITHUB_REF) {
$currentBranchName = $env:GITHUB_REF
}

Write-Verbose "Current Branch Name: $currentBranchName"

[string]$branchName = if ($currentBranchName -eq $releaseBranchName) {
'beta'
} elseif ($currentBranchName -match '^refs/pull/(\d+)/merge$') {
'pr' + $matches[1]
Write-Verbose "Pull Request Branch Detected, branchname is now pr$($matches[1])"
} else {
$currentBranchName.split('/') | Select-Object -Last 1
}

$delimiter = $MergeBuild ? '+' : '-'
[int]$commitsSince = @(& git log --oneline -- "$currentBranchName..HEAD").count
[string]$prereleaseTag = $branchName, $commitsSince.ToString().PadLeft(3, '0') -join $delimiter

return [SemanticVersion]::new($date.Year, $date.Month, $releaseCount, $prereleaseTag)
}

Get-CalendarVersion
20 changes: 9 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,30 @@ jobs:
with:
path: |
node_modules
~/.dotnet/tools
.git/gitversion_cache
.config/dotnet-tools.ci.json
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}

- name: ➕ Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
& npm ci
& dotnet tool install -g gitversion.tool --version 5.6.11
- name: 🔍 GitVersion
- name: 🔍 Get Calendar Version
id: version
run: |
$semanticVersion = & dotnet-gitversion /nofetch | ConvertFrom-Json | % SemVer
"Calculated Version: $semanticVersion"
"::set-output name=semanticVersion::$semanticVersion"
[string]$version = & .github\Get-CalendarVersion.ps1 -MergeBuild
"Calculated Version: $version"
"::set-output name=version::$version"
"::set-output name=calendarVersion::$version"
"::set-output name=semanticVersion::$version"
- name: 👷‍♂️ Build
run: |
npm run build ${{steps.version.outputs.semanticVersion}}
npm run build ${{steps.version.outputs.version}}
- name: ⬆ Artifact
uses: actions/upload-artifact@v2
with:
name: vsix-${{steps.version.outputs.semanticVersion}}
name: vsix-${{steps.version.outputs.version}}
path: '*.vsix'

- name: 📝 Draft Github Release
Expand All @@ -64,5 +62,5 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
version: '${{steps.version.outputs.semanticVersion}}'
version: '${{steps.version.outputs.version}}'
prerelease: true

0 comments on commit 6d03d87

Please sign in to comment.