-
Notifications
You must be signed in to change notification settings - Fork 1
175 lines (155 loc) · 6.43 KB
/
android.yml
File metadata and controls
175 lines (155 loc) · 6.43 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
name: Android CI
on:
workflow_dispatch:
push:
tags:
- '*.*.*'
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
# 检出代码
- uses: actions/checkout@v2
- name: Unshallow
run: git fetch --prune --unshallow
# 设置JDK版本
- name: set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17
# 缓存依赖项
# https://docs.github.com/cn/actions/guides/building-and-testing-java-with-gradle#caching-dependencies
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# Assemble Release apk
- name: Build with Gradle
run: chmod +x gradlew &&./gradlew assembleRelease
# 清除部分Gradle缓存
- name: Cleanup Gradle Cache
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties
# 上传apk 到action(需要定制)
# https://github.com/marketplace/actions/upload-a-build-artifact
- name: Upload APK/AAR
uses: actions/upload-artifact@v2
with:
name: outputs
path: |
app/build/outputs/apk/release/*.apk
SwipeMenuLayout/build/outputs/aar/*-release.aar
SwipeMenuLayout-Helper/build/outputs/aar/*-release.aar
SwipeMenuLayout-EpoxyHelper/build/outputs/aar/*-release.aar
# 获取Core aar路径(需要定制)
- name: Get core aar path
id: core-path
run: |
path=$(find SwipeMenuLayout-Core/build/outputs/aar -name '*release.aar' -type f | head -1)
echo "::set-output name=path::$path"
# 获取Helper aar路径(需要定制)
- name: Get Helper aar path
id: helper-path
run: |
path=$(find SwipeMenuLayout-Helper/build/outputs/aar -name '*release.aar' -type f | head -1)
echo "::set-output name=path::$path"
# 获取EpoxyHelper aar路径(需要定制)
- name: Get EpoxyHelper aar path
id: epoxyhelper-path
run: |
path=$(find SwipeMenuLayout-EpoxyHelper/build/outputs/aar -name '*release.aar' -type f | head -1)
echo "::set-output name=path::$path"
# 获取demo apk路径
- name: Get apk path
id: apk-path
run: |
path=$(find app/build/outputs/apk/release -name '*.apk' -type f | head -1)
echo "::set-output name=path::$path"
# 获取apk版本号
# https://github.com/marketplace/actions/apk-info-action
- name: Get apk info
id: apk-info
uses: hkusu/apk-info-action@v1
with:
apk-path: ${{ steps.apk-path.outputs.path }}
# 获取指定时区的时间
# https://github.com/marketplace/actions/get-time-action
- name: Get Time
id: time
uses: JantHsueh/get-time-action@master
with:
timeZone: 8
# 获取git log 从 previousTag 到 lastTag
- name: Get git log
id: git-log
run: |
previousTag=$(git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`)
lastTag=$(git describe --abbrev=0 --tags)
echo "previousTag:$previousTag ~ lastTag:$lastTag"
log=$(git log $previousTag..$lastTag --pretty=format:'- %cd %an: %s\n' --date=format:'%Y-%m-%d %H:%M:%S')
echo "$log"
echo "::set-output name=log::"$log""
# 显示信息(需要定制)
- name: Show info
if: always()
run: |
echo '${{ steps.core-path.outputs.path }}'
echo '${{ steps.helper-path.outputs.path }}'
echo '${{ steps.epoxyhelper-path.outputs.path }}'
echo '${{ steps.apk-path.outputs.path }}'
echo '${{ steps.apk-info.outputs.result }}' # get apk info success or failure
echo '${{ steps.time.outputs.time }}'
echo '${{ steps.git-log.outputs.log }}'
echo '${{ steps.apk-info.outputs.application-name }}'
echo '${{ steps.apk-info.outputs.application-id }}'
echo '${{ steps.apk-info.outputs.version-code }}'
echo '${{ steps.apk-info.outputs.version-name }}'
echo '${{ steps.apk-info.outputs.min-sdk-version }}'
echo '${{ steps.apk-info.outputs.target-sdk-version }}'
echo '${{ steps.apk-info.outputs.compile-sdk-version }}'
echo '${{ steps.apk-info.outputs.uses-permissions }}'
echo '${{ steps.apk-info.outputs.debuggable }}'
echo '${{ steps.apk-info.outputs.allow-backup }}'
echo '${{ steps.apk-info.outputs.supports-rtl }}'
echo '${{ steps.apk-info.outputs.file-size }}'
echo '${{ steps.apk-info.outputs.readable-file-size }}'
# 向钉钉发送消息
# https://github.com/marketplace/actions/web-request-action
- name: dingtalk
uses: satak/webrequest-action@master
with:
url: ${{ secrets.DINGTALK_WEBHOOK }}
method: POST
payload: '{"msgtype": "text", "text": {"content": "版本更新: ${{ steps.apk-info.outputs.application-name }}-版本号: ${{ steps.apk-info.outputs.version-name }} \n 编译时间: ${{ steps.time.outputs.time }} \n 距上个正式版的更新记录: \n${{ steps.git-log.outputs.log }}"}}'
headers: '{"Content-Type": "application/json"}'
# 创建Changelog文件 triggered by git tag push
- name: Generate Changelog
if: startsWith(github.ref, 'refs/tags/')
run: |
echo -e '${{ steps.git-log.outputs.log }}' > Release.txt
# Cat Changelog triggered by git tag push
- name: Cat Changelog
if: startsWith(github.ref, 'refs/tags/')
run: |
cat Release.txt
# 创建Release triggered by git tag push(需要定制)
# https://github.com/marketplace/actions/gh-release
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
body_path: Release.txt
draft: true
files: |
${{ steps.apk-path.outputs.path }}
${{ steps.core-path.outputs.path }}
${{ steps.helper-path.outputs.path }}
${{ steps.epoxyhelper-path.outputs.path }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}