Add built-in Chat feature and Slack integration documentation #80
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: Deploy Documentation | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| branch: | |
| description: 'Branch to deploy as preview' | |
| required: false | |
| type: string | |
| permissions: | |
| contents: write # Needed to push to gh-pages branch | |
| pull-requests: write # Needed to comment on PRs | |
| concurrency: | |
| group: "pages-${{ github.ref_name }}" | |
| cancel-in-progress: true | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.x' | |
| - name: Install dependencies | |
| run: pip install -r requirements.txt | |
| - name: Determine deployment type | |
| id: deploy-type | |
| run: | | |
| if [[ "${{ github.ref_name }}" == "main" ]]; then | |
| echo "type=main" >> $GITHUB_OUTPUT | |
| echo "preview_path=" >> $GITHUB_OUTPUT | |
| echo "destination_dir=." >> $GITHUB_OUTPUT | |
| else | |
| # Sanitize branch name for folder (replace non-alphanumeric with -) | |
| BRANCH_NAME="${{ github.ref_name }}" | |
| SAFE_NAME=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9-]/-/g') | |
| echo "type=preview" >> $GITHUB_OUTPUT | |
| echo "preview_path=preview/${SAFE_NAME}" >> $GITHUB_OUTPUT | |
| echo "destination_dir=preview/${SAFE_NAME}" >> $GITHUB_OUTPUT | |
| echo "branch_name=${BRANCH_NAME}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Build site | |
| run: mkdocs build | |
| - name: Deploy to GitHub Pages (main) | |
| if: github.ref_name == 'main' | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./site | |
| keep_files: true # Keep preview folders when deploying main | |
| - name: Deploy to GitHub Pages (preview) | |
| if: github.ref_name != 'main' | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./site | |
| destination_dir: ${{ steps.deploy-type.outputs.destination_dir }} | |
| keep_files: true # Keep other previews and main site | |
| - name: Output deployment URL | |
| run: | | |
| BASE_URL="https://opentrace.github.io/docs" | |
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
| PREVIEW_PATH="${{ steps.deploy-type.outputs.preview_path }}" | |
| echo "## Preview deployed to: ${BASE_URL}/${PREVIEW_PATH}/" >> $GITHUB_STEP_SUMMARY | |
| elif [[ "${{ steps.deploy-type.outputs.type }}" == "main" ]]; then | |
| echo "## Deployed to: ${BASE_URL}" >> $GITHUB_STEP_SUMMARY | |
| else | |
| PREVIEW_PATH="${{ steps.deploy-type.outputs.preview_path }}" | |
| echo "## Preview deployed to: ${BASE_URL}/${PREVIEW_PATH}/" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Comment on PR with preview link | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const previewPath = '${{ steps.deploy-type.outputs.preview_path }}'; | |
| const previewUrl = `https://opentrace.github.io/docs/${previewPath}/`; | |
| const marker = '<!-- docs-preview-comment -->'; | |
| const body = `${marker}\n📚 **Documentation Preview**\n\nPreview deployed to: ${previewUrl}`; | |
| // Find existing comment | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| }); | |
| const existing = comments.find(c => c.body.includes(marker)); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existing.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body, | |
| }); | |
| } |