|
| 1 | +name: Publish Mintlify Docs to GitHub Pages |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - '**' # Run on all branches |
| 7 | + paths: |
| 8 | + - 'docs/**' |
| 9 | + - '.github/workflows/publish-docs.yml' |
| 10 | + workflow_dispatch: # Allow manual trigger |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + pages: write |
| 15 | + id-token: write |
| 16 | + |
| 17 | +# Allow only one concurrent deployment per branch |
| 18 | +concurrency: |
| 19 | + group: pages-${{ github.ref_name }} |
| 20 | + cancel-in-progress: true |
| 21 | + |
| 22 | +jobs: |
| 23 | + build: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@v4 |
| 28 | + |
| 29 | + - name: Setup Node.js |
| 30 | + uses: actions/setup-node@v4 |
| 31 | + with: |
| 32 | + node-version: '20' |
| 33 | + |
| 34 | + - name: Install Mintlify |
| 35 | + run: npm install -g mintlify |
| 36 | + |
| 37 | + - name: Build docs |
| 38 | + run: | |
| 39 | + cd docs |
| 40 | + mintlify build |
| 41 | +
|
| 42 | + - name: Get branch name |
| 43 | + id: branch |
| 44 | + run: | |
| 45 | + # Get the branch name and sanitize it for use in URL |
| 46 | + BRANCH_NAME="${GITHUB_REF#refs/heads/}" |
| 47 | + # Replace slashes with dashes for subdirectory name |
| 48 | + SANITIZED_BRANCH=$(echo "$BRANCH_NAME" | sed 's/\//-/g') |
| 49 | + echo "name=$SANITIZED_BRANCH" >> $GITHUB_OUTPUT |
| 50 | + echo "Building docs for branch: $BRANCH_NAME (subdirectory: $SANITIZED_BRANCH)" |
| 51 | +
|
| 52 | + - name: Prepare deployment directory |
| 53 | + run: | |
| 54 | + mkdir -p _site/${{ steps.branch.outputs.name }} |
| 55 | + cp -r docs/_site/* _site/${{ steps.branch.outputs.name }}/ |
| 56 | + |
| 57 | + # Create/update index.html with branch listing |
| 58 | + cat > _site/index.html <<EOF |
| 59 | + <!DOCTYPE html> |
| 60 | + <html> |
| 61 | + <head> |
| 62 | + <title>TestDriver Documentation</title> |
| 63 | + <style> |
| 64 | + body { font-family: system-ui, -apple-system, sans-serif; max-width: 800px; margin: 50px auto; padding: 20px; } |
| 65 | + h1 { color: #152a65; } |
| 66 | + ul { list-style: none; padding: 0; } |
| 67 | + li { margin: 10px 0; } |
| 68 | + a { color: #b3d334; text-decoration: none; font-size: 18px; } |
| 69 | + a:hover { text-decoration: underline; } |
| 70 | + </style> |
| 71 | + </head> |
| 72 | + <body> |
| 73 | + <h1>TestDriver Documentation</h1> |
| 74 | + <p>Available documentation versions:</p> |
| 75 | + <ul> |
| 76 | + <li><a href="${{ steps.branch.outputs.name }}/">${{ steps.branch.outputs.name }}</a></li> |
| 77 | + </ul> |
| 78 | + </body> |
| 79 | + </html> |
| 80 | + EOF |
| 81 | +
|
| 82 | + - name: Upload artifact |
| 83 | + uses: actions/upload-pages-artifact@v3 |
| 84 | + with: |
| 85 | + path: '_site' |
| 86 | + |
| 87 | + deploy: |
| 88 | + needs: build |
| 89 | + runs-on: ubuntu-latest |
| 90 | + environment: |
| 91 | + name: github-pages |
| 92 | + url: ${{ steps.deployment.outputs.page_url }} |
| 93 | + steps: |
| 94 | + - name: Deploy to GitHub Pages |
| 95 | + id: deployment |
| 96 | + uses: actions/deploy-pages@v4 |
| 97 | + |
| 98 | + - name: Output deployment URL |
| 99 | + run: | |
| 100 | + echo "Documentation deployed to: ${{ steps.deployment.outputs.page_url }}${{ needs.build.outputs.branch_name }}" |
0 commit comments