Skip to content

[docs] update docs.yml and docs workflow to support versioning #431

[docs] update docs.yml and docs workflow to support versioning

[docs] update docs.yml and docs workflow to support versioning #431

Workflow file for this run

name: Docs
#This workflow automates updating the dev version of the documentation website and the deployment of new versions of the document website.
on:
pull_request:
paths:
- "docs/mkdocs.yml"
# Publish docs weekly
schedule:
- cron: '0 9 * * 1'
workflow_dispatch:
inputs:
testing:
type: boolean
description: Is this a test run that will be built into gamma account?
default: false
required: false
version-number:
type: string
description: What is the new version number (ex. v0.28.0) for the website? If updating dev, leave this blank.
default: master
required: false
permissions:
id-token: write
contents: read
jobs:
documentation:
runs-on: ubuntu-latest
steps:
#Phase I: Set-up
#This phase sets up all of the necessary dependencies. This includes installing Java, Python, and adding the tools used to build the documentation website.
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: 17
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install Python Dependencies
run: pip3 install nbconvert mkdocs==1.4.3 mkdocs-exclude mknotebooks mkdocs-material jupyter Pygments Markdown mike
- name: Install CN fonts
run: sudo apt-get update && sudo apt-get install fonts-arphic-uming
- name: Cache IJava Kernel
id: ijava-cache
uses: actions/cache@v4
with:
path: ~/.local/share/jupyter/kernels/java
key: ${{ runner.os }}-ijava-kernel
- name: Install IJava kernel
if: steps.ijava-cache.outputs.cache-hit != 'true'
run: |
git clone https://github.com/frankfliu/IJava.git
cd IJava/
./gradlew installKernel
#Phase II: Consolidate the Source Files
#This phase consolidates all of the source files (i.e. Markdown files and Jupyter Notebooks) that are converted into the html files that form the documenetation website.
#These files are split across the DJL, DJL-Demo, and DJL-Serving Repository. They need to be consolidated locallay and inaccordance with paths specified in the mkdocs.yml file in djl/docs.
- name: Create website directory
run: |
cd /home/runner/work/djl
mkdir site
- name: Set-up Git Config
run: |
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Checkout DJL Repo
uses: actions/checkout@v4
with:
ref: ${{github.event.version-number}}
#This step is necessary because the index.html file in djl/index.html overwrites the index.html file Mike create for the landing page
#This is problematic because this index.html corresponds to the djl website rather than the docs website.
- name: Delete index.html
run: |
rm -f index.html
shell: bash
- name: Checkout DJL-Serving
uses: actions/checkout@v4
with:
repository: 'deepjavalibrary/djl-serving'
ref: ${{ github.event.inputs.version-number || 'master' }}
path: docs/serving
- name: Checkout DJL-Demo
uses: actions/checkout@v4
with:
repository: 'deepjavalibrary/djl-demo'
ref: ${{ github.event.inputs.version-number || 'master' }}
path: docs/demos
- name: Add mybinder link
run: |
python3 tools/scripts/add_online_runner.py
- name: run Notebooks
run: |
cd docs/demos/jupyter
bash test_notebook.sh
#Phase III: Retrive Current Website
#This phase handles authentication with AWS then retrieves the current version of the website that is stored in S3. The key pieces are the index.html and versions.json which serve as the landing page and the tracker of previous versions.
#Potential Improvement: See if mike still works if only downloading the index.html file and versions.json rather than the entire previous website.
- name: Configure AWS Test Credentials
if: ${{ github.event.inputs.testing == 'true' }}
uses: aws-actions/configure-aws-credentials@v4
with:
audience: sts.amazonaws.com
aws-region: us-east-1
role-to-assume: arn:aws:iam::185921645874:role/UpdateWebsite
role-session-name: UpdateWebsite
- name: Configure Deployment AWS Credentials
if: ${{ github.event_name != 'pull_request' && github.event.inputs.testing != 'true' }}
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2
- name: Sync gh-pages
env:
TESTING: ${{ github.event.inputs.testing }}
run: |
git checkout -b docs-branch
cd /home/runner/work/djl/djl/docs
git branch gh-pages
mike delete --all
git checkout gh-pages
cd ..
if [ "$TESTING" = 'true' ]; then
echo "Attempting sync"
aws s3 cp s3://updated-documentation-website/website/ ./ --recursive
else
aws s3 cp s3://djl-ai/documentation/nightly ./ --recursive
fi
git add .
git commit -m "Synced gh-pages with S3"
git checkout docs-branch
shell: bash
# Phase IV: Build New Website
#This phase invokes mike to build the new website. How it invokes mike depends on the parameters passed when the work flow is run. The default behavior is to update the dev version of the website.
- name: build docs
env:
VERSION_NUMBER: ${{ github.event.inputs.version-number }}
run: |
cd /home/runner/work/djl/djl
cd docs
export DJL_DISABLE_PROGRESS_BAR=true
if [ "$VERSION_NUMBER" != "master" ]; then
echo "deploying $VERSION_NUMBER"
mike deploy $VERSION_NUMBER
mike set-default $VERSION_NUMBER
else
mike deploy dev
mike set-default dev
fi
git branch
shell: bash
# Phase V: Deploy Website
#This phase deploys the website to the S3 Bucket. If this is a test, the website is uploaded to Gamma. Otherwise it is uploaded to produciton.
- name: Copy files to S3 with the AWS CLI
if: github.event_name != 'pull_request'
env:
TESTING: ${{ github.event.inputs.testing }}
run: |
cd /home/runner/work/djl/djl
git checkout gh-pages
if [ -d ./docs ]; then
rm -rf ./docs
fi
git branch
pwd
ls
if [ "$TESTING" = "true" ]; then
echo "TEST SYNC"
aws s3 sync . s3://updated-documentation-website/website/ --exclude ".*" --delete
else
echo "REAL SYNC"
aws s3 sync . s3://djl-ai/documentation/nightly --exclude ".*" --delete
aws cloudfront create-invalidation --distribution-id E733IIDCG0G5U --paths "/*"
fi
shell: bash