Repository navigation
138 lines (114 loc) · 4.85 KB
/
Copy pathandroid.yml
File metadata and controls
138 lines (114 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Build AARs and Upload to Release
on:
release:
types: [published]
env:
LIB1_NAME: tcplib
LIB2_NAME: udplib
jobs:
build-and-upload:
runs-on: ubuntu-latest
permissions:
contents: write # 必须添加这个权限
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
# 先校验 tag 格式,tag 非法时直接失败,避免后续构建、上传白跑
- name: Verify Release Tag
run: |
# 严格校验Tag格式(支持v前缀和纯数字版本)
if [[ ! "${{ github.event.release.tag_name }}" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Invalid tag format. Must be like 1.0.0 or v1.0.0"
exit 1
fi
# 添加执行权限
- name: Make gradlew executable
run: chmod +x gradlew
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Set up Android SDK
uses: android-actions/setup-android@v3
with:
# 该 action 的 packages 默认值为 'tools platform-tools',
# 但 tools 包已被 Google 从 SDK 仓库移除,sdkmanager 会以
# "Warning: Failed to find package 'tools'" 退出码 1 失败,故置空跳过额外包安装
packages: ''
# 工程使用 compileSdkVersion 32 / buildToolsVersion 30.0.3,
# 而 runner 镜像仅预装 API 34~37 与 build-tools 34+,需要显式安装
- name: Install required Android SDK packages
run: |
# 自动接受尚未确认的许可
yes | sdkmanager --licenses > /dev/null || true
sdkmanager "platforms;android-32" "build-tools;30.0.3"
- name: Build all AARs
run: |
./gradlew clean
./gradlew :${{ env.LIB1_NAME }}:assembleRelease
./gradlew :${{ env.LIB2_NAME }}:assembleRelease
# 使用官方 gh CLI 上传,替换已归档、且运行在 node12 的 actions/upload-release-asset@v1
- name: Upload AARs to Release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release upload "${{ github.event.release.tag_name }}" \
"${{ env.LIB1_NAME }}/build/outputs/aar/${{ env.LIB1_NAME }}-release.aar" \
"${{ env.LIB2_NAME }}/build/outputs/aar/${{ env.LIB2_NAME }}-release.aar" \
--repo "${{ github.repository }}" \
--clobber
- name: Trigger JitPack Build
env:
JITPACK_TOKEN: ${{ secrets.JITPACK_TOKEN }} # GitHub PAT with repo scope
run: |
# Keep original tag format (preserve 'v' prefix)
VERSION=${{ github.event.release.tag_name }}
OWNER=${{ github.repository_owner }}
REPO=${{ github.event.repository.name }}
echo "Triggering build for: com.github.$OWNER/$REPO@$VERSION"
# JitPack API endpoint
API_URL="https://jitpack.io/api/builds/com.github.$OWNER/$REPO/$VERSION"
# Make initial build request
echo "Making initial build request"
RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \
-H "Authorization: Bearer $JITPACK_TOKEN" \
"$API_URL")
# Extract HTTP status and response body
HTTP_STATUS=$(echo "$RESPONSE" | grep HTTP_STATUS: | cut -d':' -f2)
BODY=$(echo "$RESPONSE" | sed '/HTTP_STATUS:/d')
echo "Initial API Response: $BODY"
echo "HTTP Status: $HTTP_STATUS"
if [[ "$HTTP_STATUS" != "200" ]]; then
echo "❌ Failed to trigger build (HTTP $HTTP_STATUS)"
exit 1
fi
# Check build status periodically
while true; do
echo "Checking build status..."
STATUS_RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \
-H "Authorization: Bearer $JITPACK_TOKEN" \
"$API_URL")
STATUS_HTTP=$(echo "$STATUS_RESPONSE" | grep HTTP_STATUS: | cut -d':' -f2)
STATUS_BODY=$(echo "$STATUS_RESPONSE" | sed '/HTTP_STATUS:/d')
# Extract status (case insensitive)
STATUS=$(echo "$STATUS_BODY" | grep -i -o '"status":"[^"]*"' | cut -d'"' -f4 | tr '[:upper:]' '[:lower:]')
if [[ "$STATUS" == "ok" ]]; then
echo "✅ Build succeeded!"
exit 0
elif [[ "$STATUS" == "error" ]]; then
echo "❌ Build failed!"
exit 1
else
echo "🔄 Build in progress (status: ${STATUS:-unknown}), waiting 30 seconds..."
sleep 30
fi
done
- name: Monitor Build Status
run: |
VERSION=${{ github.event.release.tag_name }}
echo "Monitor build progress at:"
echo "https://jitpack.io/#${{ github.repository }}/$VERSION"
echo "Note: Building may take 3-5 minutes"