Fetch #5789
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: Fetch | |
on: | |
workflow_dispatch: | |
schedule: | |
# 表达式生成 https://crontab.guru/ | |
- cron: '30 */1 * * *' | |
push: | |
paths: | |
- 'sources.list' | |
- 'config.yml' | |
- '.github/workflows/**' | |
- '**.py' | |
- 'snippets/_*' | |
jobs: | |
fetch: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 迁出代码 | |
uses: actions/checkout@v3 | |
- name: 安装 Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
cache: 'pip' | |
- name: 设置时区 | |
run: sudo timedatectl set-timezone 'Asia/Shanghai' | |
- name: 安装依赖 | |
run: pip install -r requirements.txt | |
- name: 执行任务 | |
run: python ./fetch.py | |
- name: 提交更改 | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Actions" | |
git pull origin master | |
git add list* | |
git add snippets/ | |
git commit -m "$(date '+%Y-%m-%d %H:%M:%S') 抓取节点" | |
- name: 推送更改 | |
uses: ad-m/github-push-action@master | |
with: | |
branch: master | |
- name: 计算要清除缓存的文件 | |
id: purge_urls | |
run: | | |
sleep 3 | |
baseUrl="https://cdn.jsdelivr.net/gh/${{ github.repository }}@master" | |
urls="" | |
for f in `find snippets -name "*.yml" -type f`; do | |
urls+="${baseUrl}/${f}," | |
done | |
for f in `find . -name "list*" -type f -maxdepth 1`; do | |
urls+="${baseUrl}/${f}," | |
done | |
echo "urls=${urls%,*}" >> $GITHUB_OUTPUT | |
- name: 清除 JsDelivr CDN 缓存 | |
uses: egad13/[email protected] | |
with: | |
url: ${{ steps.purge_urls.outputs.urls }} |