This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.ps1
107 lines (91 loc) · 3.46 KB
/
build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
param(
[string]$Version = ''
)
$ErrorActionPreference = 'Stop'
if ($env:APPVEYOR_REPO_TAG -eq 'true') {
$Version = [regex]::match($env:APPVEYOR_REPO_TAG_NAME,'[0-9]+\.[0-9]+\.[0-9]+').Groups[0].Value
$lastPublishedVersion = [Version]::new((Find-Module -Name JournalCli | Select-Object -ExpandProperty Version))
if ([Version]::new($Version) -le $lastPublishedVersion) {
throw "Version must be greater than the last published version, which is 'v$lastPublishedVersion'."
}
Write-Host "Last published version: 'v$lastPublishedVersion'. Current version: 'v$Version'"
} elseif ($null -ne $env:APPVEYOR_BUILD_NUMBER) {
$Version = "0.0.$env:APPVEYOR_BUILD_NUMBER"
} elseif ($Version -eq '') {
$Version = "0.0.0"
}
Write-Host "Building version '$Version'..."
$appName = "JournalCli"
if (Test-Path "$PSScriptRoot\publish") {
Remove-Item -Path "$PSScriptRoot\publish" -Recurse -Force
}
New-Item -Path "$PSScriptRoot\publish\$appName" -ItemType Directory | Out-Null
$publishOutputDir = "$PSScriptRoot\publish\$appName"
$proj = Get-ChildItem -Filter "$appName.csproj" -Recurse -Path $PSScriptRoot | Select-Object -First 1 -ExpandProperty FullName
dotnet publish $proj -c Release --self-contained true --output "$publishOutputDir"
if ($LASTEXITCODE -ne 0) {
throw "Failed to publish application."
}
$targets = 'win-x64','linux-x64','osx-x64','ubuntu.18.04-x64'
foreach ($target in $targets) {
dotnet publish $proj -c Release --self-contained true -r $target --output "$publishOutputDir\$target"
if ($LASTEXITCODE -ne 0) {
throw "Failed to publish application."
}
}
foreach ($target in $targets) {
Get-ChildItem -Path "$publishOutputDir\$target" | ForEach-Object {
if ($_.Name -notlike "*git*") {
Remove-Item $_
}
}
}
Get-ChildItem -Path $publishOutputDir -Filter "*.pdb" -Recurse | Remove-Item
Import-Module "$publishOutputDir\$appName.dll"
$moduleInfo = Get-Module $appName
Install-Module WhatsNew
Import-Module WhatsNew
$cmdletNames = Export-BinaryCmdletNames -ModuleInfo $moduleInfo
$cmdletAliases = Export-BinaryCmdletAliases -ModuleInfo $moduleInfo
$manifestPath = "$publishOutputDir\$appName.psd1"
$newManifestArgs = @{
Path = $manifestPath
}
$updateManifestArgs = @{
Path = $manifestPath
CopyRight = "(c) $((Get-Date).Year) Nick Spreitzer"
Description = "Index your markdown-based journal with yaml front matter!"
Guid = 'c45932e7-867b-4894-9226-cf278bdb4e3e'
Author = 'Nick Spreitzer'
CompanyName = 'RAWR! Productions'
ModuleVersion = $Version
AliasesToExport = $cmdletAliases
RootModule = "$appName.dll"
CmdletsToExport = $cmdletNames
CompatiblePSEditions = @("Core")
HelpInfoUri = "https://github.com/refactorsaurusrex/journal-cli/wiki"
PowerShellVersion = "7.1.0"
PrivateData = @{
Tags = 'notebook','journal','markdown'
LicenseUri = 'https://github.com/refactorsaurusrex/journal-cli/blob/master/LICENSE'
ProjectUri = 'https://github.com/refactorsaurusrex/journal-cli'
}
}
New-ModuleManifest @newManifestArgs
Update-ModuleManifest @updateManifestArgs
Remove-ModuleManifestComments $manifestPath -NoConfirm
Install-Module platyPS
Import-Module platyPS
$docs = "$PSScriptRoot\docs"
try {
git clone https://github.com/refactorsaurusrex/journal-cli.wiki.git $docs
if ($LASTEXITCODE -ne 0) {
throw "Failed to clone wiki."
}
Switch-CodeFenceToYamlFrontMatter -Path $docs -NoConfirm
New-ExternalHelp -Path $docs -OutputPath $publishOutputDir
} finally {
if (Test-Path $docs) {
Remove-Item -Path $docs -Recurse -Force
}
}