gitea
This commit is contained in:
@@ -0,0 +1,204 @@
|
||||
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"
|
||||
@@ -0,0 +1,106 @@
|
||||
name: DeleteOldRuns
|
||||
|
||||
run-name: DeleteOldRuns
|
||||
|
||||
on:
|
||||
schedule:
|
||||
# Gitea 1.23+ 按 UTC 解释:
|
||||
# UTC 16:00 = 北京时间次日 00:00
|
||||
- cron: "0 16 * * *"
|
||||
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
hour_count:
|
||||
description: "删除多少小时前的运行记录?"
|
||||
required: true
|
||||
default: "168"
|
||||
type: string
|
||||
|
||||
# 读取仓库代码,并允许删除 Actions 运行记录
|
||||
permissions:
|
||||
contents: read
|
||||
actions: write
|
||||
|
||||
jobs:
|
||||
DeleteOldRuns:
|
||||
name: DeleteOldRuns
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
|
||||
- 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
|
||||
|
||||
- name: Get Connection
|
||||
run: |
|
||||
curl -fsS https://ifconfig.me/all || true
|
||||
|
||||
- name: Delete old Gitea Actions runs
|
||||
id: run_main_program
|
||||
env:
|
||||
# 手动运行时来自输入;定时运行时为空
|
||||
HOUR_COUNT: ${{ gitea.event.inputs.hour_count }}
|
||||
|
||||
# Gitea 自动提供的当前仓库令牌
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
|
||||
# 当前 Gitea 实例及运行信息
|
||||
GITEA_API_URL: ${{ gitea.api_url }}
|
||||
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||
GITEA_RUN_ID: ${{ gitea.run_id }}
|
||||
GITEA_REF_NAME: ${{ gitea.ref_name }}
|
||||
GITEA_EVENT_NAME: ${{ gitea.event_name }}
|
||||
GITEA_ACTOR: ${{ gitea.actor }}
|
||||
GITEA_TRIGGERING_ACTOR: ${{ gitea.triggering_actor }}
|
||||
GITEA_SHA: ${{ gitea.sha }}
|
||||
GITEA_WORKFLOW: ${{ gitea.workflow }}
|
||||
GITEA_RUN_NUMBER: ${{ gitea.run_number }}
|
||||
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
# 定时触发时没有 workflow_dispatch 输入,默认保留 168 小时
|
||||
if ! [[ "${HOUR_COUNT:-}" =~ ^[0-9]+$ ]]; then
|
||||
export HOUR_COUNT="168"
|
||||
fi
|
||||
|
||||
export BEIJING_TIME="$(
|
||||
TZ='Asia/Shanghai' date +'%Y-%m-%d %H:%M:%S:%3N'
|
||||
)"
|
||||
|
||||
echo "BEIJING_TIME=$BEIJING_TIME" >> "$GITEA_OUTPUT"
|
||||
|
||||
echo "Hour Count: $HOUR_COUNT"
|
||||
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: $GITEA_REPOSITORY"
|
||||
echo "Commit SHA: $GITEA_SHA"
|
||||
echo "Workflow Name: $GITEA_WORKFLOW"
|
||||
echo "Workflow Number: $GITEA_RUN_NUMBER"
|
||||
echo "Workflow ID: $GITEA_RUN_ID"
|
||||
echo "Gitea API URL: $GITEA_API_URL"
|
||||
echo "Beijing Time: $BEIJING_TIME"
|
||||
|
||||
echo "------"
|
||||
|
||||
python scripts/delete_old_runs.py
|
||||
|
||||
- name: Delete __pycache__ folders
|
||||
if: always()
|
||||
run: |
|
||||
find . \
|
||||
-type d \
|
||||
-name "__pycache__" \
|
||||
-prune \
|
||||
-exec rm -rf {} +
|
||||
Reference in New Issue
Block a user