Skip to content

Add dev doc page for pull requests #129

Add dev doc page for pull requests

Add dev doc page for pull requests #129

Workflow file for this run

name: 'Build doc page for artifact'
on:
pull_request:
branches: [master]
types: [ opened, synchronize, closed ]
permissions:
pull-requests: write
jobs:
create_docs_comment:
name: Create the docs comment on new pull requests
runs-on: ubuntu-latest
if: github.event.action == 'opened'
env:
branch_name: ${{ github.event.pull_request.head.ref }}
steps:
- name: Add or update comment
uses: peter-evans/create-or-update-comment@v4
env:
url: 'http://flairNLP.github.io/flair-dev-docs/${{ env.branch_name }}/'
with:
issue-number: ${{ github.event.pull_request.number }}
body: 'The docs of this branch will be visible [here](${{ env.url }})'
edit-mode: replace
build_docs:
name: Build the docs using Sphinx and publish as artifact
runs-on: ubuntu-latest
if: github.event.action != 'closed'
env:
python-version: 3.9
branch_name: ${{ github.event.pull_request.head.ref }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: setup python ${{ env.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.python-version }}
- name: Install Torch cpu
run: pip install torch --index-url https://download.pytorch.org/whl/cpu
- name: Install Flair dependencies
run: pip install -e .
- name: Install unittest dependencies
run: pip install -r requirements-dev.txt
- name: Install doc dependencies
run: pip install -r docs/requirements.txt
- name: Change config to current branch
run: |
sed -i 's/^smv_branch_whitelist = r"^master$"/smv_branch_whitelist = r"^${{ env.branch_name }}$"/' docs/conf.py
sed -i 's/^smv_tag_whitelist = r"^v\d+\.\d+\.\d+$"/smv_tag_whitelist = "^$"/' docs/conf.py
cat docs/conf.py
- name: Fetch branch
run: git fetch --depth 1
- name: Build docs
run: |
sphinx-multiversion docs doc_build/
- name: Publish dev website
uses: peaceiris/actions-gh-pages@v4
with:
personal_token: ${{ secrets.FLAIR_DEV_DOCS_TOKEN }}
external_repository: 'flairNLP/flair-dev-docs'
destination_dir: './${{ env.branch_name }}'
publish_branch: main
allow_empty_commit: true
publish_dir: './doc_build/${{ env.branch_name }}'
disable_nojekyll: true
user_name: flair-docs-automation
user_email: actions@github.com
- name: Archive website results
uses: actions/upload-artifact@v4
with:
name: website
path: doc_build
cleanup:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
env:
branch_name: ${{ github.event.pull_request.head.ref }}
steps:
- name: Find existing PR comment
id: find-comment
uses: peter-evans/find-comment@v3
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: "The docs will be available at"
- name: Delete comment
if: steps.find-comment.outputs.comment-id != ''
uses: detomarco/delete-comments@1.1.0
with:
comment-id: ${{ needs.find-existing-comment.outputs.comment-id }}
- name: Checkout target repository
uses: actions/checkout@v4
with:
repository: flairNLP/flair-dev-docs
token: ${{ secrets.FLAIR_DEV_DOCS_TOKEN }}
- name: Remove folder
run: rm -rf './${{ env.branch_name }}'
- name: Commit and push changes
run: |
git config --global user.name "flair-docs-automation"
git config --global user.email "actions@github.com"
git add .
git commit -m "remove: ${{ github.repository }}@${{ github.sha }}"
git push