更新目录结构和提交历史 #5
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 Directory Tree | |
on: | |
schedule: | |
- cron: '0 0 * * *' # 每天 UTC 00:00 运行 | |
workflow_dispatch: # 允许手动触发 | |
jobs: | |
update-directory-tree: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: directory-tree-updates # 使用固定的分支名 | |
fetch-depth: 1 | |
- name: Create branch if not exists | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
# 尝试检出分支,如果不存在则创建 | |
git checkout directory-tree-updates 2>/dev/null || git checkout -b directory-tree-updates | |
- name: Install tree | |
run: sudo apt-get install -y tree | |
- name: Create Directory Tree | |
run: | | |
echo "# Personal Notes" > README.md | |
echo "" >> README.md | |
echo "## Directory Structure" >> README.md | |
echo "Last updated: $(date '+%Y-%m-%d %H:%M:%S %Z')" >> README.md | |
echo "" >> README.md | |
echo "\`\`\`" >> README.md | |
tree -L 2 -I '.git|.github|node_modules' --charset=ascii >> README.md | |
echo "\`\`\`" >> README.md | |
- name: Commit and Push Changes | |
run: | | |
git add README.md | |
git diff --quiet && git diff --staged --quiet || (git commit -m "docs: update directory tree" && git push origin directory-tree-updates --force) |