|
| 1 | +name: Sync docs with Docusaurus |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + paths: |
| 9 | + - "docs/pydoc/config_docusaurus/**" |
| 10 | + - "haystack/**" |
| 11 | + - ".github/workflows/docusaurus_sync.yml" |
| 12 | + |
| 13 | +env: |
| 14 | + HATCH_VERSION: "1.14.1" |
| 15 | + PYTHON_VERSION: "3.9" |
| 16 | + DOCS_REPO: "deepset-ai/haystack-docs" |
| 17 | + DOCS_REPO_PATH: "docs/api/haystack-api" |
| 18 | + |
| 19 | +jobs: |
| 20 | + sync: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + permissions: |
| 23 | + contents: write |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout Haystack repo |
| 27 | + uses: actions/checkout@v4 |
| 28 | + |
| 29 | + - name: Set up Python |
| 30 | + uses: actions/setup-python@v5 |
| 31 | + with: |
| 32 | + python-version: "${{ env.PYTHON_VERSION }}" |
| 33 | + |
| 34 | + - name: Install Hatch |
| 35 | + run: pip install hatch==${{ env.HATCH_VERSION }} |
| 36 | + |
| 37 | + - name: Generate API docs for Docusaurus |
| 38 | + # This command simply runs ./.github/utils/pydoc-markdown.sh with a specific config path |
| 39 | + run: hatch run readme:sync "../config_docusaurus/*" |
| 40 | + |
| 41 | + - name: Checkout Docusaurus repo |
| 42 | + uses: actions/checkout@v4 |
| 43 | + with: |
| 44 | + repository: ${{ env.DOCS_REPO }} |
| 45 | + token: ${{ secrets.HAYSTACK_BOT_TOKEN }} |
| 46 | + path: haystack-docs |
| 47 | + |
| 48 | + - name: Sync generated docs to Docusaurus repo |
| 49 | + run: | |
| 50 | + SOURCE_PATH="docs/pydoc/temp" |
| 51 | + DEST_PATH="haystack-docs/${{ env.DOCS_REPO_PATH }}" |
| 52 | +
|
| 53 | + echo "Syncing from $SOURCE_PATH to $DEST_PATH" |
| 54 | + mkdir -p $DEST_PATH |
| 55 | + # Using rsync to copy files. This will also remove files in dest that are no longer in source. |
| 56 | + rsync -av --delete --exclude='.git/' "$SOURCE_PATH/" "$DEST_PATH/" |
| 57 | +
|
| 58 | + - name: Commit and push changes |
| 59 | + env: |
| 60 | + GITHUB_TOKEN: ${{ secrets.HAYSTACK_BOT_TOKEN }} |
| 61 | + run: | |
| 62 | + git config --global user.name "github-actions[bot]" |
| 63 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 64 | +
|
| 65 | + cd haystack-docs |
| 66 | +
|
| 67 | + if [[ -n $(git status -s) ]]; then |
| 68 | + echo "Syncing docs with Docusaurus..." |
| 69 | + git add . |
| 70 | + git commit -m "docs: Sync Haystack API reference" |
| 71 | + git push |
| 72 | + else |
| 73 | + echo "No changes to sync with Docusaurus." |
| 74 | + fi |
0 commit comments