Monitor Snapshot Updates #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Monitor Snapshot Updates | |
on: | |
schedule: | |
- cron: '0 * * * *' # 每小时运行一次 | |
workflow_dispatch: | |
jobs: | |
monitor: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Fetch current snapshot files | |
run: | | |
URL="https://downloads.immortalwrt.org/snapshots/targets/x86/64/" | |
curl -s $URL > $RUNNER_TEMP/current_snapshot.html | |
- name: Compare with previous snapshot | |
run: | | |
LAST_SNAPSHOT="$RUNNER_TEMP/last_snapshot.html" | |
CURRENT_SNAPSHOT="$RUNNER_TEMP/current_snapshot.html" | |
# 如果之前没有保存快照,初始化空文件 | |
if [ ! -f "$LAST_SNAPSHOT" ]; then | |
echo "首次运行,创建初始快照文件。" | |
touch "$LAST_SNAPSHOT" | |
fi | |
# 对比快照文件 | |
if ! cmp -s "$CURRENT_SNAPSHOT" "$LAST_SNAPSHOT"; then | |
echo "检测到更新!" | |
echo "::set-output name=updated::true" | |
else | |
echo "没有检测到更新。" | |
echo "::set-output name=updated::false" | |
fi | |
- name: Save the latest snapshot | |
if: steps.check_update.outputs.updated == 'true' | |
run: | | |
mv $RUNNER_TEMP/current_snapshot.html $RUNNER_TEMP/last_snapshot.html |