|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
| 15 | +param( |
| 16 | + [Parameter(Mandatory = $false)] |
| 17 | + [string]$Tag |
| 18 | +) |
| 19 | + |
| 20 | +if (-not $Tag -and $env:CODEX_TAG) { |
| 21 | + $Tag = $env:CODEX_TAG |
| 22 | +} |
| 23 | + |
15 | 24 | $ErrorActionPreference = "Stop" |
16 | 25 |
|
17 | 26 | $pluginName = "data-agent-kit-starter-pack" |
@@ -56,25 +65,26 @@ Write-Host "--- $pluginName Installer for Codex ---" |
56 | 65 | New-Item -ItemType Directory -Force -Path $pluginsRoot | Out-Null |
57 | 66 |
|
58 | 67 | if (Test-Path $installDir) { |
59 | | - try { |
60 | | - & git -C $installDir rev-parse --is-inside-work-tree 2>$null | Out-Null |
61 | | - } catch { |
62 | | - } |
| 68 | + $timestamp = Get-Date -Format "yyyyMMdd_HHmmss" |
| 69 | + $backupName = "$pluginName" + "_backup_" + $timestamp |
| 70 | + $backupPath = Join-Path (Split-Path $installDir) $backupName |
| 71 | + Write-Host "Backing up existing plugin to $backupPath..." |
| 72 | + Rename-Item -LiteralPath $installDir -NewName $backupName |
| 73 | + Write-Host "Notice: Your previous installation has been backed up to $backupPath." |
| 74 | + Write-Host "You can delete it if you do not need it." |
| 75 | +} |
63 | 76 |
|
64 | | - if ($LASTEXITCODE -eq 0) { |
65 | | - Write-Host "Updating existing plugin at $installDir..." |
66 | | - Invoke-GitCommand -Arguments @("-C", $installDir, "pull") |
67 | | - } else { |
68 | | - Write-Host "Existing directory at $installDir is not a valid git checkout. Reinstalling..." |
69 | | - Remove-Item -LiteralPath $installDir -Recurse -Force |
70 | | - Write-Host "Cloning plugin to $installDir..." |
71 | | - Invoke-GitCommand -Arguments @("clone", $repoUrl, $installDir) |
72 | | - } |
| 77 | +if ($Tag) { |
| 78 | + Write-Host "Cloning plugin version $Tag to $installDir..." |
| 79 | + Invoke-GitCommand -Arguments @("clone", "--depth", "1", "--branch", $Tag, $repoUrl, $installDir) |
73 | 80 | } else { |
74 | | - Write-Host "Cloning plugin to $installDir..." |
75 | | - Invoke-GitCommand -Arguments @("clone", $repoUrl, $installDir) |
| 81 | + Write-Host "Cloning plugin default branch to $installDir..." |
| 82 | + Invoke-GitCommand -Arguments @("clone", "--depth", "1", $repoUrl, $installDir) |
76 | 83 | } |
77 | 84 |
|
| 85 | +Write-Host "Removing git metadata..." |
| 86 | +Remove-Item -LiteralPath (Join-Path $installDir ".git") -Recurse -Force |
| 87 | + |
78 | 88 | if (-not (Test-Path $marketplaceFile)) { |
79 | 89 | Write-Host "Creating new personal marketplace..." |
80 | 90 | Write-TextFileNoBom -Path $marketplaceFile -Content '{"name":"personal","plugins":[]}' |
|
0 commit comments