From 878ea7cc7624b5902a50a2f8fcefc15d8bd31b49 Mon Sep 17 00:00:00 2001 From: JoeAllen <2494136784@qq.com> Date: Tue, 29 Sep 2026 13:43:30 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20bump=201.0.3=EF=BC=9B=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E8=84=9A=E6=9C=AC=E9=9B=B6=E9=85=8D=E7=BD=AE=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 版本升级 1.0.2 → 1.0.3 - 脚本不再要求预置环境变量:GITEA_URL 从 git remote origin 推断, GITEA_TOKEN 缺失时自动取 Git Credential Manager 中同一主机的凭证 (与 git 推送同源的 OAuth 凭证,无需另行创建 API token) --- Cargo.lock | 2 +- gpui-app/Cargo.toml | 2 +- scripts/publish-gitea.ps1 | 33 ++++++++++++++++++++++++++++++--- scripts/publish-gitea.sh | 24 +++++++++++++++++++++--- 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b78db2c..1a469c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4135,7 +4135,7 @@ dependencies = [ [[package]] name = "mqttx-desktop" -version = "1.0.2" +version = "1.0.3" dependencies = [ "anyhow", "base64 0.22.1", diff --git a/gpui-app/Cargo.toml b/gpui-app/Cargo.toml index 4681a94..1082a81 100644 --- a/gpui-app/Cargo.toml +++ b/gpui-app/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mqttx-desktop" -version = "1.0.2" +version = "1.0.3" edition.workspace = true description = "MQTT X —— 基于 GPUI 的跨平台 MQTT 调试客户端" default-run = "mqttx" diff --git a/scripts/publish-gitea.ps1 b/scripts/publish-gitea.ps1 index 572ef78..619072d 100644 --- a/scripts/publish-gitea.ps1 +++ b/scripts/publish-gitea.ps1 @@ -48,12 +48,39 @@ try { function Die($msg) { Write-Error "错误: $msg"; exit 1 } # ── 必填配置 ──────────────────────────────────────────────────────────────── +# 地址:优先环境变量,否则从 git remote origin 推断 $GiteaUrl = $env:GITEA_URL -$Token = $env:GITEA_TOKEN -if (-not $GiteaUrl) { Die "缺少环境变量 GITEA_URL(如 https://gitea.example.com)" } -if (-not $Token) { Die "缺少环境变量 GITEA_TOKEN(需 package 写权限)" } +if (-not $GiteaUrl) { + $remote = git -C $Root remote get-url origin 2>$null + if ($remote) { + if ($remote -match "://") { $hostPart = (($remote -split "://", 2)[-1] -split "/", 2)[0] } + else { $hostPart = ($remote -split ":", 2)[0] } + $hostPart = ($hostPart -split "@")[-1] + if ($hostPart) { $GiteaUrl = "https://$hostPart" } + } +} +if (-not $GiteaUrl) { Die "缺少环境变量 GITEA_URL(如 https://gitea.example.com),且无法从 git remote 推断" } $GiteaUrl = $GiteaUrl.TrimEnd("/") +# 令牌:优先环境变量,否则取 Git Credential Manager 中同一主机的凭证 +# (即推送用的那条 OAuth 凭证,无需另行创建 API token) +$Token = $env:GITEA_TOKEN +if (-not $Token) { + try { + $env:GIT_TERMINAL_PROMPT = "0" + $env:GCM_INTERACTIVE = "Never" + $credHost = $GiteaUrl -replace "^https?://", "" + $raw = @("protocol=https", "host=$credHost", "") | git credential fill 2>$null + $Token = ($raw | Where-Object { $_ -like "password=*" }) -replace "^password=", "" + } + catch { $Token = $null } + finally { + Remove-Item Env:GIT_TERMINAL_PROMPT -ErrorAction SilentlyContinue + Remove-Item Env:GCM_INTERACTIVE -ErrorAction SilentlyContinue + } +} +if (-not $Token) { Die "缺少环境变量 GITEA_TOKEN,且无法从 git credential store 自动获取" } + $Root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path) $Pkg = if ($PackageName) { $PackageName } elseif ($env:GITEA_PKG) { $env:GITEA_PKG } else { "mqttx" } diff --git a/scripts/publish-gitea.sh b/scripts/publish-gitea.sh index c30b3ab..ea363e8 100644 --- a/scripts/publish-gitea.sh +++ b/scripts/publish-gitea.sh @@ -20,11 +20,29 @@ set -euo pipefail die() { echo "错误: $*" >&2; exit 1; } -[ -n "${GITEA_URL:-}" ] || die "缺少 GITEA_URL" -[ -n "${GITEA_TOKEN:-}" ] || die "缺少 GITEA_TOKEN" +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +# ── 地址:优先环境变量,否则从 git remote origin 推断 ──────────────────────── +if [ -z "${GITEA_URL:-}" ]; then + remote_url="$(git -C "$ROOT" remote get-url origin 2>/dev/null || true)" + case "$remote_url" in + *://*) host="${remote_url#*://}"; host="${host%%/*}" ;; + *:*) host="${remote_url%%:*}" ;; + *) host="" ;; + esac + host="${host##*@}" # 去掉 git@user@ 前缀 + [ -n "$host" ] && GITEA_URL="https://$host" +fi +[ -n "${GITEA_URL:-}" ] || die "缺少 GITEA_URL(或配置 git remote origin)" GITEA_URL="${GITEA_URL%/}" -ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +# ── 令牌:优先环境变量,否则取 Git Credential Manager 中同一主机的凭证 ──────── +if [ -z "${GITEA_TOKEN:-}" ]; then + GITEA_TOKEN="$(printf 'protocol=https\nhost=%s\n\n' "${GITEA_URL#*://}" \ + | GCM_INTERACTIVE=Never GIT_TERMINAL_PROMPT=0 git credential fill 2>/dev/null \ + | sed -n 's/^password=//p')" + [ -n "${GITEA_TOKEN:-}" ] || die "缺少 GITEA_TOKEN,且无法从 git credential store 自动获取" +fi PKG="${GITEA_PKG:-mqttx}" # ── owner/repo:优先环境变量,其次从 git remote 推断 ─────────────────────────