Skip to content

XHYS

XHYS #193

Workflow file for this run

name: XHYS
on:
schedule:
- cron: 0 0 * * *
workflow_dispatch:
inputs:
rebuild:
description: '忽略构建记录以重新构建'
required: false
type: boolean
donotpublish:
description: '构建后不提交发布新版'
required: false
type: boolean
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- userName: xisohi
repoName: XHYS
branchName: main
java_ver: 17
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 ${{ 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 '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 sourceCode-${{ env.commitS }}.zip .
tar -cJf sourceCode-${{ env.commitS }}.tar.xz --exclude=.git --exclude=.github *
- 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
- uses: actions/setup-java@v4
if: ${{ matrix.java_ver }}
with:
distribution: temurin
java-version: ${{ matrix.java_ver }}
- uses: gradle/actions/setup-gradle@v4
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
# 获取文件的基本名称
base=$(basename "$file")
# 如果文件是 TVBox_ 开头
if [[ "$base" == TVBox_* ]]; then
new_base=$(echo "$base" | sed "s/release/${{ matrix.repoName }}/")
else
new_base="${{ matrix.repoName }}_Release.apk"
fi
# 移动并重命名文件
mv "$file" "apk/$new_base"
done
mv sourceCode-${{ env.commitS }}.* apk/
- 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 }}/${{ matrix.repoName }}](${{ env.upStream }})\nCommit: ${{ env.commit }}\nChangelog:\n\`\`\`" > 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
echo -e '\n```' >> apk/${{ matrix.repoName }}-Release.log
- name: Build Upgrade log
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.repoName }}.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 }}.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 }}.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 "UploadTime=$(git log --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:%cd ${{ env.commitS }} -1)" >> $GITHUB_ENV
echo "ModifyContent=$(awk 'BEGIN{ORS="\\\\n"}{print NR ": " $0}' apk/${{ matrix.repoName }}.log)" >> $GITHUB_ENV
echo "ApkMd5=$(md5sum apk/TVBox_${{ matrix.repoName }}-armeabi-generic.apk | awk '{ print $1 }')" >> $GITHUB_ENV
echo "ApkSize=$(ls -l --block-size=K apk/TVBox_${{ matrix.repoName }}-armeabi-generic.apk | awk '{ print $5 }'|grep -o '[0-9]\+')" >> $GITHUB_ENV
- name: Upload App To Artifact
uses: actions/upload-artifact@v4
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: ${{ matrix.repoName }}
tag: ${{ matrix.repoName }}
bodyFile: TVBoxOSC/apk/${{ matrix.repoName }}-Release.log
allowUpdates: true
removeArtifacts: true
artifacts: |
TVBoxOSC/apk/*.apk
TVBoxOSC/apk/sourceCode-${{ env.commitS }}.*
- name: Push to master
if: ${{ env.commit }}
run: |
rm -rf TVBoxOSC
git reset --hard
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
sed -i 's/"VersionCode": [a-zA-Z0-9]*/"VersionCode": ${{ env.VersionCode }}/' update/${{ matrix.repoName }}.json
sed -i 's/"VersionName": "[^"]*"/"VersionName": "${{ env.VersionCode }}"/' update/${{ matrix.repoName }}.json
sed -i 's|"UploadTime": ".*"|"UploadTime": "${{ env.UploadTime }}"|g' update/${{ matrix.repoName }}.json
sed -i 's|"ModifyContent": ".*"|"ModifyContent": "${{ env.ModifyContent }}"|g' update/${{ matrix.repoName }}.json
sed -i 's|"DownloadUrl": ".*"|"DownloadUrl": "https://mirror.ghproxy.com/https://github.com/xisohi/TVBoxOSC/releases/download/${{ matrix.repoName }}/TVBox_${{ matrix.repoName }}-armeabi-generic.apk"|g' update/${{ matrix.repoName }}.json
sed -i 's/"ApkSize": [a-zA-Z0-9]*/"ApkSize": ${{ env.ApkSize }}/' update/${{ matrix.repoName }}.json
sed -i 's/"ApkMd5": "[a-zA-Z0-9]*"/"ApkMd5": "${{ env.ApkMd5 }}"/' update/${{ matrix.repoName }}.json
git add --all
git commit -m "${{ env.commit }}"
git push -u -f origin master
clean:
needs: build
runs-on: ubuntu-latest
steps:
- name: Delete older workflow runs and artifacts
uses: Mattraks/delete-workflow-runs@main
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: 14
keep_minimum_runs: 10