Files
ZFScoresCheck/.gitea/workflows/check-scores.yml
T
2026-07-27 21:07:41 +08:00

204 lines
5.9 KiB
YAML

name: CheckScores
run-name: ${{ gitea.workflow }} ${{ gitea.sha }}
on:
schedule:
# 每小时的第 0、30 分钟运行,即每 30 分钟一次
- cron: "*/30 * * * *"
workflow_dispatch:
inputs:
force_push_message:
description: "Whether or not to force a push message?"
required: true
default: "False"
type: choice
options:
- "True"
- "False"
# 允许内置 GITEA_TOKEN 向当前仓库提交代码
permissions:
contents: write
jobs:
CheckScores:
name: CheckScores
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: https://github.com/actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITEA_TOKEN }}
- name: Configure Git
run: |
git config --global user.email "actions@gitea.local"
git config --global user.name "Gitea Actions"
- name: Set up Python
uses: https://github.com/actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install requests rsa pyquery
- name: Get Connection
run: |
url="https://ifconfig.me/all"
response="$(curl -fsS "$url" || true)"
echo "$response"
- name: Run main program
id: run_main_program
env:
# 定时触发时此值为空,下面的脚本会自动改为 False
FORCE_PUSH_MESSAGE: ${{ gitea.event.inputs.force_push_message }}
URL: ${{ secrets.URL }}
USERNAME: ${{ secrets.USERNAME }}
PASSWORD: ${{ secrets.PASSWORD }}
TOKEN: ${{ secrets.TOKEN }}
GITEA_REF_NAME: ${{ gitea.ref_name }}
GITEA_EVENT_NAME: ${{ gitea.event_name }}
GITEA_ACTOR: ${{ gitea.actor }}
GITEA_TRIGGERING_ACTOR: ${{ gitea.triggering_actor }}
REPOSITORY_NAME: ${{ gitea.repository }}
GITEA_SHA: ${{ gitea.sha }}
GITEA_WORKFLOW: ${{ gitea.workflow }}
GITEA_RUN_NUMBER: ${{ gitea.run_number }}
GITEA_RUN_ID: ${{ gitea.run_id }}
run: |
set -euo pipefail
secret_is_empty=false
if [ -z "${URL:-}" ]; then
echo "错误:URL Secret 为空。"
secret_is_empty=true
fi
if [ -z "${USERNAME:-}" ]; then
echo "错误:USERNAME Secret 为空。"
secret_is_empty=true
fi
if [ -z "${PASSWORD:-}" ]; then
echo "错误:PASSWORD Secret 为空。"
secret_is_empty=true
fi
if [ -z "${TOKEN:-}" ]; then
echo "错误:TOKEN Secret 为空。"
secret_is_empty=true
fi
if [ "$secret_is_empty" = true ]; then
echo "一个或多个 Secrets 未配置。"
exit 1
fi
# 定时任务没有 workflow_dispatch 输入,默认使用 False
export FORCE_PUSH_MESSAGE="${FORCE_PUSH_MESSAGE:-False}"
export BEIJING_TIME="$(
TZ='Asia/Shanghai' date +'%Y-%m-%d %H:%M:%S:%3N'
)"
echo "BEIJING_TIME=$BEIJING_TIME" >> "$GITEA_OUTPUT"
mask_middle() {
local input="$1"
local length="${#input}"
if [ "$length" -le 3 ]; then
printf '%*s\n' "$length" '' | tr ' ' '*'
else
local first="${input:0:1}"
local last="${input: -1}"
local middle_length=$((length - 2))
local middle
middle="$(printf '%*s' "$middle_length" '' | tr ' ' '*')"
echo "${first}${middle}${last}"
fi
}
anonymize_domain() {
local url="$1"
local protocol
local rest
local domain
local path
local anonymized_domain=""
protocol="$(echo "$url" | sed -n 's#^\(.*://\).*#\1#p')"
rest="${url#*://}"
domain="$(echo "$rest" | sed 's#/.*##')"
path="$(echo "$rest" | sed 's#^[^/]*##')"
IFS='.' read -r -a domain_parts <<< "$domain"
for part in "${domain_parts[@]}"; do
anonymized_domain+="$(printf '%*s' "${#part}" '' | tr ' ' '*')."
done
anonymized_domain="${anonymized_domain%.}"
echo "${protocol}${anonymized_domain}${path}"
}
LOGINURL="xtgl/login_slogin.html"
echo "URL: $(anonymize_domain "$URL")${LOGINURL}"
echo "Username: $(mask_middle "$USERNAME")"
echo "Password: $(mask_middle "$PASSWORD")"
echo "Force Push Message: $FORCE_PUSH_MESSAGE"
echo "Branch Name: $GITEA_REF_NAME"
echo "Triggered By: $GITEA_EVENT_NAME"
echo "Initial Run By: $GITEA_ACTOR"
echo "Initiated Run By: $GITEA_TRIGGERING_ACTOR"
echo "Repository Name: $REPOSITORY_NAME"
echo "Commit SHA: $GITEA_SHA"
echo "Workflow Name: $GITEA_WORKFLOW"
echo "Workflow Number: $GITEA_RUN_NUMBER"
echo "Workflow ID: $GITEA_RUN_ID"
echo "Beijing Time: $BEIJING_TIME"
echo "------"
python main.py
- name: Delete __pycache__ folders
run: |
find . \
-type d \
-name "__pycache__" \
-prune \
-exec rm -rf {} +
- name: Commit and push changes
env:
BRANCH_NAME: ${{ gitea.ref_name }}
run: |
set -euo pipefail
git add -A
if git diff --cached --quiet; then
echo "没有需要提交的更改。"
exit 0
fi
git commit -m "Update from Gitea Actions"
# 避免使用 --force 覆盖远端提交
git pull --rebase origin "$BRANCH_NAME"
git push origin "HEAD:$BRANCH_NAME"