Removed commit information from package publish #304
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy | |
on: | |
push: | |
branches: | |
- dev | |
release: | |
types: | |
- published | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Setup .NET Core | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 6.0.x | |
- name: Restore | |
run: dotnet restore | |
- name: Trim readme.md | |
if: github.event_name == 'release' | |
shell: pwsh | |
run: | | |
(Get-Content .\readme.md | Select-Object -Skip 2) | Out-File readme.md | |
- name: Build | |
shell: pwsh | |
run: | | |
$additionalBuildArgs = @() | |
if ('${{ github.event_name }}' -ieq 'release') { | |
[string] $baseVersionPart, [string] $preReleaseVersionPart = '${{ github.ref_name }}' -split '\-' | |
[int] $major, [int] $minor, [int] $revision = $baseVersionPart -split '\.', 3 | |
# The build version represents a build of the same sources, this seldom happens with releases. | |
# Pre-releases have only major and minor version leaving the build and revision numbers as undefined. | |
# | |
# Releases map the major, minor and patch version numbers to major, minor and revision respectively, | |
# leaving the build number to always be 0. If there will be a case where the same sources are build | |
# and released in a separate NuGet package it will be addressed at that point, right now I don't see | |
# how that will ever happen since releases are tagged in git (must be unique) using SemVer. | |
# | |
# https://learn.microsoft.com/dotnet/api/system.version | |
# https://semver.org | |
[string] $version = "$major.$minor.0.$revision" | |
if ($preReleaseVersionPart -ne [string]::Empty) { | |
$version = "$major.$minor" | |
} | |
$additionalBuildArgs += "-property:Version=$version" | |
} | |
$additionalBuildArgs += '-property:InformationalVersion=${{ github.ref_name }}' | |
[Convert]::FromBase64String('${{ secrets.KeyFile }}') ` | |
| Set-Content ./CodeMap.snk -AsByteStream | |
dotnet build ` | |
--configuration Release ` | |
--no-restore ` | |
-property:SignAssembly=True ` | |
-property:AssemblyOriginatorKeyFile=../CodeMap.snk ` | |
-property:DisableStrongNamer=False ` | |
@additionalBuildArgs | |
- name: Test | |
shell: pwsh | |
run: | | |
dotnet test ` | |
--configuration Release ` | |
--no-build ` | |
--verbosity normal | |
- name: Pack | |
if: github.event_name == 'release' | |
shell: pwsh | |
run: | | |
[string] $releaseNotes = (@" | |
${{ github.event.release.body }} | |
"@ -split '# Release Notes', 2 | Select-Object -Last 1).Trim() -replace ',', '%2c' | |
dotnet pack ` | |
--configuration Release ` | |
--output publish ` | |
--no-build ` | |
-property:PackageVersion='${{ github.ref_name }}' ` | |
-property:PackageReleaseNotes="$releaseNotes" | |
- name: Upload CodeMap NuGet Package to Release | |
uses: actions/upload-release-asset@v1 | |
if: github.event_name == 'release' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ github.event.release.upload_url }} | |
asset_path: ./publish/CodeMap.${{ github.ref_name }}.nupkg | |
asset_name: CodeMap.${{ github.ref_name }}.nupkg | |
asset_content_type: application/zip | |
- name: Generate Project Site | |
shell: pwsh | |
run: | | |
function Sort-SemVerDescending([string[]] $versions) { | |
[string[]] $sortedVersions = @() | |
while ($versions.Length -gt 0) { | |
[string] $maxVersion = $versions[0] | |
$versions | Select-Object -Skip 1 | ForEach-Object { | |
if ((Compare-SemVer $maxVersion $_) -lt 0) { | |
$maxVersion = $_ | |
} | |
} | |
$sortedVersions += $maxVersion | |
$versions = $versions | Where-Object { $_ -ne $maxVersion } | |
} | |
return $sortedVersions | |
} | |
function Compare-SemVer([string] $left, [string] $right) { | |
[string] $leftVersionParts = Get-VersionParts $left | |
[string] $rightVersionParts = Get-VersionParts $right | |
[int] $index = 0 | |
[int] $result = 0 | |
while ($index -lt $leftVersionParts.Length -and $index -lt $rightVersionParts.Length -and $result -eq 0) { | |
if ($leftVersionParts[$index] -lt $rightVersionParts[$index]) { | |
$result = -1 | |
} | |
elseif ($leftVersionParts[$index] -gt $rightVersionParts[$index]) { | |
$result = 1 | |
} | |
else { | |
$index++ | |
} | |
} | |
if ($result -eq 0 -and ($leftVersionParts.Length -ne $rightVersionParts.Length)) { | |
if ($index -eq $leftVersionParts.Length) { | |
$result = -1 | |
} | |
elseif ($index -eq $rightVersionParts.Length) { | |
$result = 1 | |
} | |
} | |
return $result | |
} | |
function Get-VersionParts([string] $version) { | |
[string] $baseAndPreRelease, [string] $build = $version -split '\+', 2 | |
[string] $base, [string] $preRelease = $baseAndPreRelease -split '-', 2 | |
[int] $major, [int] $minor, [int] $patch = $base -split '\.', 3 | |
$versionParts = @($major, $minor, $patch) | |
if (-not [string]::IsNullOrWhiteSpace($preRelease)) { | |
$versionParts += 0 | |
($preRelease -split '\.') ` | |
| ForEach-Object { | |
if ($_ -imatch '^\d+$') { | |
$versionParts += 0 | |
$versionParts += [int]$_ | |
} | |
else { | |
$versionParts += 1 | |
$versionParts += $_ | |
} | |
} | |
} | |
if (-not [string]::IsNullOrWhiteSpace($build)) { | |
$versionParts += 1 | |
($build -split '\.') ` | |
| ForEach-Object { | |
if ($_ -imatch '^\d+$') { | |
$versionParts += 0 | |
$versionParts += [int]$_ | |
} | |
else { | |
$versionParts += 1 | |
$versionParts += $_ | |
} | |
} | |
} | |
return $versionParts | |
} | |
New-Item ` | |
-Type Directory ` | |
-Name docs ` | |
-ErrorAction SilentlyContinue ` | |
| Out-Null | |
New-Item ` | |
-Type Directory ` | |
-Name _data ` | |
-Path docs ` | |
-ErrorAction SilentlyContinue ` | |
| Out-Null | |
[string] $documentationDirectoryPath = if ('${{ github.event_name }}' -ieq 'release' -or '${{ github.ref_name }}' -ieq 'dev') { '${{ github.ref_name }}' } else { 'dev/${{ github.ref_name }}' } | |
dotnet run ` | |
--project CodeMap.Documentation ` | |
--configuration Release ` | |
--no-build ` | |
-- ` | |
-OutputFilePath "./docs/$documentationDirectoryPath/index.html" | |
if (Test-Path 'CodeMap.Documentation/GitHub Pages') { | |
Copy-Item ` | |
-Path 'CodeMap.Documentation/GitHub Pages/*' ` | |
-Destination './docs' ` | |
-Recurse | |
if (('${{ github.ref_name }}' -ine 'dev') -and (Test-Path './docs/_posts')) { | |
Remove-Item ` | |
-Path './docs/_posts' ` | |
-Recurse | |
} | |
} | |
Sort-SemVerDescending ( | |
git tag ` | |
| Where-Object { $_ -imatch '^\d+\.\d+\.\d+(-[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)?(\+[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)?$' } | |
) ` | |
| ForEach-Object { "- $_" } ` | |
| Out-File ./docs/_data/tags.yml -Encoding utf8 | |
- name: Publish Project Site | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./docs | |
destination_dir: docs | |
enable_jekyll: true | |
keep_files: true |