forked from isaacrlevin/winget-publish-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
136 lines (127 loc) · 4.05 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
Param
(
[parameter(Mandatory = $true)]
[string]
$User,
[parameter(Mandatory = $true)]
[string]
$Package,
[parameter(Mandatory = $true)]
[string]
$Version,
[parameter(Mandatory = $true)]
[string]
$Url,
[parameter(Mandatory = $true)]
[string]
$Arch,
[parameter(Mandatory = $true)]
[string]
$InstallerType,
[parameter(Mandatory = $true)]
[string]
$Publisher,
[parameter(Mandatory = $true)]
[string]
$PackageName,
[parameter(Mandatory = $true)]
[string]
$License,
[parameter(Mandatory = $true)]
[string]
$ShortDescription,
[parameter(Mandatory = $true)]
$FamilyName,
[parameter(Mandatory = $true)]
[string]
$Token
)
function Get-Hash {
param (
[parameter(Mandatory = $true)]
[string]
$Url
)
Invoke-WebRequest -Uri $Url -OutFile "./file"
$hash = Get-Filehash "./file"
return $hash.Hash
}
function Write-MetaData {
param (
[parameter(Mandatory = $true)]
[string]
$FileName,
[parameter(Mandatory = $true)]
[string]
$User,
[parameter(Mandatory = $true)]
[string]
$Package,
[parameter(Mandatory = $true)]
[string]
$Version,
[parameter(Mandatory = $true)]
[string]
$Url,
[parameter(Mandatory = $true)]
[string]
$Arch,
[parameter(Mandatory = $true)]
[string]
$InstallerType,
[parameter(Mandatory = $true)]
[string]
$Publisher,
[parameter(Mandatory = $true)]
[string]
$PackageName,
[parameter(Mandatory = $true)]
[string]
$License,
[parameter(Mandatory = $true)]
[string]
$ShortDescription,
[parameter(Mandatory = $true)]
$FamilyName,
[parameter(Mandatory = $true)]
[string]
$Hash
)
$content = Get-Content "D:\a\_actions\isaacrlevin\winget-publish-action\v.7\templates\$FileName" -Raw
$content = $content.Replace('<VERSION>', $Version)
$content = $content.Replace('<FAMILY-NAME>', $FamilyName)
$content = $content.Replace('<USER>', $User)
$content = $content.Replace('<PACKAGE>', $Package)
$content = $content.Replace('<HASH>', $Hash)
$content = $content.Replace('<ARCH>', $Arch)
$content = $content.Replace('<INSTALLER-TYPE>', $InstallerType)
$content = $content.Replace('<URL>', $Url)
$content = $content.Replace('<PUBLISHER>', $Publisher)
$content = $content.Replace('<PACKAGE-NAME>', $PackageName)
$content = $content.Replace('<LICENSE>', $License)
$content = $content.Replace('<DESCRIPTION>', $ShortDescription)
$fName = $FileName.Replace('user',$User)
$fName = $FileName.Replace('package',$Package)
$content | Out-File -Encoding 'UTF8' "./$Version/$fName"
}
New-Item -Path $PWD -Name $Version -ItemType "directory"
$Hash = Get-Hash -Url $Url
Get-ChildItem 'D:\a\_actions\isaacrlevin\winget-publish-action\v.7\templates\*.yaml' | ForEach-Object -Process {
Write-MetaData -FileName $_.Name -User $User -Package $Package -Url $Url -ShortDescription $ShortDescription -FamilyName $FamilyName -Version $Version -Hash $Hash -Arch $Arch -InstallerType $InstallerType -Publisher $Publisher -PackageName $PackageName -License $License
}
if (-not $Token) {
return
}
# Install the latest wingetcreate exe
# Need to do things this way, see https://github.com/PowerShell/PowerShell/issues/13138
Import-Module Appx -UseWindowsPowerShell
# Download and install C++ Runtime framework package.
$vcLibsBundleFile = "$env:TEMP\Microsoft.VCLibs.Desktop.appx"
Invoke-WebRequest https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile $vcLibsBundleFile
Add-AppxPackage $vcLibsBundleFile
# Download Winget-Create msixbundle, install, and execute update.
$appxBundleFile = "$env:TEMP\wingetcreate.msixbundle"
Invoke-WebRequest https://aka.ms/wingetcreate/latest/msixbundle -OutFile $appxBundleFile
Add-AppxPackage $appxBundleFile
# Create the PR
wingetcreate submit --token $Token $Version