Generate PDF Documentation #28
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: Generate PDF Documentation | |
on: | |
pull_request: | |
branches: | |
- 'main' | |
- 'pdf-documentation' | |
workflow_dispatch: | |
inputs: | |
folder_path: | |
description: 'Path to the documentation folder' | |
required: true | |
default: './docs' | |
sidebar_path: | |
description: 'Path to the sidebar.js file' | |
required: true | |
default: './sidebars.js' | |
combined_md_file_path: | |
description: 'Path to the combined docs markdown file' | |
required: true | |
default: './combined_docs.md' | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
generate_docs: | |
runs-on: ubuntu-latest | |
outputs: | |
pdf_url: ${{ steps.s3_upload.outputs.s3_url }} # Output the S3 bucket URL where the generated PDF is stored | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' # Specify the Node.js version you need | |
- name: Install Python | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y python3 python3-pip | |
- name: Install LaTeX, Pandoc, and Required Packages | |
run: | | |
sudo apt-get install -y pandoc | |
sudo apt-get install texlive-latex-base | |
sudo apt-get install texlive-luatex | |
sudo apt-get install lmodern | |
sudo apt-get install texlive-fonts-recommended | |
sudo apt-get install texlive-fonts-extra | |
sudo apt-get install texlive-latex-extra | |
- name: Set environment variables | |
env: | |
FOLDER_PATH: ${{ github.event.inputs.folder_path || './docs' }} # For manual runs or PR body | |
SIDEBAR_PATH: ${{ github.event.inputs.sidebar_path || './sidebars.js' }} # For manual runs or PR body | |
COMBINED_DOC_PATH: ${{ github.event.inputs.combined_md_file_path || './combined_docs.md' }} # For manual runs or PR body | |
BRANCH_NAME: ${{ github.head_ref || github.ref }} | |
run: | | |
echo "FOLDER_PATH=${FOLDER_PATH}" >> $GITHUB_ENV | |
echo "SIDEBAR_PATH=${SIDEBAR_PATH}" >> $GITHUB_ENV | |
echo "COMBINED_DOC_PATH=${COMBINED_DOC_PATH}" >> $GITHUB_ENV | |
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV | |
# start new content 1 | |
# Fallback: Set the repository name as the documentation name if no title is found | |
- name: Set repository name as documentation name fallback | |
run: | # Extracts the repository name (everything after the slash in org/repo) | |
echo "REPO_NAME=$(echo $GITHUB_REPOSITORY | cut -d'/' -f2)" >> $GITHUB_ENV | |
# Extract documentation title and determine the version number dynamically | |
- name: Extract title and version | |
run: | | |
DOC_TITLE=$(node -p "require('./documentation/makersaurus.config.js').title || ''") | |
if [[ "${{ env.FOLDER_PATH }}" == "./docs" ]]; then | |
VERSION=$(node -p "require('./documentation/makersaurus.config.js').versions?.current?.label || '0.0.0'") | |
else | |
VERSION=$(basename "${{ env.FOLDER_PATH }}" | sed 's/version-//') | |
fi | |
SAFE_TITLE=$(echo "$DOC_TITLE" | tr ' ' '_' | tr -dc 'A-Za-z0-9._-') | |
echo "DOC_TITLE=${DOC_TITLE}" >> $GITHUB_ENV | |
echo "VERSION=${VERSION}" >> $GITHUB_ENV | |
echo "SAFE_TITLE=${SAFE_TITLE}" >> $GITHUB_ENV | |
# end new content 1 | |
# Download the script from another repository (replace with correct repo and script path) | |
- name: Download script and make it executable | |
run: | | |
curl -H "Authorization: bearer ${{ secrets.GH_ACTIONS_RUNNERS_H2O_OPS_TOKEN }}" -L -o ./documentation/generate_combined_md.py "https://raw.githubusercontent.com/h2oai/makersaurus/refs/heads/main/documentation/generate_combined_md.py" | |
curl -H "Authorization: bearer ${{ secrets.GH_ACTIONS_RUNNERS_H2O_OPS_TOKEN }}" -L -o ./documentation/generate_pdf_doc.py "https://raw.githubusercontent.com/h2oai/makersaurus/refs/heads/main/documentation/generate_pdf_doc.py" | |
curl -H "Authorization: bearer ${{ secrets.GH_ACTIONS_RUNNERS_H2O_OPS_TOKEN }}" -L -o ./documentation/parse_sidebar.js "https://raw.githubusercontent.com/h2oai/makersaurus/refs/heads/main/documentation/parse_sidebar.js" | |
chmod +x ./documentation/generate_combined_md.py | |
chmod +x ./documentation/generate_pdf_doc.py | |
chmod +x ./documentation/parse_sidebar.js | |
# start new content 2 | |
# Generate either a combined markdown file or a PDF depending on the branch | |
- name: Generate combined markdown or PDF | |
run: | | |
cd documentation | |
if [[ "${{ env.BRANCH_NAME }}" =~ ^refs/heads/pdf-documentation ]]; then | |
python3 generate_pdf_doc.py "${{ env.FOLDER_PATH }}" "${{ env.SIDEBAR_PATH }}" "${{ env.COMBINED_DOC_PATH }}" | |
else | |
python3 generate_combined_md.py "${{ env.FOLDER_PATH }}" "${{ env.SIDEBAR_PATH }}" | |
fi | |
# Rename the generated output files to include the documentation title and version | |
- name: Rename output files | |
run: | | |
cd documentation | |
if [[ -f documentation.pdf ]]; then | |
mv documentation.pdf "${{ env.SAFE_TITLE }}_${{ env.VERSION }}.pdf" | |
fi | |
if [[ -f combined_docs.md ]]; then | |
mv combined_docs.md "${{ env.SAFE_TITLE }}_${{ env.VERSION }}.md" | |
fi | |
# end new content 2 | |
- name: Upload generated documentation | |
uses: actions/upload-artifact@v4 | |
with: | |
name: documentation_artifacts | |
path: | | |
documentation/${{ env.SAFE_TITLE }}_${{ env.VERSION }}.md | |
documentation/${{ env.SAFE_TITLE }}_${{ env.VERSION }}.pdf | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: arn:aws:iam::905418351423:role/GitHub-OIDC-Role | |
role-session-name: h2o-llm-studio | |
aws-region: us-east-1 | |
- name: Publish documentation to S3 | |
id: s3_upload | |
run: | | |
if [[ "${{ env.BRANCH_NAME }}" =~ ^refs/heads/pdf-documentation ]]; then | |
aws s3 cp "documentation/${{ env.SAFE_TITLE }}_${{ env.VERSION }}.pdf" s3://pdf-documentation/h2o-llm-studio/ | |
S3_BUCKET="pdf-documentation" | |
S3_KEY="h2o-llm-studio/${{ env.SAFE_TITLE }}_${{ env.VERSION }}.pdf" | |
S3_URL="https://${S3_BUCKET}.s3.amazonaws.com/${S3_KEY}" | |
echo "s3_url=${S3_URL}" >> $GITHUB_OUTPUT | |
echo "PDF uploaded successfully to: ${S3_URL}" | |
else | |
echo "Skipping S3 upload - not on pdf-documentation branch" | |
fi | |
- name: Display PDF URL | |
if: steps.s3_upload.outputs.s3_url != '' | |
run: | | |
echo "PDF is available at: ${{ steps.s3_upload.outputs.s3_url }}" | |
echo "pdf_url=${{ steps.s3_upload.outputs.s3_url }}" >> $GITHUB_ENV | |