build-documentation #8
This file contains 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: build-documentation | |
on: | |
workflow_run: | |
workflows: [test-python-package] | |
types: | |
- completed | |
jobs: | |
build_docs: | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- name: Checkout code | |
uses: nschloe/action-cached-lfs-checkout@v1 | |
with: | |
ref: ${{ github.event.workflow_run.head_sha }} | |
- uses: actions/setup-python@v5 | |
name: Install Python | |
with: | |
python-version: '3.10' | |
- name: Install dependency | |
run: | | |
sudo apt-get install -y pandoc jq | |
sudo pip install --upgrade pip | |
pip install --user sphinx==7.* pydata-sphinx-theme==0.15.* pandoc nbsphinx \ | |
Pygments==2.16.* sphinx-autodoc-typehints myst-parser \ | |
markupsafe==2.1.* sphinx-plotly-directive | |
- name: Download wheel files from artifacts | |
id: download-artifact | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
workflow: test_python.yml | |
commit: ${{ github.event.workflow_run.head_sha }} | |
name: wheel-files | |
path: wheel_files | |
- name: Install wheel files | |
run: pip install --user wheel_files/*.whl | |
- name: Build doc | |
run: sphinx-build ${GITHUB_WORKSPACE}/docs _build/html | |
- name: Get SnapATAC2 version | |
id: get_version | |
run: | | |
VERSION_NUMBER=$(python -c "import snapatac2;print('.'.join(snapatac2.__version__.split('.')[:2]))") | |
echo $VERSION_NUMBER | |
echo "VERSION=$VERSION_NUMBER" >> $GITHUB_ENV | |
IS_DEV=$(python -c "import snapatac2;print('dev' in snapatac2.__version__)") | |
echo $IS_DEV | |
BRANCH_NAME=${{ github.event.workflow_run.head_branch }} | |
if [[ $IS_DEV == "True" && $BRANCH_NAME == "main" ]]; then | |
echo "DEPLOY_DEV=true" >> $GITHUB_ENV | |
elif [[ $BRANCH_NAME =~ ^v[0-9]+ || $BRANCH_NAME == "main" ]]; then | |
echo "DEPLOY_VERSION=true" >> $GITHUB_ENV | |
fi | |
- name: Deploy 🚀 | |
uses: JamesIves/github-pages-deploy-action@v4 | |
if: ${{ env.DEPLOY_DEV == 'true' }} | |
with: | |
single-commit: true | |
branch: gh-pages | |
folder: _build/html | |
clean: true | |
target-folder: /version/dev/ | |
- name: Deploy (version) 🚀 | |
uses: JamesIves/github-pages-deploy-action@v4 | |
if: ${{ env.DEPLOY_VERSION == 'true' }} | |
with: | |
single-commit: true | |
branch: gh-pages | |
folder: _build/html | |
clean: true | |
target-folder: /version/${{ env.VERSION }}/ | |
- name: Fetch JSON and Get Preferred Version | |
run: | | |
#JSON=$(cat ${GITHUB_WORKSPACE}/docs/_static/versions.json) | |
JSON=$(curl -s "https://raw.githubusercontent.com/kaizhang/SnapATAC2/main/docs/_static/versions.json") | |
VERSION=$(echo "$JSON" | jq -r '.[] | select(.preferred == true) | .version') | |
echo "PREFERRED_VERSION=$VERSION" >> $GITHUB_ENV | |
echo "Preferred version is $VERSION" | |
- name: Checkout code from gh-pages branch into folder | |
uses: actions/checkout@v2 | |
with: | |
ref: 'gh-pages' | |
path: 'gh-pages-folder' | |
- name: Deploy (preferred version) | |
uses: JamesIves/github-pages-deploy-action@v4 | |
with: | |
single-commit: true | |
branch: gh-pages | |
folder: gh-pages-folder/version/${{ env.PREFERRED_VERSION }} | |
clean: true | |
clean-exclude: version |