1# Based on the template in: https://docs.digitalocean.com/reference/api/spaces-api/
 2$ErrorActionPreference = "Stop"
 3. "$PSScriptRoot\lib\blob-store.ps1"
 4. "$PSScriptRoot\lib\workspace.ps1"
 5
 6$allowedTargets = @("windows")
 7
 8function Test-AllowedTarget {
 9    param (
10        [string]$Target
11    )
12
13    return $allowedTargets -contains $Target
14}
15
16# Process arguments
17if ($args.Count -gt 0) {
18    $target = $args[0]
19    if (Test-AllowedTarget $target) {
20        # Valid target
21    } else {
22        Write-Error "Error: Target '$target' is not allowed.`nUsage: $($MyInvocation.MyCommand.Name) [$($allowedTargets -join ', ')]"
23        exit 1
24    }
25} else {
26    Write-Error "Error: Target is not specified.`nUsage: $($MyInvocation.MyCommand.Name) [$($allowedTargets -join ', ')]"
27    exit 1
28}
29
30ParseZedWorkspace
31Write-Host "Uploading nightly for target: $target"
32
33$bucketName = "zed-nightly-host"
34
35# Get current git SHA
36$sha = git rev-parse HEAD
37$sha | Out-File -FilePath "target/latest-sha" -NoNewline
38
39# TODO:
40# Upload remote server files
41# $remoteServerFiles = Get-ChildItem -Path "target" -Filter "zed-remote-server-*.gz" -Recurse -File
42# foreach ($file in $remoteServerFiles) {
43#     Upload-ToBlobStore -BucketName $bucketName -FileToUpload $file.FullName -BlobStoreKey "nightly/$($file.Name)"
44#     Remove-Item -Path $file.FullName
45# }
46
47switch ($target) {
48    "windows" {
49        UploadToBlobStore -BucketName $bucketName -FileToUpload $env:SETUP_PATH -BlobStoreKey "nightly/Zed-x86_64.exe"
50        UploadToBlobStore -BucketName $bucketName -FileToUpload "target/latest-sha" -BlobStoreKey "nightly/latest-sha-windows"
51
52        Remove-Item -Path $env:SETUP_PATH -ErrorAction SilentlyContinue
53        Remove-Item -Path "target/latest-sha" -ErrorAction SilentlyContinue
54    }
55
56    default {
57        Write-Error "Error: Unknown target '$target'"
58        exit 1
59    }
60}