Test #20057
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: Test | |
on: | |
schedule: | |
- cron: 59 */8 * * * | |
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: q215613905 | |
repoName: TVBoxOS | |
branchName: main | |
- userName: takagen99 | |
repoName: Box | |
branchName: main | |
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: 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: | | |
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/main/res/layout/dialog_about.xml | |
echo 'crosswalk源,防挂' | |
if grep -q 'crosswalk' build.gradle; then | |
sed -i "/crosswalk/a\ maven { url 'https://o0halflife0o.github.io/crosswalk/releases/crosswalk/android/maven2' }" build.gradle | |
else | |
sed -i "/jitpack.io/a\ maven { url 'https://o0halflife0o.github.io/crosswalk/releases/crosswalk/android/maven2' }" 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=TVBoxOSC' ./gradle.properties | |
sed -i '$a\RELEASE_KEY_PASSWORD=TVBoxOSC' ./gradle.properties | |
- name: Check JAVA Version | |
if: ${{ env.commit }} | |
working-directory: TVBoxOSC | |
run: | | |
setup_java_ver=$(grep -o 'JavaVersion.VERSION_[0-9_]\+' app/build.gradle |head -1 |sed 's/.*_//') | |
if [ $setup_java_ver -gt 11 ]; then | |
echo "setup_java_ver=$setup_java_ver" >> $GITHUB_ENV | |
fi | |
- uses: actions/setup-java@v4 | |
if: ${{ env.setup_java_ver }} | |
with: | |
distribution: temurin | |
java-version: ${{ env.setup_java_ver }} | |
- uses: gradle/gradle-build-action@v2 | |
if: ${{ env.commit }} | |
- 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/ | |
for file in `find ~ -name "*release*.apk" -print`; do | |
mv "$file" apk/TVBox_${{ matrix.userName }}_${{ env.tag }}.apk | |
done | |
- name: Release Note | |
if: ${{ env.commit }} | |
working-directory: TVBoxOSC | |
run: | | |
lastCommit=$(grep "${{ matrix.userName }}\/${{ matrix.repoName }}" ${{ github.workspace }}/README.md |grep -o '[a-z0-9]\{40\}') | |
export LESSCHARSET=utf-8 | |
echo -e "Credit: [${{ matrix.userName }}](${{ 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: 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@v1 | |
if: ${{ env.commit }} | |
with: | |
name: ${{ env.tag }} | |
tag: ${{ env.tag }} | |
bodyFile: TVBoxOSC/apk/${{ matrix.userName }}-Release.log | |
allowUpdates: true | |
removeArtifacts: true | |
artifacts: | | |
TVBoxOSC/apk/*.apk | |
TVBoxOSC/source-${{ env.commitS }}.* | |
- name: Post To Telegram | |
if: ${{ env.commit }} | |
working-directory: TVBoxOSC | |
run: | | |
if [ -n "${{ secrets.CHANNEL_ID }}" ] && [ -n "${{ secrets.BOT_TOKEN }}" ]; then | |
OUTPUT="${{ github.workspace }}/TVBoxOSC" | |
export appRelease=$(find $OUTPUT/apk/ -name "*${{ matrix.userName }}*.apk") | |
export sourceCode=$(find $OUTPUT -name "source-${{ env.commitS }}.*") | |
ESCAPED="$(sed -e '1s/\[\(.*\)\].*/#\1/' -e 's#\([&"\/]\)#\\\1#g' apk/${{ matrix.userName }}-Release.log)" | |
count=$(echo "$ESCAPED" |wc -m |cut -d ' ' -f1) | |
if [ ${count} -eq 1 ] || [ ${count} -gt 1024 ]; then | |
ESCAPED="$(echo -e "Credit: #${{ matrix.userName }}\nCommit: ${{ env.commit }}\nChangelog:\n${{ env.upStream }}/commits/${{ matrix.branchName }}")" | |
fi | |
ESCAPED=`python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "$ESCAPED"` | |
#检查源码尺寸,太大则不上传 | |
file_size=$(du -s ${sourceCode} | awk '{print $1}') | |
#文件最大值,1024代表1M | |
file_limit_size=20480 | |
if [[ ${file_size} -lt ${file_limit_size} ]];then | |
curl -v "https://api.telegram.org/bot${{ secrets.BOT_TOKEN }}/sendMediaGroup?chat_id=${{ secrets.CHANNEL_ID }}&media=%5B%7B%22type%22%3A%22document%22%2C%20%22media%22%3A%22attach%3A%2F%2FappRelease%22%7D%2C%7B%22type%22%3A%22document%22%2C%20%22media%22%3A%22attach%3A%2F%2FsourceCode%22%2C%20%22caption%22%3A%22${ESCAPED}%22%7D%5D" -F appRelease="@$appRelease" -F sourceCode="@$sourceCode" | |
else | |
curl -v "https://api.telegram.org/bot${{ secrets.BOT_TOKEN }}/sendMediaGroup?chat_id=${{ secrets.CHANNEL_ID }}&media=%5B%7B%22type%22%3A%22document%22%2C%20%22media%22%3A%22attach%3A%2F%2FappRelease%22%2C%20%22caption%22%3A%22${ESCAPED}%22%7D%5D" -F appRelease="@$appRelease" | |
fi | |
fi | |
- 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 }}/s#Updated: [a-zA-Z0-9]*#Updated: ${{ env.commit }}#" README.md | |
git add --all | |
git commit -m "${{ env.commit }}" | |
git push -u -f origin master |