|
| 1 | +name: sync wiki |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - v4 |
| 8 | + paths: |
| 9 | + - '.github/workflows/sync-wiki.yml' |
| 10 | + - 'scripts/sync_docs_to_wiki.py' |
| 11 | + - 'tests/test_sync_docs_to_wiki.py' |
| 12 | + - 'zh/**' |
| 13 | + - 'en/**' |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: sync-wiki-${{ github.ref }} |
| 17 | + cancel-in-progress: true |
| 18 | + |
| 19 | +jobs: |
| 20 | + sync: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Validate manual ref |
| 27 | + if: github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/v4' |
| 28 | + run: | |
| 29 | + echo "This workflow only publishes from refs/heads/v4. Re-run it from the v4 branch." |
| 30 | + exit 1 |
| 31 | +
|
| 32 | + - name: Check out docs repository |
| 33 | + uses: actions/checkout@v4 |
| 34 | + |
| 35 | + - name: Set up Python |
| 36 | + uses: actions/setup-python@v5 |
| 37 | + with: |
| 38 | + python-version: '3.11' |
| 39 | + |
| 40 | + - name: Run sync unit tests |
| 41 | + run: python -m unittest discover -s tests -p 'test_sync_docs_to_wiki.py' -v |
| 42 | + |
| 43 | + - name: Validate internal doc links |
| 44 | + run: python scripts/sync_docs_to_wiki.py --source-root . --check-links-only |
| 45 | + |
| 46 | + - name: Clone AstrBot wiki |
| 47 | + env: |
| 48 | + WIKI_TOKEN: ${{ secrets.ASTRBOT_WIKI_TOKEN }} |
| 49 | + run: | |
| 50 | + test -n "$WIKI_TOKEN" |
| 51 | + git clone "https://x-access-token:${WIKI_TOKEN}@github.com/AstrBotDevs/AstrBot.wiki.git" wiki |
| 52 | +
|
| 53 | + - name: Generate wiki pages |
| 54 | + run: python scripts/sync_docs_to_wiki.py --source-root . --wiki-root wiki |
| 55 | + |
| 56 | + - name: Commit and push wiki changes |
| 57 | + working-directory: wiki |
| 58 | + run: | |
| 59 | + git config user.name "github-actions[bot]" |
| 60 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 61 | + git add . |
| 62 | + if git diff --cached --quiet; then |
| 63 | + echo "No wiki changes to push" |
| 64 | + exit 0 |
| 65 | + fi |
| 66 | + git commit -m "docs: sync wiki from AstrBot-docs" |
| 67 | + git push |
0 commit comments