Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
mgqnfoqv7k2w
AutoBuildImmortalWrt
Commits
6a0acefe
Unverified
Commit
6a0acefe
authored
Aug 13, 2025
by
wukongdaily
Committed by
GitHub
Aug 13, 2025
Browse files
Create clean-workflow.yml
parent
b617c227
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
+52
-0
.github/workflows/clean-workflow.yml
.github/workflows/clean-workflow.yml
+52
-0
No files found.
.github/workflows/clean-workflow.yml
0 → 100644
View file @
6a0acefe
name
:
Cleanup Old Workflow Runs
on
:
workflow_dispatch
:
inputs
:
keep_days
:
description
:
"
保留最近多少天(默认
1)"
required
:
false
default
:
"
1"
jobs
:
cleanup
:
runs-on
:
ubuntu-latest
permissions
:
actions
:
write
steps
:
-
name
:
安装 jq
run
:
|
sudo apt-get update
sudo apt-get install -y jq
-
name
:
删除指定天数前的已完成运行
env
:
GH_TOKEN
:
${{ secrets.GITHUB_TOKEN }}
KEEP_DAYS
:
${{ github.event.inputs.keep_days }}
run
:
|
: "${KEEP_DAYS:=1}"
THRESHOLD="$(date -u -d "${KEEP_DAYS} days ago" '+%Y-%m-%dT%H:%M:%SZ')"
echo "阈值时间(UTC):$THRESHOLD"
RUN_IDS=$(gh api -X GET "repos/${GITHUB_REPOSITORY}/actions/runs" \
--paginate -F per_page=100 \
--jq '.workflow_runs[]
| select(.status=="completed" and .created_at < "'"$THRESHOLD"'")
| .id')
if [ -z "$RUN_IDS" ]; then
echo "✅ 没有可删除的运行"
exit 0
fi
echo "待删除运行数量:$(wc -w <<< "$RUN_IDS")"
for ID in $RUN_IDS; do
echo "🗑 正在删除运行 ID: $ID"
gh api -X DELETE "repos/${GITHUB_REPOSITORY}/actions/runs/${ID}" || {
echo "⚠️ 删除失败:$ID(将继续处理其他项)"
}
sleep 0.2
done
echo "🎉 清理完成"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment