fongmi #214
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: fongmi | |
# 代码来自xinyi1984 | |
on: | |
schedule: | |
- cron: 0 2 * * * | |
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: fongmi | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
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 https://github.com/androidx/media.git TVBoxOSC | |
cd TVBoxOSC | |
#git checkout -b main origin/main | |
cd /home/runner/work/TVBoxOSC/TVBoxOSC | |
git clone ${{ env.upStream }} TVBoxOSC/media | |
cd TVBoxOSC/media | |
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/midia | |
#run: | | |
#echo '修改VersionName' | |
#sed -i "/versionName/s#[0-9a-zA-Z_\.\'\"-]\+\$#\'${{ env.tag }}\'#" app/build.gradle | |
#sed -i "/android:text=/s#=\"#=\"${{ env.tag }}\\\\n\\\\n#" app/src/leanback/res/layout/activity_setting.xml | |
#sed -i "/android:text=/s#=\"#=\"${{ env.tag }}\\\\n\\\\n#" app/src/mobile/res/layout/fragment_setting.xml | |
#echo 'crosswalk源,防挂' | |
#if grep -q 'crosswalk' build.gradle; then | |
#sed -i "/crosswalk/a\ maven { url 'https://xisohi.github.io/crosswalk/releases/crosswalk/android/maven2' }" build.gradle | |
#else | |
#sed -i "/jitpack.io/a\ maven { url 'https://xisohi.github.io/crosswalk/releases/crosswalk/android/maven2' }" build.gradle | |
#fi | |
- name: Compress Source Code | |
if: ${{ env.commit }} | |
working-directory: TVBoxOSC/media | |
run: | | |
#删除xisohi-XHTV的release目录 | |
rm -rf release | |
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/media | |
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/media | |
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 | |
# Set up JDK 17 解决androidx/room/RoomProcessor has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0 61需要java-version: 17 | |
- name: set up JDK 17 | |
if: ${{ env.commit }} | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
- name: Setup Gradle | |
if: ${{ env.commit }} | |
uses: gradle/actions/setup-gradle@v4 | |
- name: Build With Gradle | |
if: ${{ env.commit }} | |
working-directory: TVBoxOSC/media | |
run: | | |
chmod +x /home/runner/work/TVBoxOSC/TVBoxOSC/TVBoxOSC/media/gradlew | |
#cp -r gradle.properties local.properties | |
rm -rf app/src/armeabi_v7a/assets | |
rm -rf app/src/arm64_v8a/assets | |
./gradlew assemblerelease --build-cache --parallel --daemon --warning-mode all | |
#./gradlew assembleleanbackJavaArm64_v8arelease --build-cache --parallel --daemon --warning-mode all | |
#./gradlew assembleleanbackJavaArmeabi_v7arelease --build-cache --parallel --daemon --warning-mode all | |
#./gradlew assemblemobileJavaArm64_v8arelease --build-cache --parallel --daemon --warning-mode all | |
- name: Prepare App | |
if: ${{ env.commit }} | |
working-directory: TVBoxOSC/media | |
run: | | |
rm -rf apk/ | |
mkdir -p apk/ | |
for file in `find ~ \( -name "*python*.apk" -o -name "*java*.apk" \) -not -name "*x86*" -print`; do | |
#for file in `find ~ -name "*java*.apk" -not -name "*x86*" -print`; do | |
# 获取文件的基本名称 | |
base=$(basename "$file") | |
# 在基本名称添加分支${{ matrix.branchName }}_ | |
new_base="${{ matrix.branchName }}_$base" | |
# 移动并重命名文件 | |
mv "$file" "apk/$new_base" | |
done | |
mv source-${{ env.commitS }}.* apk/ | |
- name: Release Note | |
if: ${{ env.commit }} | |
working-directory: TVBoxOSC/media | |
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.userName }}-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.userName }}-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.userName }}-Release.log | |
fi | |
- name: Build Upgrade log | |
if: ${{ env.commit }} | |
working-directory: TVBoxOSC/media | |
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.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/media | |
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: Release and Upload Assets | |
uses: ncipollo/release-action@v1 | |
if: ${{ env.commit }} | |
with: | |
name: ${{ matrix.repoName }} | |
tag: ${{ matrix.branchName }} | |
bodyFile: TVBoxOSC/media/apk/${{ matrix.userName }}-Release.log | |
allowUpdates: true | |
removeArtifacts: true | |
artifacts: | | |
TVBoxOSC/media/apk/*.apk | |
TVBoxOSC/media/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.GITHUB_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 | |
git add --all | |
git commit -m "${{ env.commit }}" | |
git push -u -f origin master | |
#continue-on-error: true 是因为 git commit 会失败也是预期的,这个步骤可以忽略失败。加上这个命令就可以在这个步骤失败的时候,不会影响其他步骤 | |
continue-on-error: true |