Skip to content

Commit

Permalink
action
Browse files Browse the repository at this point in the history
  • Loading branch information
jing332 committed Jan 14, 2024
1 parent bb1db04 commit 6ee8683
Show file tree
Hide file tree
Showing 12 changed files with 506 additions and 11 deletions.
53 changes: 53 additions & 0 deletions .github/scripts/check_alist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

function to_int() {
echo $(echo "$1" | grep -oE '[0-9]+' | tr -d '\n')
}

function get_latest_version() {
echo $(curl -s https://api.github.com/repos/alist-org/alist/releases/latest | grep -o '"tag_name": ".*"' | cut -d'"' -f4)
}

LATEST_VER=""
for index in $(seq 5)
do
echo "Try to get latest version, index=$index"
LATEST_VER=$(get_latest_version)
if [ -z "$LATEST_VER" ]; then
if [ "$index" -ge 5 ]; then
echo "Failed to get latest version, exit"
exit 1
fi
echo "Failed to get latest version, sleep 15s and retry"
sleep 15
else
break
fi

done

LATEST_VER_INT=$(to_int "$LATEST_VER")
echo "Latest AList version $LATEST_VER ${LATEST_VER_INT}"

echo "alist_version=$LATEST_VER" >> "$GITHUB_ENV"
# VERSION_FILE="$GITHUB_WORKSPACE/alist_version.txt"

VER=$(cat "$VERSION_FILE")

if [ -z "$VER" ]; then
VER="v3.25.1"
echo "No version file, use default version ${VER}"
fi

VER_INT=$(to_int $VER)

echo "Current AList version: $VER ${VER_INT}"


if [ "$VER_INT" -ge "$LATEST_VER_INT" ]; then
echo "Current >= Latest"
echo "alist_update=0" >> "$GITHUB_ENV"
else
echo "Current < Latest"
echo "alist_update=1" >> "$GITHUB_ENV"
fi
98 changes: 98 additions & 0 deletions .github/scripts/lzy_web.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import requests, os, datetime, sys

# Cookie 中 phpdisk_info 的值
cookie_phpdisk_info = os.environ.get('phpdisk_info')
# Cookie 中 ylogin 的值
cookie_ylogin = os.environ.get('ylogin')

# 请求头
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36 Edg/89.0.774.45',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Referer': 'https://pc.woozooo.com/account.php?action=login'
}

# 小饼干
cookie = {
'ylogin': cookie_ylogin,
'phpdisk_info': cookie_phpdisk_info
}


# 日志打印
def log(msg):
utc_time = datetime.datetime.utcnow()
china_time = utc_time + datetime.timedelta(hours=8)
print(f"[{china_time.strftime('%Y.%m.%d %H:%M:%S')}] {msg}")


# 检查是否已登录
def login_by_cookie():
url_account = "https://pc.woozooo.com/account.php"
if cookie['phpdisk_info'] is None:
log('ERROR: 请指定 Cookie 中 phpdisk_info 的值!')
return False
if cookie['ylogin'] is None:
log('ERROR: 请指定 Cookie 中 ylogin 的值!')
return False
res = requests.get(url_account, headers=headers, cookies=cookie, verify=True)
if '网盘用户登录' in res.text:
log('ERROR: 登录失败,请更新Cookie')
return False
else:
log('登录成功')
return True


# 上传文件
def upload_file(file_dir, folder_id):
file_name = os.path.basename(file_dir)
url_upload = "https://up.woozooo.com/fileup.php"
headers['Referer'] = f'https://up.woozooo.com/mydisk.php?item=files&action=index&u={cookie_ylogin}'
post_data = {
"task": "1",
"folder_id": folder_id,
"id": "WU_FILE_0",
"name": file_name,
}
files = {'upload_file': (file_name, open(file_dir, "rb"), 'application/octet-stream')}
res = requests.post(url_upload, data=post_data, files=files, headers=headers, cookies=cookie, timeout=120).json()
log(f"{file_dir} -> {res['info']}")
return res['zt'] == 1


# 上传文件夹内的文件
def upload_folder(folder_dir, folder_id):
file_list = sorted(os.listdir(folder_dir), reverse=True)
for file in file_list:
path = os.path.join(folder_dir, file)
if os.path.isfile(path):
upload_file(path, folder_id)
else:
upload_folder(path, folder_id)


# 上传
def upload(dir, folder_id):
if dir is None:
log('ERROR: 请指定上传的文件路径')
return
if folder_id is None:
log('ERROR: 请指定蓝奏云的文件夹id')
return
if os.path.isfile(dir):
upload_file(dir, str(folder_id))
else:
upload_folder(dir, str(folder_id))


if __name__ == '__main__':
argv = sys.argv[1:]
if len(argv) != 2:
log('ERROR: 参数错误,请以这种格式重新尝试\npython lzy_web.py 需上传的路径 蓝奏云文件夹id')
# 需上传的路径
upload_path = argv[0]
# 蓝奏云文件夹id
lzy_folder_id = argv[1]
if login_by_cookie():
upload(upload_path, lzy_folder_id)
126 changes: 126 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: Build

on:
push:
branches:
- "master"
paths-ignore:
- "*.md"
- "*.sh"
- "release.yaml"
# - "sync_frp.yaml"

workflow_dispatch:

jobs:
go:
runs-on: ubuntu-latest
strategy:
matrix:
GO_ARCH: [ "386", amd64, arm, arm64 ]
steps:
- uses: actions/checkout@v3

- name: Download AList Source Code
run: |
cd $GITHUB_WORKSPACE/alist-lib/scripts
chmod +x *.sh
./init_alist_core.sh
./init_alist_web.sh
- uses: actions/setup-go@v4
with:
go-version: 1.21.5
cache-dependency-path: ${{ github.workspace }}/alist-lib/go.sum

- name: Build
run: |
cd $GITHUB_WORKSPACE/alist-lib
GOARCH=${{ matrix.GO_ARCH }}
declare -A goarch2cc=( ["arm64"]="aarch64-linux-android32-clang" ["arm"]="armv7a-linux-androideabi32-clang" ["amd64"]="x86_64-linux-android32-clang" ["386"]="i686-linux-android32-clang")
export CC="$ANDROID_NDK_LATEST_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/${goarch2cc[$GOARCH]}"
declare -A arch2lib=( ["arm64"]="arm64-v8a" ["arm"]="armeabi-v7a" ["amd64"]="x86_64" ["386"]="x86")
export LIB="${arch2lib[$GOARCH]}"
./scripts/install_alist.sh $GOARCH $LIB
- name: Upload to Artifact
uses: actions/upload-artifact@v3
with:
name: "app_libs"
path: "${{ github.workspace }}/android/app/libs"

android:
runs-on: ubuntu-latest
needs: [ go ]
env:
output: "${{ github.workspace }}/build/app/outputs/apk/release"
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17

- name: Setup Gradle
uses: gradle/[email protected]

- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: "app_libs"
path: "${{ github.workspace }}/android/app/libs"

- name: Init Signature
run: |
cd android
touch local.properties
echo ALIAS_NAME='${{ secrets.ALIAS_NAME }}' >> local.properties
echo ALIAS_PASSWORD='${{ secrets.ALIAS_PASSWORD }}' >> local.properties
echo KEY_PASSWORD='${{ secrets.KEY_PASSWORD }}' >> local.properties
echo KEY_PATH='./key.jks' >> local.properties
# 从Secrets读取无换行符Base64解码, 然后保存到到app/key.jks
echo ${{ secrets.KEY_STORE }} | base64 --decode > $GITHUB_WORKSPACE/app/key.jks
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.16.7'
- run: flutter build apk --split-per-abi --release

- name: Upload missing_rules.txt
if: failure() && steps.gradle.outcome != 'success'
uses: actions/upload-artifact@v3
with:
name: "missing_rules"
path: "${{ github.workspace }}/build/app/outputs/mapping/release/missing_rules.txt"

- name: Init APP Version Name
run: |
echo "ver_name=$(grep -m 1 'versionName' ${{ env.output }}/output-metadata.json | cut -d\" -f4)" >> $GITHUB_ENV
- name: Upload App To Artifact arm64-v8a
if: success () || failure ()
uses: actions/upload-artifact@v3
with:
name: "AListAndroid-v${{ env.ver_name }}_arm64-v8a"
path: "${{ env.output }}/*-v8a.apk"

- name: Upload App To Artifact arm-v7a
if: success () || failure ()
uses: actions/upload-artifact@v3
with:
name: "AListAndroid-v${{ env.ver_name }}_arm-v7a"
path: "${{ env.output }}/*-v7a.apk"

- name: Upload App To Artifact x86
if: success () || failure ()
uses: actions/upload-artifact@v3
with:
name: "AListAndroid-v${{ env.ver_name }}_x86"
path: "${{ env.output }}/*_x86.apk"
Loading

0 comments on commit 6ee8683

Please sign in to comment.