-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathupdate.ps1
executable file
·84 lines (68 loc) · 2.51 KB
/
update.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
#!/usr/bin/pwsh
using namespace System.Management.Automation
[CmdletBinding()]
param ()
$PSNativeCommandUseErrorActionPreference = $true
if ($DebugPreference -ne 'SilentlyContinue') {
$ErrorActionPreference = 'Break'
} else {
$ErrorActionPreference = 'Stop'
}
$Debug = $PSCmdlet.MyInvocation.BoundParameters['Debug']
git config --global user.email 'davidxuang@live.com'
git config --global user.name 'Dawei Huang'
Push-Location .
try {
Set-Location $PSScriptRoot
$localTag = Select-Xml -Path "$PSScriptRoot/Directory.Build.props" -XPath "//VersionPrefix" | Select-Object -First 1 -ExpandProperty 'Node' | Select-Object -ExpandProperty '#text'
Write-Host "Local at $localTag"
Set-Location "$PSScriptRoot/seagull-icons/upstream"
git checkout main
git pull --ff-only
$upstreamTag = Get-Content "$PSScriptRoot/seagull-icons/upstream/packages/svg-icons/package.json" | ConvertFrom-Json | Select-Object -ExpandProperty version
Write-Host "Upstream at $upstreamTag"
if (([Version]::Parse($localTag)) -ge ([Version]::Parse($upstreamTag)) -and -not $Debug) {
return
}
Set-Location $PSScriptRoot
& "$PSScriptRoot/seagull-icons/build.ps1"
# update enums
function ConvertTo-Enum {
param (
[string]$Json,
[string]$Cs,
[string]$Enum
)
$map = [System.Collections.Generic.Dictionary[string, int]]::new()
(Get-Content $json | ConvertFrom-Json).PSObject.Properties | ForEach-Object {
$map.Add(($_.Name -replace '(?:^|_)([0-9a-z])', { $_.Groups[1].Value.ToUpperInvariant() }),
[int]$_.Value)
}
@"
namespace FluentIcons.Common;
public enum $Enum : int
{
"@ > $Cs
foreach ($key in $map.Keys) {
@"
$key
= $('0x{0:X}' -f $map[$key]),
"@ >> $Cs
}
@"
}
"@ >> $Cs
}
ConvertTo-Enum -Json "$PSScriptRoot/seagull-icons/obj/icons.json" -Cs "$PSScriptRoot/FluentIcons.Common/Icon.cs" -Enum "Icon"
ConvertTo-Enum -Json "$PSScriptRoot/seagull-icons/obj/icons-resizable.json" -Cs "$PSScriptRoot/FluentIcons.Common/Symbol.cs" -Enum "Symbol"
# patch project version
(Get-Content "$PSScriptRoot/Directory.Build.props") -replace '<VersionPrefix>(.*)<\/VersionPrefix>', "<VersionPrefix>$($upstreamTag)</VersionPrefix>" | Out-File "$PSScriptRoot/Directory.Build.props"
# Commit
git add -A
if (-not $Debug) {
git commit -m "Upstream version v$upstreamTag"
git tag "$upstreamTag-ci"
}
} finally {
Pop-Location
}