2023-02-10 07:19:54 +00:00
|
|
|
|
name: Weekly Build
|
|
|
|
|
|
|
|
|
|
# 触发器
|
|
|
|
|
on:
|
|
|
|
|
schedule:
|
|
|
|
|
- cron: '0 15 * * 0' #每周天在国际标准时间15点(北京时间+8,即 23:00)
|
|
|
|
|
workflow_dispatch:
|
|
|
|
|
inputs:
|
|
|
|
|
root_sol:
|
|
|
|
|
description: "Weekly Build Title"
|
|
|
|
|
required: true
|
|
|
|
|
default: "SmsForwarder"
|
|
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
|
build:
|
|
|
|
|
runs-on: ubuntu-latest
|
2024-01-16 09:54:23 +00:00
|
|
|
|
env:
|
|
|
|
|
output: "${{ github.workspace }}/build/app/outputs/apk/release"
|
2023-02-10 07:19:54 +00:00
|
|
|
|
steps:
|
|
|
|
|
# 检出代码
|
2024-01-17 01:08:54 +00:00
|
|
|
|
- uses: actions/checkout@v4
|
2023-02-10 07:19:54 +00:00
|
|
|
|
# 删除旧的工作流
|
|
|
|
|
- name: Delete Weekly Build
|
|
|
|
|
uses: Mattraks/delete-workflow-runs@v2
|
|
|
|
|
with:
|
2024-03-05 15:30:25 +00:00
|
|
|
|
token: ${{ secrets.TOKEN }}
|
2023-02-10 07:19:54 +00:00
|
|
|
|
repository: ${{ github.repository }}
|
|
|
|
|
retain_days: 0 # 全部删除只留正在跑的一条
|
|
|
|
|
keep_minimum_runs: 0 # 全部删除只留正在跑的一条
|
|
|
|
|
delete_workflow_pattern: 'Weekly Build'
|
|
|
|
|
# 设置jdk环境为11
|
|
|
|
|
- name: set up JDK 11
|
2024-01-17 15:42:00 +00:00
|
|
|
|
uses: actions/setup-java@v4
|
2023-02-10 07:19:54 +00:00
|
|
|
|
with:
|
2024-01-17 01:52:46 +00:00
|
|
|
|
distribution: 'zulu'
|
|
|
|
|
java-version: '11'
|
|
|
|
|
java-package: jdk
|
2023-02-10 07:19:54 +00:00
|
|
|
|
# 获取打包秘钥
|
|
|
|
|
- name: Checkout Android Keystore
|
2024-01-17 01:08:54 +00:00
|
|
|
|
uses: actions/checkout@v4
|
2023-02-10 07:19:54 +00:00
|
|
|
|
with:
|
|
|
|
|
repository: pppscn/keystore
|
|
|
|
|
token: ${{ secrets.TOKEN }} # 连接仓库的token,需要单独配置
|
|
|
|
|
path: keystore # 仓库的根目录名
|
|
|
|
|
# 打包release
|
|
|
|
|
- name: Build with Gradle
|
|
|
|
|
run: bash ./gradlew assembleRelease
|
2024-03-05 15:30:25 +00:00
|
|
|
|
# 自动发布预览计划
|
|
|
|
|
- name: Parse output-metadata.json and upload APKs to XUpdate
|
2024-01-16 09:54:23 +00:00
|
|
|
|
run: |
|
2024-03-05 15:30:25 +00:00
|
|
|
|
metadata_file="${{ env.output }}/output-metadata.json"
|
|
|
|
|
applicationId=$(jq -r '.applicationId' "$metadata_file")
|
|
|
|
|
buildDate=$(jq -r '.buildDate' "$metadata_file")
|
|
|
|
|
buildTime=$(jq -r '.buildTime' "$metadata_file")
|
|
|
|
|
gitCommitId=$(jq -r '.gitCommitId' "$metadata_file")
|
|
|
|
|
|
|
|
|
|
# 遍历 elements,并从 outputFile 中提取 versionName 和 versionCode
|
|
|
|
|
jq -r '.elements | sort_by(.outputFile) | .[].outputFile' "$metadata_file" |
|
|
|
|
|
while IFS= read -r apk; do
|
|
|
|
|
echo "APK: $apk"
|
|
|
|
|
# 使用正则表达式从文件名中提取 versionName、versionCode 和 ABI
|
|
|
|
|
if [[ $apk =~ SmsF_([^_]+)_([^_]+)_(.+)_release.apk ]]; then
|
|
|
|
|
versionName="${BASH_REMATCH[1]}"
|
|
|
|
|
versionCode="${BASH_REMATCH[2]}"
|
|
|
|
|
abi="${BASH_REMATCH[3]}"
|
|
|
|
|
echo "ver_name=$versionName" >> $GITHUB_ENV
|
|
|
|
|
echo "ver_code=${versionCode: -3}" >> $GITHUB_ENV
|
|
|
|
|
|
|
|
|
|
response=$(curl --retry 3 -X POST -H "Cache-Control: no-cache" \
|
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
|
-H "Cookie: xupdate_token=${{ secrets.XUPDATE_TOKEN }}" \
|
|
|
|
|
-H "X-Token: ${{ secrets.X_TOKEN }}" \
|
|
|
|
|
-d "{\"appKey\":\"${applicationId}\",\"versionName\":\"${versionName}\",\"versionCode\":\"${versionCode}\",\"modifyContent\":\"\",\"updateStatus\":1,\"gitCommitId\":\"${gitCommitId}\",\"buildTime\":\"${buildTime}\",\"uploadTime\":\"${buildTime}\"}" \
|
|
|
|
|
${{ secrets.URL_ADD_VERSION }})
|
2024-03-11 03:00:33 +00:00
|
|
|
|
|
2024-03-05 15:30:25 +00:00
|
|
|
|
version_id=$(echo $response | grep -oP '"versionId":\s*\K\d+') # 提取versionId
|
|
|
|
|
echo "versionId: $version_id"
|
2024-03-11 03:00:33 +00:00
|
|
|
|
|
2024-03-05 15:30:25 +00:00
|
|
|
|
if [[ $version_id =~ ^[0-9]+$ ]]; then
|
|
|
|
|
curl --retry 3 -X POST -H "Cache-Control: no-cache" \
|
|
|
|
|
-H "Content-Type: multipart/form-data" \
|
|
|
|
|
-H "Cookie: xupdate_token=${{ secrets.XUPDATE_TOKEN }}" \
|
|
|
|
|
-H "X-Token: ${{ secrets.X_TOKEN }}" \
|
|
|
|
|
-F "file=@${{ env.output }}/${apk};filename=${apk}" \
|
|
|
|
|
-F "versionId=${version_id}" \
|
|
|
|
|
${{ secrets.URL_UPLOAD_APK }}
|
2024-03-11 03:00:33 +00:00
|
|
|
|
|
2024-03-05 15:30:25 +00:00
|
|
|
|
# If upload is successful, set success to true to exit the retry loop
|
|
|
|
|
if [[ $? -eq 0 ]]; then
|
|
|
|
|
success=true
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
echo "Error: version_id is not a valid number. skip upload apk"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
# 存档打包的文件,以便后续上传,TODO: 看起来有点笨,有没有更好的方法?
|
2024-01-16 09:54:23 +00:00
|
|
|
|
- name: Upload App To Artifact universal
|
|
|
|
|
if: success () || failure ()
|
2024-03-05 15:30:25 +00:00
|
|
|
|
uses: actions/upload-artifact@v4
|
2023-02-10 07:19:54 +00:00
|
|
|
|
with:
|
2024-03-05 15:30:25 +00:00
|
|
|
|
name: "SmsF_${{ env.ver_name }}_100${{ env.ver_code }}_universal_release.apk"
|
2024-03-11 03:00:33 +00:00
|
|
|
|
path: "${{ env.output }}/SmsF_*_universal_release.apk"
|
2024-01-16 09:54:23 +00:00
|
|
|
|
- name: Upload App To Artifact armeabi-v7a
|
|
|
|
|
if: success () || failure ()
|
2024-03-05 15:30:25 +00:00
|
|
|
|
uses: actions/upload-artifact@v4
|
2024-01-16 09:54:23 +00:00
|
|
|
|
with:
|
2024-03-05 15:30:25 +00:00
|
|
|
|
name: "SmsF_${{ env.ver_name }}_200${{ env.ver_code }}_armeabi-v7a_release.apk"
|
2024-03-11 03:00:33 +00:00
|
|
|
|
path: "${{ env.output }}/SmsF_*_armeabi-v7a_release.apk"
|
2024-01-16 09:54:23 +00:00
|
|
|
|
- name: Upload App To Artifact arm64-v8a
|
|
|
|
|
if: success () || failure ()
|
2024-03-05 15:30:25 +00:00
|
|
|
|
uses: actions/upload-artifact@v4
|
2024-01-16 09:54:23 +00:00
|
|
|
|
with:
|
2024-03-05 15:30:25 +00:00
|
|
|
|
name: "SmsF_${{ env.ver_name }}_300${{ env.ver_code }}_arm64-v8a_release.apk"
|
2024-03-11 03:00:33 +00:00
|
|
|
|
path: "${{ env.output }}/SmsF_*_arm64-v8a_release.apk"
|
2024-01-16 09:54:23 +00:00
|
|
|
|
- name: Upload App To Artifact x86
|
|
|
|
|
if: success () || failure ()
|
2024-03-05 15:30:25 +00:00
|
|
|
|
uses: actions/upload-artifact@v4
|
2024-01-16 09:54:23 +00:00
|
|
|
|
with:
|
2024-03-05 15:30:25 +00:00
|
|
|
|
name: "SmsF_${{ env.ver_name }}_400${{ env.ver_code }}_x86_release.apk"
|
2024-03-11 03:00:33 +00:00
|
|
|
|
path: "${{ env.output }}/SmsF_*_x86_release.apk"
|
2024-01-16 09:54:23 +00:00
|
|
|
|
- name: Upload App To Artifact x86_64
|
|
|
|
|
if: success () || failure ()
|
2024-03-05 15:30:25 +00:00
|
|
|
|
uses: actions/upload-artifact@v4
|
2024-01-16 09:54:23 +00:00
|
|
|
|
with:
|
2024-03-05 15:30:25 +00:00
|
|
|
|
name: "SmsF_${{ env.ver_name }}_500${{ env.ver_code }}_x86_64_release.apk"
|
2024-03-11 03:00:33 +00:00
|
|
|
|
path: "${{ env.output }}/SmsF_*_x86_64_release.apk"
|