1
+ param ($IEModFolder )
1
2
2
- function New-GithubReleaseDescription { param ($ReleaseDescription )
3
+ function New-GithubReleaseDescription {
4
+ param ($ReleaseDescription )
3
5
4
6
Add-Type - AssemblyName System.Windows.Forms
5
7
$form = New-Object System.Windows.Forms.Form
@@ -32,7 +34,8 @@ function New-GithubReleaseDescription { param($ReleaseDescription)
32
34
}
33
35
}
34
36
35
- function Get-IEModVersion { param ($FullName )
37
+ function Get-IEModVersion {
38
+ param ($FullName )
36
39
$regexVersion = New-Object System.Text.RegularExpressions.Regex(' .*?VERSION(\s*)(|~"|~|"|)(@.+|.+)("~|"|~|)(|\s*)' , [System.Text.RegularExpressions.RegexOptions ]::IgnoreCase)
37
40
foreach ($line in [System.IO.File ]::ReadLines($FullName )) {
38
41
$line = $line -replace " \/\/(.*)(\n|)"
@@ -47,7 +50,8 @@ function Get-IEModVersion { param($FullName)
47
50
}
48
51
}
49
52
50
- function Update-GithubReleaseAsset { param ($FullName , $OrgUser , $Repository , $ReleaseID )
53
+ function Update-GithubReleaseAsset {
54
+ param ($FullName , $OrgUser , $Repository , $ReleaseID )
51
55
if ($FullName ) {
52
56
# DELETE existing asset with the same name
53
57
$json = Invoke-RestMethod " https://api.github.com/repos/$OrgUser /$repository /releases/tags/$newTagRelease " - Headers $Headers - Method GET
@@ -67,10 +71,29 @@ function Update-GithubReleaseAsset { param($FullName, $OrgUser, $Repository, $Re
67
71
# Fix for TLS12
68
72
[Net.ServicePointManager ]::SecurityProtocol = [Net.SecurityProtocolType ]::Tls12
69
73
74
+ # script directory as initial execution location
70
75
$ ( try { $script :MyInvocation.MyCommand.Path , $script :psISE.CurrentFile.Fullpath , $script :psEditor.GetEditorContext ().CurrentFile.Path, $script :dte.ActiveDocument.FullName } catch { $_ } ) | % { $_ | Split-Path - EA 0 | Set-Location }
71
76
72
- # Set this to you Personal access token
73
- $apiKey = Get-Content " .\#ModRelease-Github-Key.txt"
77
+ if ($IEModFolder ) {
78
+ Set-Location $IEModFolder
79
+ } else {
80
+ Write-Host " Cant determine mod top-level folder."
81
+ break
82
+ }
83
+
84
+ if ( ! (Get-Item ' ..\#ModRelease\#ModRelease-Github-Key.txt' )) {
85
+ Rename-Item ' ..\#ModRelease\#ModRelease-Github-Key-Example.txt' ' ..\#ModRelease\#ModRelease-Github-Key.txt' | Out-Null
86
+ }
87
+
88
+ # get Personal Access Token
89
+ $apiKey = Get-Content " ..\#ModRelease\#ModRelease-Github-Key.txt"
90
+
91
+ if ($apiKey.Length -ne 40 ) {
92
+ Write-Host " API-KEY length is not 40 characters, please check the first line of #ModRelease-Github-Key.txt"
93
+ pause
94
+ break
95
+ }
96
+
74
97
$repository = (Split-Path ( git config -- get remote.origin.url ) - Leaf ) -replace ' \.git'
75
98
$OrgUser = (Split-Path ( git config -- get remote.origin.url ) - Parent ) -replace ' https:\\\\github.com\\'
76
99
$username = git config -- get user.name
@@ -81,8 +104,8 @@ $Headers = @{ Authorization = 'Basic {0}' -f $Base64Token }
81
104
82
105
[array ]$dataReleases = ( Invoke-RestMethod " https://api.github.com/repos/$OrgUser /$repository /releases" - Headers $Headers - Method Get ).tag_name
83
106
84
- $tp2File = ( Get-ChildItem - Path $modFolder - Filter * .tp2 - Recurse )[0 ]
85
- $tp2FullPath = (( Get-ChildItem - Path $modFolder - Filter * .tp2 - Recurse )[0 ] ).FullName
107
+ $tp2File = ( Get-ChildItem - Path $IEModFolder - Filter * .tp2 - Recurse )[0 ]
108
+ $tp2FullPath = (( Get-ChildItem - Path $IEModFolder - Filter * .tp2 - Recurse )[0 ] ).FullName
86
109
$tp2Version = Get-IEModVersion - FullName $tp2FullPath
87
110
$newTagRelease = $tp2Version -replace " \s+" , ' _'
88
111
@@ -130,8 +153,6 @@ $Body = @{
130
153
body = $releaseDescription -join ' </br>'
131
154
} | ConvertTo-Json
132
155
133
-
134
-
135
156
$json = Invoke-RestMethod " https://api.github.com/repos/$OrgUser /$repository /releases" - Headers $Headers - Body $Body - Method POST
136
157
$json
137
158
0 commit comments