forked from o0HalfLife0o/TVBoxOSC
-
Notifications
You must be signed in to change notification settings - Fork 1
209 lines (191 loc) · 9.98 KB
/
Release.yml
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: release
on:
schedule:
- cron: 0 4 * * *
workflow_dispatch:
inputs:
rebuild:
description: '忽略构建记录以重新构建'
required: false
type: boolean
donotpublish:
description: '构建后不提交发布新版'
required: false
type: boolean
testOption:
description: 'arm64支持,不支持ijk解码'
required: false
type: boolean
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- userName: xisohi
repoName: XHTV
branchName: release
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
# - name: Check New Commit
# run: |
# upStream=https://github.com/${{ matrix.userName }}/${{ matrix.repoName }}
# echo "upStream=$upStream" >> $GITHUB_ENV
# commit=$(curl -sL $upStream/commits/${{ matrix.branchName }} |grep -o "/${{ matrix.userName }}/${{ matrix.repoName }}/commit/[a-z0-9]\+" |head -1 | cut -d\/ -f5)
# if ! grep -q "$commit" README.md || [ "${{ inputs.rebuild }}" == "true" ]; then
# echo "commit=$commit" >> $GITHUB_ENV
# echo "commitS=${commit:0:7}" >> $GITHUB_ENV
# fi
- name: Check New Commit
run: |
upStream="https://github.com/${{ matrix.userName }}/${{ matrix.repoName }}"
echo "upStream=$upStream" >> $GITHUB_ENV
commit=$(curl -sL "https://api.github.com/repos/${{ matrix.userName }}/${{ matrix.repoName }}/commits/${{ matrix.branchName }}" | jq -r '.sha')
if [ $? -ne 0 ]; then
echo "Failed to get commit from API"
exit 1
fi
if [ -z "$commit" ] || ! grep -q "$commit" README.md; then
echo "commit=$commit" >> $GITHUB_ENV
echo "commitS=${commit:0:7}" >> $GITHUB_ENV
fi
- name: Checkout Source Code
if: ${{ env.commit }}
run: |
git clone ${{ env.upStream }} TVBoxOSC
cd TVBoxOSC
git checkout ${{ env.commit }}
echo "tag=$(git log --date=format:'%y%m%d%H%M' --pretty=format:%cd ${{ env.commitS }} -1)" >> $GITHUB_ENV
- name: Extra Modify
if: ${{ env.commit }}
working-directory: TVBoxOSC
run: |
if [[ "${{ matrix.userName }}" == "xisohi" ]]; then
sed -i 's/TeamNewPipe/teamnewpipe/g' app/build.gradle
fi
- name: Compress Source Code
if: ${{ env.commit }}
working-directory: TVBoxOSC
run: |
#zip -q -x ".git/*" -x ".github/*" -r source-${{ env.commitS }}.zip .
tar -cJf source-${{ env.commitS }}.tar.xz --exclude=.git --exclude=.github *
- name: Option For Test
if: ${{ inputs.testOption }}
working-directory: TVBoxOSC
run: |
#添加arm64支持,不支持ijk解码
sed -i "/armeabi-v7a[\'\"]$/s#\$#, 'arm64-v8a'#" app/build.gradle
sed -i "/armeabi-v7a[\'\"]$/s#\$#, 'arm64-v8a'#" player/build.gradle
- name: Release Apk Sign
if: ${{ env.commit }}
working-directory: TVBoxOSC
run: |
signingConfigs='ICAgIHNpZ25pbmdDb25maWdzIHtcCiAgICAgICAgaWYgKHByb2plY3QuaGFzUHJvcGVydHkoIlJFTEVBU0VfU1RPUkVfRklMRSIpKSB7XAogICAgICAgICAgICBteUNvbmZpZyB7XAogICAgICAgICAgICAgICAgc3RvcmVGaWxlIGZpbGUoUkVMRUFTRV9TVE9SRV9GSUxFKVwKICAgICAgICAgICAgICAgIHN0b3JlUGFzc3dvcmQgUkVMRUFTRV9TVE9SRV9QQVNTV09SRFwKICAgICAgICAgICAgICAgIGtleUFsaWFzIFJFTEVBU0VfS0VZX0FMSUFTXAogICAgICAgICAgICAgICAga2V5UGFzc3dvcmQgUkVMRUFTRV9LRVlfUEFTU1dPUkRcCiAgICAgICAgICAgICAgICB2MVNpZ25pbmdFbmFibGVkIHRydWVcCiAgICAgICAgICAgICAgICB2MlNpZ25pbmdFbmFibGVkIHRydWVcCiAgICAgICAgICAgICAgICBlbmFibGVWM1NpZ25pbmcgPSB0cnVlXAogICAgICAgICAgICAgICAgZW5hYmxlVjRTaWduaW5nID0gdHJ1ZVwKICAgICAgICAgICAgfVwKICAgICAgICB9XAogICAgfVwKXA=='
signingConfig='ICAgICAgICAgICAgaWYgKHByb2plY3QuaGFzUHJvcGVydHkoIlJFTEVBU0VfU1RPUkVfRklMRSIpKSB7XAogICAgICAgICAgICAgICAgc2lnbmluZ0NvbmZpZyBzaWduaW5nQ29uZmlncy5teUNvbmZpZ1wKICAgICAgICAgICAgfVwK'
signingConfigs="$(echo "$signingConfigs" |base64 -d )"
signingConfig="$(echo "$signingConfig" |base64 -d )"
sed -i -e "/defaultConfig {/i\\$signingConfigs " -e "/debug {/a\\$signingConfig " -e "/release {/a\\$signingConfig " app/build.gradle
cp -f ${{ github.workspace }}/.github/workflows/TVBoxOSC.jks app/TVBoxOSC.jks
sed -i '$a\RELEASE_STORE_FILE=./TVBoxOSC.jks' ./gradle.properties
sed -i '$a\RELEASE_KEY_ALIAS=TVBoxOSC' ./gradle.properties
sed -i '$a\RELEASE_STORE_PASSWORD=xh8621989' ./gradle.properties
sed -i '$a\RELEASE_KEY_PASSWORD=xh8621989' ./gradle.properties
- name: Setup Java
if: ${{ env.commit && (matrix.userName == 'xisohi') }}
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Setup Gradle
if: ${{ env.commit }}
uses: gradle/gradle-build-action@v2
- name: Build With Gradle
if: ${{ env.commit }}
working-directory: TVBoxOSC
run: |
chmod +x gradlew
./gradlew assemblerelease --build-cache --parallel --daemon --warning-mode all
- name: Prepare App
if: ${{ env.commit }}
working-directory: TVBoxOSC
run: |
rm -rf apk/
mkdir -p apk/
find ~ -type d -iname "release" -print0 | while IFS= read -r -d '' dir; do
find "$dir" -type f -name "*.apk" -exec sh -c 'cp "$1" "apk/${1##*/}"' sh {} \;
done
- name: Release Note
if: ${{ env.commit }}
working-directory: TVBoxOSC
run: |
lastCommit=$(grep "${{ matrix.userName }}\/${{ matrix.repoName }}\/tree\/${{ matrix.branchName }}" ${{ github.workspace }}/README.md |grep -o '[a-z0-9]\{40\}')
export LESSCHARSET=utf-8
echo -e "Credit: [${{ matrix.userName }}/${{ matrix.repoName }}/${{ matrix.branchName }}](${{ env.upStream }})\nCommit: ${{ env.commit }}\nChangelog:" > apk/${{ matrix.repoName }}-Release.log
if [ "${{ env.commit }}" == "${lastCommit}" ]; then
git log --pretty=format:%B ${{ env.commitS }} -1 |sed -e "s# \{2,\}#\n#g" -e "/^Merge \(pull\|branch\|remote\)/d" -e '/^$/d' |cat -n |sort -k2,2 -k1,1n |uniq -f1 |sort -k1,1n |cut -f2- >> apk/${{ matrix.repoName }}-Release.log
else
git log --pretty=format:%B ${{ env.commitS }}...${lastCommit:0:7} |sed -e "s# \{2,\}#\n#g" -e "/^Merge \(pull\|branch\|remote\)/d" -e '/^$/d' |cat -n |sort -k2,2 -k1,1n |uniq -f1 |sort -k1,1n |cut -f2- >> apk/${{ matrix.repoName }}-Release.log
fi
- name: Build Upgrade log
if: ${{ env.commit }}
working-directory: TVBoxOSC
run: |
lastCommit=$(grep "${{ matrix.userName }}\/${{ matrix.repoName }}\/tree\/${{ matrix.branchName }}" ${{ github.workspace }}/README.md |grep -o '[a-z0-9]\{40\}')
export LESSCHARSET=utf-8
echo -e "Credit: [${{ matrix.branchName }}](${{ env.upStream }})\nCommit: ${{ env.commit }}\nChangelog:" > apk/${{ matrix.branchName }}.log
if [ "${{ env.commit }}" == "${lastCommit}" ]; then
git log --pretty=format:%B ${{ env.commitS }} -1 |sed -e "s# \{2,\}#\n#g" -e "/^Merge \(pull\|branch\|remote\)/d" -e '/^$/d' |cat -n |sort -k2,2 -k1,1n |uniq -f1 |sort -k1,1n |cut -f2- > apk/${{ matrix.branchName }}.log
else
git log --pretty=format:%B ${{ env.commitS }}...${lastCommit:0:7} |sed -e "s# \{2,\}#\n#g" -e "/^Merge \(pull\|branch\|remote\)/d" -e '/^$/d' |cat -n |sort -k2,2 -k1,1n |uniq -f1 |sort -k1,1n |cut -f2- > apk/${{ matrix.branchName }}.log
fi
- name: Build Upgrade content
if: ${{ env.commit }}
working-directory: TVBoxOSC
run: |
echo "versionCode=$(grep -oP 'versionCode \K\d+' app/build.gradle)" >> $GITHUB_ENV
echo "versionName=$(grep -oP 'versionName \"\K[^\"]+' app/build.gradle)" >> $GITHUB_ENV
echo "desc=$(awk 'BEGIN{ORS="\\\\n"}{print NR ": " $0}' apk/${{ matrix.branchName }}.log)" >> $GITHUB_ENV
- name: Upload App To Artifact
uses: actions/upload-artifact@v3
if: ${{ env.commit }}
with:
name: ${{ matrix.userName }}-${{ matrix.repoName }}
path: |
TVBoxOSC/apk/*
- name: Whether Or Not to Publish
if: ${{ inputs.donotpublish && env.commit }}
run: |
echo "commit=" >> $GITHUB_ENV
- name: Release and Upload Assets
uses: ncipollo/release-action@main
if: ${{ env.commit }}
with:
name: ${{ matrix.repoName }}
tag: ${{ matrix.branchName }}
bodyFile: TVBoxOSC/apk/${{ matrix.repoName }}-Release.log
allowUpdates: true
removeArtifacts: true
artifacts: |
TVBoxOSC/apk/*.apk
TVBoxOSC/source-${{ env.commitS }}.*
- name: Push to master
if: ${{ env.commit }}
run: |
rm -rf TVBoxOSC
sed -i '/url =/d' ./.git/config
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git remote set-url --add origin "https://${{ github.actor }}:${{ secrets.GIT_TOKEN }}@github.com/${{ github.repository }}"
git pull --rebase
sed -i "/${{ matrix.userName }}\/${{ matrix.repoName }}\/tree\/${{ matrix.branchName }}/s#Updated: [a-zA-Z0-9]*#Updated: ${{ env.commit }}#" README.md
sed -i 's/"code": "[a-zA-Z0-9]*"/"code": "${{ env.versionCode }}"/' update/${{ matrix.branchName }}.json
sed -i 's/"name": "[^"]*"/"name": "${{ env.versionName }}"/' update/${{ matrix.branchName }}.json
sed -i 's|"desc": ".*"|"desc": "${{ env.desc }}"|g' update/${{ matrix.branchName }}.json
sed -i "s/update at .*/update at $(date '+%Y-%m-%d %H:%M:%S')/" README.md
git add --all
git commit -m "${{ env.commit }}"
git push -u -f origin master