Optimize some code

This commit is contained in:
NianBroken
2024-08-03 00:47:39 +08:00 Unverified
parent b7a47ceea5
commit b676fb6aca
4 changed files with 122 additions and 46 deletions
+8 -10
View File
@@ -24,13 +24,6 @@ jobs:
runs-on: ubuntu-latest
steps:
# 判断 GITHUB_TOKEN 是否存在,如果不存在就退出
- name: Check Secret
run: |
if [ -z "$GITHUB_TOKEN" ]; then
exit 0
fi
# 使用GitHub Actions提供的动作来检出代码库
- name: Checkout Repository
uses: actions/checkout@main
@@ -70,6 +63,11 @@ jobs:
GITHUB_RUN_NUMBER: ${{ github.run_number }}
GITHUB_RUN_ID: ${{ github.run_id }}
run: |
# 判断 GITHUB_TOKEN 是否存在,如果不存在就退出
if [ -z "$GITHUB_TOKEN" ]; then
exit 0
fi
# 运行主程序
export BEIJING_TIME="$(TZ='Asia/Shanghai' date +'%Y-%m-%d %H:%M:%S:%3N')"
echo "BEIJING_TIME=$BEIJING_TIME" >> $GITHUB_OUTPUT
@@ -92,9 +90,6 @@ jobs:
export HOUR_COUNT="${{ github.event.inputs.hour_count }}"
fi
python scripts/delete_old_runs.py
echo "------"
# 方便通过截图快速定位到用户
echo "Hour Count: $HOUR_COUNT"
echo "Branch Name: $GITHUB_REF_NAME"
@@ -112,6 +107,9 @@ jobs:
echo "Author's website: https://www.nianbroken.top/"
echo "Author's Repository URL: https://github.com/NianBroken/ZFCheckScores/"
echo "------"
python scripts/delete_old_runs.py
- name: Delete __pycache__ folder
run: |
# 删除__pycache__文件夹
+39 -29
View File
@@ -78,6 +78,40 @@ jobs:
GITHUB_RUN_ID: ${{ github.run_id }}
run: |
# 运行主程序
# 判断环境变量是否为空
if [ -z "$URL" ]; then
echo "URL Secret is empty!"
echo "::error title=URL Secret is empty!" \
"::Your 'URL' Secret is not filled with any" \
"information, so your program will not work!"
Whether_Secret_is_empty=true
fi
if [ -z "$USERNAME" ]; then
echo "USERNAME Secret is empty!"
echo "::error title=USERNAME Secret is empty!" \
"::Your 'USERNAME' Secret is not filled with any" \
"information, so your program will not work!"
Whether_Secret_is_empty=true
fi
if [ -z "$PASSWORD" ]; then
echo "PASSWORD Secret is empty!"
echo "::error title=PASSWORD Secret is empty!" \
"::Your 'PASSWORD' Secret is not filled with any" \
"information, so your program will not work!"
Whether_Secret_is_empty=true
fi
if [ -z "$TOKEN" ]; then
echo "TOKEN Secret is empty!"
echo "::error title=TOKEN Secret is empty!" \
"::Your 'TOKEN' Secret is not filled with any" \
"information, so your program will not work!"
Whether_Secret_is_empty=true
fi
if [ "$Whether_Secret_is_empty" = true ]; then
echo "One or more Secrets are empty."
exit 1
fi
# 判断是否需要强制推送信息
if [ -z "${{ github.event.inputs.force_push_message }}" ]; then
export FORCE_PUSH_MESSAGE="False"
@@ -86,34 +120,6 @@ jobs:
fi
export BEIJING_TIME="$(TZ='Asia/Shanghai' date +'%Y-%m-%d %H:%M:%S:%3N')"
echo "BEIJING_TIME=$BEIJING_TIME" >> $GITHUB_OUTPUT
python main.py
echo "------"
# 判断环境变量是否为空
if [ -z "$URL" ]; then
echo "URL Secret is empty!"
echo "::error title=URL Secret is empty!" \
"::Your 'URL' Secret is not filled with any" \
"information, so your program will not work!"
fi
if [ -z "$USERNAME" ]; then
echo "USERNAME Secret is empty!"
echo "::error title=USERNAME Secret is empty!" \
"::Your 'USERNAME' Secret is not filled with any" \
"information, so your program will not work!"
fi
if [ -z "$PASSWORD" ]; then
echo "PASSWORD Secret is empty!"
echo "::error title=PASSWORD Secret is empty!" \
"::Your 'PASSWORD' Secret is not filled with any" \
"information, so your program will not work!"
fi
if [ -z "$TOKEN" ]; then
echo "TOKEN Secret is empty!"
echo "::error title=TOKEN Secret is empty!" \
"::Your 'TOKEN' Secret is not filled with any" \
"information, so your program will not work!"
fi
# 定义 mask_middle 函数,接收一个字符串作为输入参数
mask_middle() {
@@ -150,6 +156,7 @@ jobs:
# 组合协议、匿名化后的域名和路径,输出结果
echo "${protocol}${anonymized_domain}${path}"
}
LOGINURL="xtgl/login_slogin.html"
# 方便通过截图快速定位到用户
@@ -172,6 +179,9 @@ jobs:
echo "Author's website: https://www.nianbroken.top/"
echo "Author's Repository URL: https://github.com/NianBroken/ZFCheckScores/"
echo "------"
python main.py
- name: Delete __pycache__ folder
run: |
# 删除__pycache__文件夹
@@ -183,4 +193,4 @@ jobs:
# 将更改强制推送到运行分支
git add .
git commit -m "Update from GitHub Actions" || true
git push origin $GITHUB_REF_NAME --force
git push origin $GITHUB_REF_NAME --force