[docs] update docs.yml and docs workflow to support versioning #428
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: 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 | |
is-new-version: | |
type: boolean | |
description: Are you deploying new version? If so, enter the new version number (ex. 28.0). If not, skip the rest of the parameters. | |
default: false | |
required: true | |
version-number: | |
type: string | |
description: What is the new version number for the website? | |
default: dev | |
required: false | |
djl-tag: | |
type: string | |
description: The commit SHA (e.g. 6b642e1) for the tag of the version of djl. | |
default: 'DJL SHA' | |
required: false | |
djl-serving-tag: | |
type: string | |
description: The commit SHA (e.g. 6b642e1) for the version of djl-serving. | |
default: 'DJL Serving SHA' | |
required: false | |
djl-demo-tag: | |
description: The commit SHA (e.g. 6b642e1) for the version of djl-demo. | |
default: 'DJL Demo SHA' | |
required: false | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
documentation: | |
# Change line below | |
if: github.repository == 'Varun-Dutta/djl' | |
runs-on: ubuntu-latest | |
steps: | |
#Phase I: Set-up | |
#This phase sets up all of the necessary dependencies. This includes authenticating the workflow, installing Java and Python, and adding the tools used to build the documentation 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: 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.inputs.is-new-version == 'true' && github.event.inputs.djl-tag || 'master' }} | |
#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 | |
git add -u | |
git commit -m "Removed index.html" || echo "No changes to commit" | |
shell: bash | |
- name: Clone DJL-Serving | |
env: | |
IS_NEW_VERSION: ${{ github.event.inputs.is-new-version }} | |
DJL_SERVING_TAG: ${{ github.event.inputs.djl-serving-tag }} | |
run: | | |
cd /home/runner/work/djl/djl/docs | |
git clone https://github.com/deepjavalibrary/djl-serving.git serving | |
cd serving | |
if [ "$IS_NEW_VERSION" = "true" ]; then | |
git checkout "$DJL_SERVING_TAG" | |
fi | |
shell: bash | |
- name: Clone DJL-Demo | |
env: | |
IS_NEW_VERSION: ${{ github.event.inputs.is-new-version }} | |
DJL_DEMO_TAG: ${{ github.event.inputs.djl-demo-tag }} | |
run: | | |
cd /home/runner/work/djl/djl/docs | |
git clone https://github.com/deepjavalibrary/djl-demo.git demos | |
cd demos | |
if [ "$IS_NEW_VERSION" = "true" ]; then | |
git checkout "$DJL_DEMO_TAG" | |
fi | |
shell: bash | |
- 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 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: 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 }} | |
IS_NEW_VERSION: ${{ github.event.inputs.is-new-version }} | |
run: | | |
cd /home/runner/work/djl/djl | |
cd docs | |
export DJL_DISABLE_PROGRESS_BAR=true | |
if [ "$IS_NEW_VERSION" = "true" ]; 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 | |