Skip to content

Commit dd1c78f

Browse files
authored
Create gradle-publish-jitpack.yml
1 parent e1c6cfe commit dd1c78f

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Publish to JitPack on Release
2+
3+
on:
4+
release:
5+
types: [published] # 只在发布正式Release时触发
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
11+
# 可选:排除预发布版本
12+
if: ${{ !github.event.release.prerelease }}
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0 # JitPack需要完整的git历史记录
19+
20+
- name: Verify Release Tag
21+
id: verify-tag
22+
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"
26+
exit 1
27+
fi
28+
echo "Valid tag: ${{ github.event.release.tag_name }}"
29+
30+
- name: Trigger JitPack build
31+
env:
32+
JITPACK_TOKEN: ${{ secrets.JITPACK_TOKEN }}
33+
run: |
34+
# 提取版本号(保留原始格式)
35+
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"
48+
exit 1
49+
fi
50+
51+
- name: Verify JitPack Build
52+
run: |
53+
VERSION=${{ github.event.release.tag_name }}
54+
echo "Check build status at:"
55+
echo "https://jitpack.io/#${{ github.repository }}/$VERSION"
56+
echo "If build fails, you can retry manually at the above URL"

0 commit comments

Comments
 (0)