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

106 lines
3.0 KiB
YAML

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 {} +