Auto backup Wiki #5066
This file contains hidden or 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: Auto backup Wiki | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| # GitHub Wiki 没有可供 Actions 直接订阅的变更事件,保留低频轮询作为兜底。 | |
| - cron: '17 */2 * * *' | |
| permissions: | |
| actions: write | |
| contents: write | |
| concurrency: | |
| group: main-writers | |
| jobs: | |
| backup-wiki-root: | |
| if: github.repository == 'Aethersailor/Custom_OpenClash_Rules' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout main branch for wiki backup | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 | |
| with: | |
| ref: main | |
| fetch-depth: 0 | |
| - name: Clone wiki repository with auth | |
| env: | |
| TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git clone "https://x-access-token:${TOKEN}@github.com/${{ github.repository }}.wiki.git" _wiki | |
| - name: Build and validate Wiki backup | |
| run: | | |
| python .github/scripts/wiki_backup.py \ | |
| --source _wiki \ | |
| --destination "$RUNNER_TEMP/wiki-backup" \ | |
| --repository "${GITHUB_REPOSITORY}" | |
| - name: Replace validated Wiki Markdown backup | |
| run: | | |
| mkdir -p wiki | |
| find wiki -maxdepth 1 -type f -name '*.md' -delete | |
| cp "$RUNNER_TEMP"/wiki-backup/*.md wiki/ | |
| - name: Commit and push changes | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add wiki | |
| if ! git diff --cached --quiet; then | |
| git commit -m "chore(wiki): auto backup Wiki" | |
| git pull --rebase origin main | |
| git push origin HEAD:main | |
| gh workflow run pages.yml --ref main | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |