This commit is contained in:
NianBroken
2024-02-13 13:46:30 +08:00 Unverified
parent 0fc043e91a
commit 08d32845dd
+24 -6
View File
@@ -2,7 +2,7 @@ name: CheckScores
on: on:
schedule: schedule:
- cron: "*/30 * * * *" # 每30分钟执行一次123 - cron: "*/30 * * * *" # 每30分钟执行一次
workflow_dispatch: workflow_dispatch:
inputs: inputs:
force_push_message: force_push_message:
@@ -41,14 +41,19 @@ jobs:
git config --global user.email "actions@github.com" git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions" git config --global user.name "GitHub Actions"
# 拉取上游 main 分支最新代码并强制覆盖当前分支的 .github/workflows/main.yml 文件 # 添加上游仓库作为远程仓库,并获取上游仓库的main分支最新更改
- name: Fetch and override upstream workflows - name: Fetch upstream changes
run: | run: |
git remote add upstream https://github.com/NianBroken/ZFCheckScores.git
git fetch upstream main git fetch upstream main
git checkout upstream/main .github/workflows/main.yml
# 检查上游分支的 .github/workflows/main.yml 文件是否有更改
git diff --exit-code upstream/main -- .github/workflows/main.yml || {
echo "Upstream main branch's .github/workflows/main.yml file has changed. Force pushing changes."
git checkout upstream/main -- .github/workflows/main.yml
git add .github/workflows/main.yml git add .github/workflows/main.yml
git commit -m "Override main.yml from upstream" git commit -m "Update .github/workflows/main.yml from upstream"
git push origin main }
# 创建一个备份目录,并将当前目录中的所有.txt文件复制到备份目录 # 创建一个备份目录,并将当前目录中的所有.txt文件复制到备份目录
- name: Backup local .txt files - name: Backup local .txt files
@@ -56,6 +61,19 @@ jobs:
mkdir -p backup mkdir -p backup
cp -r *.txt backup/ || echo "No .txt files to backup" cp -r *.txt backup/ || echo "No .txt files to backup"
# 将上游main分支的更改强制推送到当前main分支
- name: Force push changes from upstream to current main branch
run: |
git checkout main
git reset --hard upstream/main
git push origin main --force
# 从备份目录将.txt文件还原到当前目录,然后删除备份目录
- name: Restore local .txt files and delete backup
run: |
cp -r backup/*.txt . || echo "No .txt files to restore"
rm -rf backup
# 运行主程序main.py # 运行主程序main.py
- name: Run main.py - name: Run main.py
env: env: