Merge branch 'main' of https://git.fig-lang.cn/PuqiAR/Fig
This commit is contained in:
@@ -29,16 +29,22 @@ jobs:
|
|||||||
git clone https://git.fig-lang.cn/${{ github.repository }} .
|
git clone https://git.fig-lang.cn/${{ github.repository }} .
|
||||||
git checkout ${{ github.ref }}
|
git checkout ${{ github.ref }}
|
||||||
|
|
||||||
- name: 设置版本
|
- name: 设置版本和提交信息
|
||||||
run: |
|
run: |
|
||||||
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||||
VERSION="${{ inputs.version }}"
|
VERSION="${{ inputs.version }}"
|
||||||
else
|
else
|
||||||
VERSION="${GITHUB_REF#refs/tags/}"
|
VERSION="${{ github.ref_name }}"
|
||||||
fi
|
fi
|
||||||
echo "构建版本: $VERSION"
|
echo "构建版本: $VERSION"
|
||||||
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
# 拿提交消息
|
||||||
|
COMMIT_MSG=$(git log -1 --pretty=%B)
|
||||||
|
echo "COMMIT_MSG<<EOF" >> $GITHUB_ENV
|
||||||
|
echo "$COMMIT_MSG" >> $GITHUB_ENV
|
||||||
|
echo "EOF" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: 构建项目 (Linux)
|
- name: 构建项目 (Linux)
|
||||||
run: |
|
run: |
|
||||||
echo "开始构建Linux版本..."
|
echo "开始构建Linux版本..."
|
||||||
@@ -83,48 +89,74 @@ jobs:
|
|||||||
GITEA_TOKEN: ${{ secrets.CI_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.CI_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
VERSION="${{ env.VERSION }}"
|
VERSION="${{ env.VERSION }}"
|
||||||
|
if [ -z "$VERSION" ]; then
|
||||||
|
VERSION="${{ github.ref_name }}"
|
||||||
|
fi
|
||||||
|
COMMIT_MSG="${{ env.COMMIT_MSG }}"
|
||||||
API="https://git.fig-lang.cn/api/v1/repos/${{ github.repository }}"
|
API="https://git.fig-lang.cn/api/v1/repos/${{ github.repository }}"
|
||||||
|
|
||||||
echo "正在为Linux版本创建/更新发布 $VERSION ..."
|
echo "正在检查版本 $VERSION 的发布状态..."
|
||||||
|
|
||||||
RESPONSE=$(curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" \
|
# 准备 JSON 数据
|
||||||
-H "Content-Type: application/json" \
|
VERSION="$VERSION" COMMIT_MSG="$COMMIT_MSG" python3 -c "import json, os; print(json.dumps({'tag_name': os.environ.get('VERSION', ''), 'name': 'Fig ' + os.environ.get('VERSION', ''), 'body': os.environ.get('COMMIT_MSG', ''), 'draft': False, 'prerelease': False}))" > release_body.json
|
||||||
-d "{\"tag_name\":\"$VERSION\",\"name\":\"Fig $VERSION\",\"draft\":false,\"prerelease\":false}" \
|
|
||||||
"$API/releases" 2>/dev/null || echo '{"id":0}')
|
|
||||||
|
|
||||||
RELEASE_ID=$(echo "$RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d':' -f2)
|
# 1. 尝试获取已有发布
|
||||||
|
RESPONSE_TAG=$(curl -sS -H "Authorization: token $GITEA_TOKEN" "$API/releases/tags/$VERSION" 2>/dev/null || echo '{"id":0}')
|
||||||
|
RELEASE_ID=$(echo "$RESPONSE_TAG" | grep -o '"id":[0-9]*' | head -1 | cut -d':' -f2)
|
||||||
|
|
||||||
if [ -z "$RELEASE_ID" ] || [ "$RELEASE_ID" = "0" ]; then
|
if [ -n "$RELEASE_ID" ] && [ "$RELEASE_ID" != "0" ]; then
|
||||||
echo "尝试通过标签获取已有发布的ID..."
|
echo "✅ 找到已有发布 (ID: $RELEASE_ID),正在更新说明..."
|
||||||
RELEASE_ID=$(curl -sS -H "Authorization: token $GITEA_TOKEN" \
|
curl -sS -X PATCH -H "Authorization: token $GITEA_TOKEN" \
|
||||||
"$API/releases/tags/$VERSION" | grep -o '"id":[0-9]*' | head -1 | cut -d':' -f2)
|
-H "Content-Type: application/json" \
|
||||||
|
-d @release_body.json \
|
||||||
|
"$API/releases/$RELEASE_ID" > /dev/null
|
||||||
|
else
|
||||||
|
echo "未找到已有发布,准备创建新发布..."
|
||||||
|
RESPONSE=$(curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d @release_body.json \
|
||||||
|
"$API/releases" 2>/dev/null || echo '{"id":0}')
|
||||||
|
|
||||||
|
RELEASE_ID=$(echo "$RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d':' -f2)
|
||||||
|
|
||||||
|
if [ -z "$RELEASE_ID" ] || [ "$RELEASE_ID" = "0" ]; then
|
||||||
|
# 再次尝试获取,防止并发冲突
|
||||||
|
RESPONSE_TAG=$(curl -sS -H "Authorization: token $GITEA_TOKEN" "$API/releases/tags/$VERSION" 2>/dev/null || echo '{"id":0}')
|
||||||
|
RELEASE_ID=$(echo "$RESPONSE_TAG" | grep -o '"id":[0-9]*' | head -1 | cut -d':' -f2)
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$RELEASE_ID" ]; then
|
if [ -z "$RELEASE_ID" ] || [ "$RELEASE_ID" = "0" ]; then
|
||||||
echo "错误:无法获取或创建发布 ID"
|
echo "❌ 错误:无法获取或创建发布 ID"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "使用发布 ID: $RELEASE_ID 进行上传"
|
echo "✅ 使用发布 ID: $RELEASE_ID 进行上传"
|
||||||
|
|
||||||
# 上传语言包
|
# 上传资产
|
||||||
|
PACKAGE_ZIP="Fig-$VERSION-linux-x86_64.tar.gz"
|
||||||
|
PACKAGE_SHA="Fig-$VERSION-linux-x86_64.sha256"
|
||||||
|
|
||||||
|
echo "正在上传 $PACKAGE_ZIP ..."
|
||||||
curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" \
|
curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" \
|
||||||
-H "Content-Type: application/octet-stream" \
|
-H "Content-Type: application/octet-stream" \
|
||||||
--data-binary @Fig-$VERSION-linux-x86_64.tar.gz \
|
--data-binary "@$PACKAGE_ZIP" \
|
||||||
"$API/releases/$RELEASE_ID/assets?name=Fig-$VERSION-linux-x86_64.tar.gz"
|
"$API/releases/$RELEASE_ID/assets?name=$PACKAGE_ZIP" > /dev/null
|
||||||
|
|
||||||
|
echo "正在上传 $PACKAGE_SHA ..."
|
||||||
curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" \
|
curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" \
|
||||||
-H "Content-Type: text/plain" \
|
-H "Content-Type: text/plain" \
|
||||||
--data-binary @Fig-$VERSION-linux-x86_64.sha256 \
|
--data-binary "@$PACKAGE_SHA" \
|
||||||
"$API/releases/$RELEASE_ID/assets?name=Fig-$VERSION-linux-x86_64.sha256"
|
"$API/releases/$RELEASE_ID/assets?name=$PACKAGE_SHA" > /dev/null
|
||||||
|
|
||||||
# 🔧 新增:上传Linux安装器
|
# 🔧 上传Linux安装器
|
||||||
if [ -f "Installer/ConsoleInstaller/dist/linux/FigSetup-Linux" ]; then
|
INSTALLER="Installer/ConsoleInstaller/dist/linux/FigSetup-Linux"
|
||||||
|
if [ -f "$INSTALLER" ]; then
|
||||||
echo "正在上传Linux安装器..."
|
echo "正在上传Linux安装器..."
|
||||||
curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" \
|
curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" \
|
||||||
-H "Content-Type: application/octet-stream" \
|
-H "Content-Type: application/octet-stream" \
|
||||||
--data-binary @Installer/ConsoleInstaller/dist/linux/FigSetup-Linux \
|
--data-binary "@$INSTALLER" \
|
||||||
"$API/releases/$RELEASE_ID/assets?name=FigSetup-Linux"
|
"$API/releases/$RELEASE_ID/assets?name=FigSetup-Linux" > /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "✅ Linux版本发布完成!"
|
echo "✅ Linux版本发布完成!"
|
||||||
@@ -151,9 +183,9 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
$env:Path = "C:\Program Files\Git\cmd;$env:Path"
|
$env:Path = "C:\Program Files\Git\cmd;$env:Path"
|
||||||
git clone https://git.fig-lang.cn/$env:GITHUB_REPOSITORY .
|
git clone https://git.fig-lang.cn/$env:GITHUB_REPOSITORY .
|
||||||
git checkout $env:GITHUB_REF
|
git checkout ${{ github.ref }}
|
||||||
|
|
||||||
- name: 设置版本
|
- name: 设置版本和提交信息
|
||||||
run: |
|
run: |
|
||||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||||
if ($env:GITHUB_EVENT_NAME -eq 'workflow_dispatch') {
|
if ($env:GITHUB_EVENT_NAME -eq 'workflow_dispatch') {
|
||||||
@@ -161,10 +193,16 @@ jobs:
|
|||||||
if (-not $VERSION) { $VERSION = $env:VERSION_INPUT }
|
if (-not $VERSION) { $VERSION = $env:VERSION_INPUT }
|
||||||
if (-not $VERSION) { $VERSION = "dev-build" }
|
if (-not $VERSION) { $VERSION = "dev-build" }
|
||||||
} else {
|
} else {
|
||||||
$VERSION = $env:GITHUB_REF_NAME
|
$VERSION = "${{ github.ref_name }}"
|
||||||
}
|
}
|
||||||
Write-Host "构建版本: $VERSION"
|
Write-Host "构建版本: $VERSION"
|
||||||
"VERSION=$VERSION" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
|
||||||
|
# 确保无 BOM 的 UTF8
|
||||||
|
[System.IO.File]::AppendAllText($env:GITHUB_ENV, "VERSION=$VERSION`n")
|
||||||
|
|
||||||
|
# 提交消息
|
||||||
|
$COMMIT_MSG = git log -1 --pretty=%B
|
||||||
|
[System.IO.File]::AppendAllText($env:GITHUB_ENV, "COMMIT_MSG<<EOF`n$COMMIT_MSG`nEOF`n")
|
||||||
|
|
||||||
- name: 构建项目 (Windows Native)
|
- name: 构建项目 (Windows Native)
|
||||||
run: |
|
run: |
|
||||||
@@ -186,14 +224,11 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||||
|
|
||||||
# 🔧 修改:与发布步骤使用相同的版本号计算逻辑
|
$VERSION = $env:VERSION
|
||||||
if ($env:GITHUB_EVENT_NAME -eq 'workflow_dispatch') {
|
if (-not $VERSION) {
|
||||||
$VERSION = $env:INPUT_VERSION
|
$VERSION = "${{ github.ref_name }}"
|
||||||
if (-not $VERSION) { $VERSION = "dev-build" }
|
Write-Host "⚠️ 警告:从环境变量获取 VERSION 失败,回退到 github.ref_name: $VERSION"
|
||||||
} else {
|
|
||||||
$VERSION = $env:GITHUB_REF_NAME
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "打包版本: $VERSION"
|
Write-Host "打包版本: $VERSION"
|
||||||
|
|
||||||
$PACKAGE_NAME = "Fig-${VERSION}-windows-x86_64"
|
$PACKAGE_NAME = "Fig-${VERSION}-windows-x86_64"
|
||||||
@@ -231,91 +266,100 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||||
|
|
||||||
# 重新计算版本号(不使用 $env:VERSION)
|
$VERSION = $env:VERSION
|
||||||
if ($env:GITHUB_EVENT_NAME -eq 'workflow_dispatch') {
|
$COMMIT_MSG = $env:COMMIT_MSG
|
||||||
$VERSION = $env:INPUT_VERSION
|
|
||||||
if (-not $VERSION) { $VERSION = "dev-build" }
|
if (-not $VERSION) {
|
||||||
} else {
|
$VERSION = "${{ github.ref_name }}"
|
||||||
$VERSION = $env:GITHUB_REF_NAME
|
Write-Host "⚠️ 警告:从环境变量获取 VERSION 失败,回退到 github.ref_name: $VERSION"
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "正在上传Windows版本到发布: $VERSION"
|
if (-not $VERSION) {
|
||||||
|
Write-Host "❌ 错误:版本号仍然为空,无法创建发布。"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
$REPO = $env:GITHUB_REPOSITORY
|
$REPO = $env:GITHUB_REPOSITORY
|
||||||
$API = "https://git.fig-lang.cn/api/v1/repos/$REPO"
|
$API = "https://git.fig-lang.cn/api/v1/repos/$REPO"
|
||||||
$TOKEN = $env:GITEA_TOKEN
|
$TOKEN = $env:GITEA_TOKEN
|
||||||
|
$HEADERS = @{
|
||||||
|
Authorization = "token $TOKEN"
|
||||||
|
'Content-Type' = 'application/json'
|
||||||
|
}
|
||||||
|
|
||||||
# 🔧 新增:检查必需的文件是否存在
|
|
||||||
$ZIP_FILE = "Fig-$VERSION-windows-x86_64.zip"
|
$ZIP_FILE = "Fig-$VERSION-windows-x86_64.zip"
|
||||||
$HASH_FILE = "Fig-$VERSION-windows-x86_64.sha256"
|
$HASH_FILE = "Fig-$VERSION-windows-x86_64.sha256"
|
||||||
$INSTALLER_PATH = "Installer\ConsoleInstaller\dist\windows\FigSetup.exe"
|
$INSTALLER_PATH = "Installer\ConsoleInstaller\dist\windows\FigSetup.exe"
|
||||||
|
|
||||||
if (-not (Test-Path $ZIP_FILE)) {
|
if (-not (Test-Path $ZIP_FILE)) {
|
||||||
Write-Host "❌ 错误:找不到ZIP文件 $ZIP_FILE"
|
Write-Host "❌ 错误:找不到ZIP文件 $ZIP_FILE"
|
||||||
Get-ChildItem *.zip
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "正在为Windows版本创建/更新发布 $VERSION ..."
|
|
||||||
|
|
||||||
# 🔧 关键修改:直接创建发布,不先检查(与Linux逻辑一致)
|
|
||||||
$CREATE_BODY = @{
|
$CREATE_BODY = @{
|
||||||
tag_name = $VERSION
|
tag_name = $VERSION
|
||||||
name = "Fig $VERSION"
|
name = "Fig $VERSION"
|
||||||
|
body = $COMMIT_MSG
|
||||||
draft = $false
|
draft = $false
|
||||||
prerelease = $false
|
prerelease = $false
|
||||||
} | ConvertTo-Json -Compress
|
} | ConvertTo-Json -Compress
|
||||||
|
|
||||||
Write-Host "创建发布请求体: $CREATE_BODY"
|
Write-Host "正在检查版本 $VERSION 的发布状态..."
|
||||||
|
$RELEASE_ID = $null
|
||||||
|
|
||||||
# 直接创建发布(Gitea会自动处理重复创建)
|
try {
|
||||||
$RESPONSE = Invoke-RestMethod -Method Post -Uri "$API/releases" `
|
$EXISTING = Invoke-RestMethod -Uri "$API/releases/tags/$VERSION" -Headers $HEADERS -ErrorAction Stop
|
||||||
-Headers @{
|
if ($EXISTING -and $EXISTING.id) {
|
||||||
Authorization = "token $TOKEN"
|
$RELEASE_ID = $EXISTING.id
|
||||||
'Content-Type' = 'application/json'
|
Write-Host "✅ 找到已有发布 (ID: $RELEASE_ID),正在更新..."
|
||||||
} -Body $CREATE_BODY -ErrorAction SilentlyContinue
|
Invoke-RestMethod -Method Patch -Uri "$API/releases/$RELEASE_ID" -Headers $HEADERS -Body $CREATE_BODY -ErrorAction Stop | Out-Null
|
||||||
|
}
|
||||||
if (-not $RESPONSE -or -not $RESPONSE.id) {
|
} catch {
|
||||||
# 如果创建失败,尝试通过标签获取已有发布的ID
|
Write-Host "未找到已有发布,准备创建新发布..."
|
||||||
Write-Host "创建失败,尝试获取已有发布..."
|
|
||||||
$RESPONSE = Invoke-RestMethod -Uri "$API/releases/tags/$VERSION" `
|
|
||||||
-Headers @{Authorization = "token $TOKEN" } `
|
|
||||||
-ErrorAction SilentlyContinue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($RESPONSE -and $RESPONSE.id) {
|
if (-not $RELEASE_ID) {
|
||||||
$RELEASE_ID = $RESPONSE.id
|
try {
|
||||||
Write-Host "✅ 使用发布 ID: $RELEASE_ID 进行上传"
|
Write-Host "正在创建新发布: $VERSION ..."
|
||||||
} else {
|
$RESPONSE = Invoke-RestMethod -Method Post -Uri "$API/releases" -Headers $HEADERS -Body $CREATE_BODY -ErrorAction Stop
|
||||||
Write-Host "❌ 错误:无法获取或创建发布 ID"
|
$RELEASE_ID = $RESPONSE.id
|
||||||
exit 1
|
Write-Host "✅ 发布创建成功 (ID: $RELEASE_ID)"
|
||||||
|
} catch {
|
||||||
|
$err = $_.Exception.Message
|
||||||
|
Write-Host "❌ 创建发布失败: $err"
|
||||||
|
# 最后一次尝试:再次尝试按标签获取,防止由于并发导致的冲突
|
||||||
|
try {
|
||||||
|
$RETRY = Invoke-RestMethod -Uri "$API/releases/tags/$VERSION" -Headers $HEADERS -ErrorAction Stop
|
||||||
|
$RELEASE_ID = $RETRY.id
|
||||||
|
Write-Host "✅ 重试获取发布成功 (ID: $RELEASE_ID)"
|
||||||
|
} catch {
|
||||||
|
Write-Host "❌ 无法获取或创建发布 ID"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# 上传资产
|
# 上传资产
|
||||||
Write-Host "正在上传 ZIP 文件..."
|
Write-Host "正在上传文件..."
|
||||||
Invoke-RestMethod -Method Post -Uri "$API/releases/$RELEASE_ID/assets?name=$ZIP_FILE" `
|
$ASSETS = @(
|
||||||
-Headers @{
|
@{ Name = $ZIP_FILE; Path = $ZIP_FILE; ContentType = "application/octet-stream" },
|
||||||
Authorization = "token $TOKEN"
|
@{ Name = $HASH_FILE; Path = $HASH_FILE; ContentType = "text/plain" }
|
||||||
'Content-Type' = 'application/octet-stream'
|
)
|
||||||
} -InFile $ZIP_FILE -ErrorAction SilentlyContinue
|
|
||||||
|
|
||||||
Write-Host "正在上传校验文件..."
|
|
||||||
Invoke-RestMethod -Method Post -Uri "$API/releases/$RELEASE_ID/assets?name=$HASH_FILE" `
|
|
||||||
-Headers @{
|
|
||||||
Authorization = "token $TOKEN"
|
|
||||||
'Content-Type' = 'text/plain'
|
|
||||||
} -InFile $HASH_FILE -ErrorAction SilentlyContinue
|
|
||||||
|
|
||||||
# 上传Windows安装器
|
|
||||||
if (Test-Path $INSTALLER_PATH) {
|
if (Test-Path $INSTALLER_PATH) {
|
||||||
Write-Host "正在上传Windows安装器..."
|
$ASSETS += @{ Name = "FigSetup.exe"; Path = $INSTALLER_PATH; ContentType = "application/octet-stream" }
|
||||||
Invoke-RestMethod -Method Post -Uri "$API/releases/$RELEASE_ID/assets?name=FigSetup.exe" `
|
}
|
||||||
-Headers @{
|
|
||||||
Authorization = "token $TOKEN"
|
foreach ($asset in $ASSETS) {
|
||||||
'Content-Type' = 'application/octet-stream'
|
Write-Host "正在上传 $($asset.Name) ..."
|
||||||
} -InFile $INSTALLER_PATH -ErrorAction SilentlyContinue
|
try {
|
||||||
} else {
|
# 如果资产已存在,Gitea 可能会报错,这里简单处理
|
||||||
Write-Host "⚠️ 警告:未找到安装器文件 $INSTALLER_PATH"
|
Invoke-RestMethod -Method Post -Uri "$API/releases/$RELEASE_ID/assets?name=$($asset.Name)" `
|
||||||
|
-Headers @{ Authorization = "token $TOKEN"; 'Content-Type' = $asset.ContentType } `
|
||||||
|
-InFile $asset.Path -ErrorAction SilentlyContinue | Out-Null
|
||||||
|
} catch {
|
||||||
|
Write-Host "⚠️ 上传 $($asset.Name) 失败,可能已存在。"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "✅ Windows版本发布完成!"
|
Write-Host "✅ Windows版本发布完成!"
|
||||||
Reference in New Issue
Block a user