fix: Add detailed logging to Create Release step for debugging
Auto Release / build (push) Successful in 27s
Auto Release / build (push) Successful in 27s
This commit is contained in:
@@ -32,18 +32,31 @@ jobs:
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
set -e
|
||||
# 从 plugin.yml 提取版本号作为标签
|
||||
VERSION=$(grep '^version:' src/main/resources/plugin.yml | awk '{print $2}' | tr -d '\r\n ')
|
||||
TAG="v${VERSION}"
|
||||
BASE="${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}"
|
||||
echo "Version: ${VERSION}, Tag: ${TAG}"
|
||||
echo "Token prefix: ${GITEA_TOKEN:0:8}..."
|
||||
|
||||
# 如果同版本标签已存在,先删除旧 release(允许重新发布同版本)
|
||||
OLD_ID=$(curl -s \
|
||||
# 测试 token 权限
|
||||
echo "=== Testing API access ==="
|
||||
curl -s -w "\nHTTP_CODE:%{http_code}\n" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
"${BASE}/releases/tags/${TAG}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||
if [ -n "$OLD_ID" ]; then
|
||||
echo "Tag ${TAG} already exists (release #${OLD_ID}), deleting..."
|
||||
"${BASE}" | tail -5
|
||||
|
||||
# 如果同版本标签已存在,先删除旧 release
|
||||
echo "=== Checking existing tag ${TAG} ==="
|
||||
RESP=$(curl -s -w "\nHTTP_CODE:%{http_code}" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
"${BASE}/releases/tags/${TAG}")
|
||||
HTTP_CODE=$(echo "$RESP" | grep -o 'HTTP_CODE:[0-9]*' | cut -d: -f2)
|
||||
echo "Check tag HTTP: ${HTTP_CODE}"
|
||||
|
||||
if [ "$HTTP_CODE" = "200" ]; then
|
||||
OLD_ID=$(echo "$RESP" | head -1 | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||
echo "Tag ${TAG} exists (release #${OLD_ID}), deleting..."
|
||||
curl -s -X DELETE \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
"${BASE}/releases/${OLD_ID}"
|
||||
@@ -51,26 +64,37 @@ jobs:
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
"${BASE}/tags/${TAG}"
|
||||
sleep 1
|
||||
elif [ "$HTTP_CODE" = "404" ]; then
|
||||
echo "Tag ${TAG} not found, will create new"
|
||||
else
|
||||
echo "Warning: unexpected response checking tag"
|
||||
fi
|
||||
|
||||
# 创建新 release
|
||||
curl -s -X POST \
|
||||
echo "=== Creating release ${TAG} ==="
|
||||
RELEASE_RESP=$(curl -s -w "\nHTTP_CODE:%{http_code}" -X POST \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"tag_name\":\"${TAG}\",\"name\":\"Sdf1_login ${TAG}\",\"body\":\"Version: ${VERSION}\\nCommit: ${{ gitea.sha }}\\nBranch: ${{ gitea.ref_name }}\",\"draft\":false,\"prerelease\":false}" \
|
||||
"${BASE}/releases"
|
||||
"${BASE}/releases")
|
||||
RELEASE_HTTP=$(echo "$RELEASE_RESP" | grep -o 'HTTP_CODE:[0-9]*' | cut -d: -f2)
|
||||
echo "Create release HTTP: ${RELEASE_HTTP}"
|
||||
|
||||
if [ "$RELEASE_HTTP" != "201" ]; then
|
||||
echo "=== Release creation failed! ==="
|
||||
echo "$RELEASE_RESP" | head -1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 上传 JAR 资产
|
||||
RELEASE_ID=$(curl -s \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
"${BASE}/releases/tags/${TAG}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||
|
||||
RELEASE_ID=$(echo "$RELEASE_RESP" | head -1 | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||
if [ -n "$RELEASE_ID" ]; then
|
||||
echo "=== Uploading JAR to release #${RELEASE_ID} ==="
|
||||
curl -s -X POST \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-F "attachment=@target/Sdf1_login.jar" \
|
||||
"${BASE}/releases/${RELEASE_ID}/assets"
|
||||
echo "Release ${TAG} created with JAR"
|
||||
echo "✅ Release ${TAG} created with JAR"
|
||||
else
|
||||
echo "Release tag ${TAG} created (JAR attach may need manual check)"
|
||||
echo "⚠️ Release created but could not get release ID for JAR upload"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user