1.域名重新分组;2.定时更新hosts;3.优化代码 #1
Workflow file for this run
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: Update hosts | |
on: | |
push: | |
paths: | |
- 'setHosts.py' | |
- 'requirements.txt' | |
schedule: | |
- cron: '0 */4 * * *' | |
workflow_dispatch: # 允许手动触发 | |
jobs: | |
update-hosts: | |
runs-on: ubuntu-latest | |
# 添加并发限制,避免同时运行多个工作流 | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 # 减少克隆深度,加快检出速度 | |
- name: Set up Python | |
uses: actions/setup-python@v5 # 使用最新的 v5 版本 | |
with: | |
python-version: '3.11' | |
cache: 'pip' # 启用 pip 缓存 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Run hosts update script | |
run: | | |
sudo python setHosts.py | |
- name: Commit and push changes | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "action_bot" | |
if [[ -n $(git status -s) ]]; then | |
git add . | |
git commit -m "更新 hosts 内容" | |
git push | |
else | |
echo "No changes to commit" | |
fi |