Skip to content

Commit 9732dd3

Browse files
authored
Create gradle-publish-jitpack.yml
1 parent bcbba65 commit 9732dd3

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
# 添加执行权限
21+
- name: Make gradlew executable
22+
run: chmod +x gradlew
23+
24+
- name: Set up JDK
25+
uses: actions/setup-java@v3
26+
with:
27+
distribution: 'temurin'
28+
java-version: '17'
29+
30+
- name: Set up Android SDK
31+
uses: android-actions/setup-android@v2
32+
33+
- name: Verify Release Tag
34+
id: verify-tag
35+
run: |
36+
# 检查tag名称是否符合语义化版本规范
37+
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
38+
echo "::error::Tag name ${{ github.event.release.tag_name }} does not follow semantic versioning"
39+
exit 1
40+
fi
41+
echo "Valid tag: ${{ github.event.release.tag_name }}"
42+
43+
- name: Build with Gradle
44+
run: ./gradlew build
45+
46+
- name: Trigger JitPack build
47+
env:
48+
JITPACK_TOKEN: ${{ secrets.JITPACK_TOKEN }}
49+
run: |
50+
# 提取版本号(去掉可能的v前缀)
51+
VERSION=${GITHUB_REF#refs/tags/}
52+
VERSION=${VERSION#v} # 去掉v前缀
53+
54+
echo "Triggering JitPack build for version $VERSION"
55+
56+
# 使用JitPack API触发构建
57+
curl -X POST "https://jitpack.io/api/build" \
58+
-H "Content-Type: application/json" \
59+
-d "{
60+
\"groupId\": \"com.github.${{ github.repository_owner }}\",
61+
\"artifactId\": \"${{ github.event.repository.name }}\",
62+
\"version\": \"$VERSION\"
63+
}" \
64+
-u "${{ github.repository_owner }}:$JITPACK_TOKEN"
65+
66+
- name: Verify JitPack Build
67+
run: |
68+
echo "Check build status at:"
69+
echo "https://jitpack.io/#${{ github.repository }}/$VERSION"

0 commit comments

Comments
 (0)