|
7 | 7 | jobs: |
8 | 8 | publish: |
9 | 9 | runs-on: ubuntu-latest |
10 | | - |
11 | | - # 可选:排除预发布版本 |
12 | | - if: ${{ !github.event.release.prerelease }} |
13 | | - |
| 10 | + permissions: |
| 11 | + contents: read # 必须的基础权限 |
| 12 | + |
14 | 13 | steps: |
15 | 14 | - name: Checkout code |
16 | 15 | uses: actions/checkout@v4 |
17 | 16 | with: |
18 | 17 | fetch-depth: 0 # JitPack需要完整的git历史记录 |
19 | 18 |
|
20 | 19 | - name: Verify Release Tag |
21 | | - id: verify-tag |
22 | 20 | 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" |
26 | 24 | exit 1 |
27 | 25 | fi |
28 | | - echo "Valid tag: ${{ github.event.release.tag_name }}" |
29 | 26 |
|
30 | | - - name: Trigger JitPack build |
| 27 | + - name: Trigger JitPack Build |
31 | 28 | env: |
32 | | - JITPACK_TOKEN: ${{ secrets.JITPACK_TOKEN }} |
| 29 | + JITPACK_TOKEN: ${{ secrets.JITPACK_TOKEN }} # GitHub PAT with repo scope |
33 | 30 | run: | |
34 | | - # 提取版本号(保留原始格式) |
| 31 | + # 保留原始Tag格式(不修改v前缀) |
35 | 32 | 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" |
48 | 55 | exit 1 |
49 | 56 | fi |
50 | 57 |
|
51 | | - - name: Verify JitPack Build |
| 58 | + - name: Monitor Build Status |
52 | 59 | run: | |
53 | 60 | VERSION=${{ github.event.release.tag_name }} |
54 | | - echo "Check build status at:" |
| 61 | + echo "Monitor build progress at:" |
55 | 62 | 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