Skip to content

Update README Timestamps #258

Update README Timestamps

Update README Timestamps #258

Workflow file for this run

name: Update README Timestamps
on:
push:
paths:
- 'HiddifyConfigsCLI/bin/Debug/net8.0/valid_links.txt'
- 'HiddifyConfigsCLI/bin/Debug/net8.0/valid_links_01.txt'
- 'HiddifyConfigsCLI/bin/Debug/net8.0/valid_links_02.txt'
schedule:
- cron: '0 20 * * *'
workflow_dispatch:
jobs:
update-readme:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout with full history
uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0
- name: Get timestamps
id: ts
run: |
format_time() {
local f="$1"
if [ ! -f "$f" ]; then
echo "1970-01-01 00:00:00"
return
fi
git log -1 --format="%cd" --date=format-local:'%Y-%m-%d %H:%M:%S' "$f" 2>/dev/null || echo "1970-01-01 00:00:00"
}
echo "ALL_TIME=$(format_time 'HiddifyConfigsCLI/bin/Debug/net8.0/valid_links.txt') +0800" >> $GITHUB_OUTPUT
echo "P01_TIME=$(format_time 'HiddifyConfigsCLI/bin/Debug/net8.0/valid_links_01.txt') +0800" >> $GITHUB_OUTPUT
echo "P02_TIME=$(format_time 'HiddifyConfigsCLI/bin/Debug/net8.0/valid_links_02.txt') +0800" >> $GITHUB_OUTPUT
- name: Replace time in [] using sed (safe & simple)
run: |
# 转义 sed 特殊字符
escape_sed() {
echo "$1" | sed 's/[&/\]/\\&/g'
}
ALL_ESC=$(escape_sed "${{ steps.ts.outputs.ALL_TIME }}")
P01_ESC=$(escape_sed "${{ steps.ts.outputs.P01_TIME }}")
P02_ESC=$(escape_sed "${{ steps.ts.outputs.P02_TIME }}")
# 替换 valid_links.txt 行
sed -i "/valid_links\.txt/ s/\[Last Updated: [^]]\+\]/[Last Updated: $ALL_ESC]/" README.md
sed -i "/valid_links_01\.txt/ s/\[Last Updated: [^]]\+\]/[Last Updated: $P01_ESC]/" README.md
sed -i "/valid_links_02\.txt/ s/\[Last Updated: [^]]\+\]/[Last Updated: $P02_ESC]/" README.md
echo "=== Updated timestamps ==="
grep "Last Updated" README.md || true
- name: Commit if changed
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if [[ "${{ github.event_name }}" == "push" ]]; then
if git diff --quiet HEAD~1 -- HiddifyConfigsCLI/bin/Debug/net8.0/valid_links*.txt 2>/dev/null; then
echo "No source change → skip"
exit 0
fi
fi
git add README.md
if git diff --quiet --staged; then
echo "README unchanged → skip"
exit 0
fi
git commit -m "chore: update timestamps [skip ci]"
git push