-
Notifications
You must be signed in to change notification settings - Fork 52
/
package_release_with_server.ps1
112 lines (89 loc) · 2.92 KB
/
package_release_with_server.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
Param(
[Parameter(Mandatory = $false)]
[Switch] $Overwrite,
[Parameter(Mandatory = $false)]
[string] $Branch,
[Parameter(Mandatory = $false)]
[string] $Commit,
[Parameter(Mandatory = $true)]
[string] $SITCoopVer
)
$ErrorActionPreference = "Stop"
$SOURCE_REPO = "https://dev.sp-tarkov.com/SPT-AKI/Server.git"
$SERVER_DIR = "./Aki-Server"
$ZIP_Folder = "./tempZipContents"
# build coop mod
npm ci
npm run build
if ($LASTEXITCODE -ne 0) {
throw "coop mod npm run build failed, exit code $LASTEXITCODE"
}
# clone aki server
if (Test-Path -Path $SERVER_DIR) {
if ($Overwrite -or (Read-Host "$SERVER_DIR exists, delete? [y/n]") -eq 'y') {
Write-Output "$SERVER_DIR exists, removing"
Remove-Item -Recurse -Force $SERVER_DIR
}
else {
Exit 1
}
}
Write-Output "clone repo"
if ($Branch.Length -gt 0) {
Write-Output "Cloning branch/tag $Branch"
git clone --depth 1 -b $Branch $SOURCE_REPO $SERVER_DIR
} else {
Write-Output "Cloning default branch"
git clone --depth 1 $SOURCE_REPO $SERVER_DIR
}
Set-Location $SERVER_DIR
if ($Commit.Length -gt 0) {
Write-Output "Checking out the commit $Commit"
git fetch --depth=1 $SOURCE_REPO $Commit
git checkout $Commit
if ($LASTEXITCODE -ne 0) {
throw "Commit $Commit checkout failed. It doesn't exist? git exit code $LASTEXITCODE"
}
} else {
$Commit = git rev-parse HEAD
}
$packageJsonPath = "./project/package.json"
$akiVer = (Get-Content $packageJsonPath -Raw | ConvertFrom-Json).version
Write-Output "AKI_VERSION=$akiVer" >> "$env:GITHUB_OUTPUT"
Write-Output "lfs"
git lfs fetch
git lfs pull
Write-Output "build"
Set-Location ./project
if ($IsWindows) {
npm install
npm run build:release
} else {
rm -rf node_modules
rm -f package-lock.json
npm cache clean --force
npm install
npm run build:release
}
if ($LASTEXITCODE -ne 0) {
throw "npm run build:release failed, exit code $LASTEXITCODE"
}
Set-Location ../../
New-Item -ItemType Directory -Force -Path "$ZIP_Folder/user/mods/"
Copy-Item -Path "$SERVER_DIR/project/build\*" -Destination "$ZIP_Folder" -Recurse
Copy-Item -Path "./SITCoop" -Destination "$ZIP_Folder/user/mods/" -Recurse
# make release package
if ($IsWindows) {
$CommitShort = $Commit.Substring(0, 6)
$ZipName = "SITCoop-$SITCoopVer-WithAki$akiVer-$CommitShort-win.zip"
Compress-Archive -Path "$ZIP_Folder/*" -DestinationPath "$ZipName" -Force
} else {
$CommitShort = $Commit.Substring(0, 6)
$ZipName = "SITCoop-$SITCoopVer-WithAki$akiVer-$CommitShort-linux.tar.gz"
Set-Location "$ZIP_Folder"
tar --overwrite -czf "../$ZipName" ./*
}
# After calculating $ZipName, $akiVer, and $CommitShort
Write-Output "ZIP_NAME=$ZipName" | Out-File -Append -FilePath $Env:GITHUB_ENV
Write-Output "AKI_VERSION=$akiVer" | Out-File -Append -FilePath $Env:GITHUB_ENV
Write-Output "COMMIT_SHORT=$CommitShort" | Out-File -Append -FilePath $Env:GITHUB_ENV