diff --git a/.github/Get-CalendarVersion.ps1 b/.github/Get-CalendarVersion.ps1 new file mode 100644 index 00000000..85ad22bd --- /dev/null +++ b/.github/Get-CalendarVersion.ps1 @@ -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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52c1b676..60be3956 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -64,5 +62,5 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - version: '${{steps.version.outputs.semanticVersion}}' + version: '${{steps.version.outputs.version}}' prerelease: true