Skip to content

Commit 2f94930

Browse files
committed
renaming
1 parent 99c833e commit 2f94930

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
replace this line with you "personal access token", example: 34fa4ce6bdec11b8abe0b5fc45b3d3b3330987a7
1+
rename this file to: #ModRelease-Github-Key.txt, replace this line with you "personal access token", example: 34fa4ce6bdec11b8abe0b5fc45b3d3b3330987a7

#ModRelease/#ModRelease.ps1

+30-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
param($IEModFolder)
12

2-
function New-GithubReleaseDescription { param($ReleaseDescription)
3+
function New-GithubReleaseDescription {
4+
param($ReleaseDescription)
35

46
Add-Type -AssemblyName System.Windows.Forms
57
$form = New-Object System.Windows.Forms.Form
@@ -32,7 +34,8 @@ function New-GithubReleaseDescription { param($ReleaseDescription)
3234
}
3335
}
3436

35-
function Get-IEModVersion { param($FullName)
37+
function Get-IEModVersion {
38+
param($FullName)
3639
$regexVersion = New-Object System.Text.RegularExpressions.Regex('.*?VERSION(\s*)(|~"|~|"|)(@.+|.+)("~|"|~|)(|\s*)', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
3740
foreach ($line in [System.IO.File]::ReadLines($FullName)) {
3841
$line = $line -replace "\/\/(.*)(\n|)"
@@ -47,7 +50,8 @@ function Get-IEModVersion { param($FullName)
4750
}
4851
}
4952

50-
function Update-GithubReleaseAsset { param($FullName, $OrgUser, $Repository, $ReleaseID)
53+
function Update-GithubReleaseAsset {
54+
param($FullName, $OrgUser, $Repository, $ReleaseID)
5155
if ($FullName) {
5256
# DELETE existing asset with the same name
5357
$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
6771
# Fix for TLS12
6872
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
6973

74+
# script directory as initial execution location
7075
$( 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 }
7176

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+
7497
$repository = (Split-Path ( git config --get remote.origin.url ) -Leaf ) -replace '\.git'
7598
$OrgUser = (Split-Path ( git config --get remote.origin.url ) -Parent ) -replace 'https:\\\\github.com\\'
7699
$username = git config --get user.name
@@ -81,8 +104,8 @@ $Headers = @{ Authorization = 'Basic {0}' -f $Base64Token }
81104

82105
[array]$dataReleases = ( Invoke-RestMethod "https://api.github.com/repos/$OrgUser/$repository/releases" -Headers $Headers -Method Get ).tag_name
83106

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
86109
$tp2Version = Get-IEModVersion -FullName $tp2FullPath
87110
$newTagRelease = $tp2Version -replace "\s+", '_'
88111

@@ -130,8 +153,6 @@ $Body = @{
130153
body = $releaseDescription -join '</br>'
131154
} | ConvertTo-Json
132155

133-
134-
135156
$json = Invoke-RestMethod "https://api.github.com/repos/$OrgUser/$repository/releases" -Headers $Headers -Body $Body -Method POST
136157
$json
137158

0 commit comments

Comments
 (0)