Skip to content

Commit 19f0a57

Browse files
authored
Update gradle-publish-jitpack.yml
1 parent dd1c78f commit 19f0a57

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

.github/workflows/gradle-publish-jitpack.yml

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,57 @@ on:
77
jobs:
88
publish:
99
runs-on: ubuntu-latest
10-
11-
# 可选:排除预发布版本
12-
if: ${{ !github.event.release.prerelease }}
13-
10+
permissions:
11+
contents: read # 必须的基础权限
12+
1413
steps:
1514
- name: Checkout code
1615
uses: actions/checkout@v4
1716
with:
1817
fetch-depth: 0 # JitPack需要完整的git历史记录
1918

2019
- name: Verify Release Tag
21-
id: verify-tag
2220
run: |
23-
# 检查tag名称是否符合语义化版本规范
24-
if [[ ! ${{ github.event.release.tag_name }} =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+)?$ ]]; then
25-
echo "::error::Tag name ${{ github.event.release.tag_name }} does not follow semantic versioning"
21+
# 严格校验Tag格式(支持v前缀和纯数字版本)
22+
if [[ ! "${{ github.event.release.tag_name }}" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
23+
echo "::error::Invalid tag format. Must be like 1.0.0 or v1.0.0"
2624
exit 1
2725
fi
28-
echo "Valid tag: ${{ github.event.release.tag_name }}"
2926
30-
- name: Trigger JitPack build
27+
- name: Trigger JitPack Build
3128
env:
32-
JITPACK_TOKEN: ${{ secrets.JITPACK_TOKEN }}
29+
JITPACK_TOKEN: ${{ secrets.JITPACK_TOKEN }} # GitHub PAT with repo scope
3330
run: |
34-
# 提取版本号(保留原始格式
31+
# 保留原始Tag格式(不修改v前缀
3532
VERSION=${{ github.event.release.tag_name }}
36-
37-
echo "Triggering JitPack build for version $VERSION"
38-
39-
# 使用JitPack API触发构建
40-
RESPONSE=$(curl -X POST \
41-
"https://jitpack.io/api/builds/com.github.${{ github.repository_owner }}/${{ github.event.repository.name }}/$VERSION" \
42-
-H "Authorization: Bearer $JITPACK_TOKEN")
43-
44-
echo "API Response: $RESPONSE"
45-
46-
if [[ -z "$RESPONSE" || $RESPONSE == *"error"* ]]; then
47-
echo "::error::Failed to trigger JitPack build"
33+
OWNER=${{ github.repository_owner }}
34+
REPO=${{ github.event.repository.name }}
35+
36+
echo "Triggering build for: com.github.$OWNER/$REPO@$VERSION"
37+
38+
# JitPack官方GET API
39+
API_URL="https://jitpack.io/api/builds/com.github.$OWNER/$REPO/$VERSION"
40+
41+
# 带认证的GET请求
42+
RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \
43+
-H "Authorization: Bearer $JITPACK_TOKEN" \
44+
"$API_URL")
45+
46+
# 提取HTTP状态码和响应体
47+
HTTP_STATUS=$(echo "$RESPONSE" | grep HTTP_STATUS: | cut -d':' -f2)
48+
BODY=$(echo "$RESPONSE" | sed '/HTTP_STATUS:/d')
49+
50+
echo "API Response: $BODY"
51+
echo "HTTP Status: $HTTP_STATUS"
52+
53+
if [[ "$HTTP_STATUS" != "200" ]]; then
54+
echo "::error::JitPack API failed with status $HTTP_STATUS"
4855
exit 1
4956
fi
5057
51-
- name: Verify JitPack Build
58+
- name: Monitor Build Status
5259
run: |
5360
VERSION=${{ github.event.release.tag_name }}
54-
echo "Check build status at:"
61+
echo "Monitor build progress at:"
5562
echo "https://jitpack.io/#${{ github.repository }}/$VERSION"
56-
echo "If build fails, you can retry manually at the above URL"
63+
echo "Note: Building may take 3-5 minutes"

0 commit comments

Comments
 (0)