来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
135 lines
3.8 KiB
PowerShell
135 lines
3.8 KiB
PowerShell
# Push project to Gitea
|
|
# Usage:
|
|
# $env:GITEA_URL = "http://your-gitea.example.com"
|
|
# $env:GITEA_TOKEN = "your_access_token"
|
|
# $env:GITEA_OWNER = "your_username" # optional, defaults from API /user
|
|
# powershell -ExecutionPolicy Bypass -File scripts/push-to-gitea.ps1
|
|
#
|
|
# Or create .env.gitea in project root:
|
|
# GITEA_URL=https://git.xdjchuanhui.com
|
|
# GITEA_TOKEN=xxxxxxxx
|
|
# GITEA_OWNER=admin
|
|
|
|
param(
|
|
[string]$RepoName = "ai-fresh-delivery",
|
|
[string]$Description = "AI生鲜配送系统 - 智能生鲜供应链管理平台"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$root = Split-Path -Parent $PSScriptRoot
|
|
Set-Location $root
|
|
|
|
function Find-Git {
|
|
$cmd = Get-Command git -ErrorAction SilentlyContinue
|
|
if ($cmd) { return $cmd.Source }
|
|
$candidates = @(
|
|
"C:\Program Files\Git\bin\git.exe",
|
|
"C:\Program Files (x86)\Git\bin\git.exe",
|
|
"$root\.tools\PortableGit\bin\git.exe"
|
|
)
|
|
foreach ($p in $candidates) {
|
|
if (Test-Path $p) { return $p }
|
|
}
|
|
return $null
|
|
}
|
|
|
|
$git = Find-Git
|
|
if (-not $git) {
|
|
Write-Error @"
|
|
Git is not installed. Install Git for Windows first:
|
|
winget install Git.Git
|
|
Then re-run this script.
|
|
"@
|
|
}
|
|
|
|
$envFile = Join-Path $root ".env.gitea"
|
|
if (Test-Path $envFile) {
|
|
Get-Content $envFile | ForEach-Object {
|
|
if ($_ -match '^\s*#' -or $_ -match '^\s*$') { return }
|
|
$parts = $_ -split '=', 2
|
|
if ($parts.Length -eq 2) {
|
|
$name = $parts[0].Trim()
|
|
$value = $parts[1].Trim()
|
|
Set-Item -Path "Env:$name" -Value $value
|
|
}
|
|
}
|
|
}
|
|
|
|
$giteaUrl = $env:GITEA_URL
|
|
$giteaToken = $env:GITEA_TOKEN
|
|
$giteaOwner = $env:GITEA_OWNER
|
|
|
|
if (-not $giteaUrl -or -not $giteaToken) {
|
|
Write-Error @"
|
|
Missing Gitea config. Set environment variables or create .env.gitea:
|
|
GITEA_URL=http://your-gitea-host:3000
|
|
GITEA_TOKEN=your_personal_access_token
|
|
GITEA_OWNER=your_username
|
|
"@
|
|
}
|
|
|
|
$giteaUrl = $giteaUrl.TrimEnd('/')
|
|
|
|
Write-Host "Checking Gitea connection..." -ForegroundColor Cyan
|
|
$userResp = Invoke-RestMethod -Uri "$giteaUrl/api/v1/user" -Headers @{ Authorization = "token $giteaToken" }
|
|
if (-not $giteaOwner) { $giteaOwner = $userResp.username }
|
|
Write-Host "Gitea user: $giteaOwner" -ForegroundColor Green
|
|
|
|
Write-Host "Creating repository '$RepoName'..." -ForegroundColor Cyan
|
|
$createBody = @{
|
|
name = $RepoName
|
|
description = $Description
|
|
private = $false
|
|
auto_init = $false
|
|
} | ConvertTo-Json -Compress
|
|
|
|
try {
|
|
Invoke-RestMethod -Method POST -Uri "$giteaUrl/api/v1/user/repos" `
|
|
-Headers @{ Authorization = "token $giteaToken"; "Content-Type" = "application/json" } `
|
|
-Body $createBody | Out-Null
|
|
Write-Host "Repository created." -ForegroundColor Green
|
|
} catch {
|
|
$msg = $_.Exception.Message
|
|
if ($msg -match '409|already exists|exist') {
|
|
Write-Host "Repository already exists, will push to it." -ForegroundColor Yellow
|
|
} else {
|
|
throw
|
|
}
|
|
}
|
|
|
|
$repoPath = "$giteaOwner/$RepoName"
|
|
$cloneUrl = "$giteaUrl/$repoPath.git"
|
|
|
|
$uri = [Uri]$giteaUrl
|
|
$hostWithPort = if ($uri.IsDefaultPort) { $uri.Host } else { "$($uri.Host):$($uri.Port)" }
|
|
$authRemote = "$($uri.Scheme)://oauth2:$giteaToken@$hostWithPort/$repoPath.git"
|
|
|
|
if (-not (Test-Path (Join-Path $root ".git"))) {
|
|
& $git init
|
|
& $git branch -M main
|
|
}
|
|
|
|
& $git add -A
|
|
$status = & $git status --porcelain
|
|
if ($status) {
|
|
& $git -c user.email="dev@local" -c user.name="AI生鲜配送系统" commit -m "$( @'
|
|
Initial commit: AI生鲜配送系统
|
|
|
|
Express + PostgreSQL local stack for AI fresh food delivery management.
|
|
'@ )"
|
|
} else {
|
|
Write-Host "No changes to commit." -ForegroundColor Yellow
|
|
}
|
|
|
|
& $git remote remove origin 2>$null
|
|
& $git remote add origin $authRemote
|
|
|
|
Write-Host "Pushing to $cloneUrl ..." -ForegroundColor Cyan
|
|
& $git push -u origin main
|
|
|
|
& $git remote set-url origin $cloneUrl
|
|
|
|
Write-Host ""
|
|
Write-Host "Done!" -ForegroundColor Green
|
|
Write-Host "Repository: $cloneUrl" -ForegroundColor White
|