fix #4
Workflow file for this run
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: publish | |
on: | |
push: | |
branches: [ main, preview, feature/modernize-to-2025-standards ] | |
workflow_dispatch: | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
concurrency: | |
group: "pages" | |
cancel-in-progress: false | |
jobs: | |
publish: | |
runs-on: html_publisher | |
environment: | |
name: ${{ github.ref_name == 'main' && 'github-pages' || 'preview' }} | |
url: ${{ steps.deployment.outputs.page_url }} | |
steps: | |
- name: Checkout project | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.11" | |
- name: Install dependencies | |
run: | | |
pip install --upgrade pip | |
pip install nbconvert jupyter-book sphinx markdown | |
- name: Convert notebooks to HTML | |
run: | | |
mkdir -p site | |
# Convert .ipynb notebooks to HTML with code visible | |
for notebook in notebooks/*.ipynb; do | |
if [ -f "$notebook" ]; then | |
jupyter nbconvert "$notebook" --to html --output-dir site --template classic --HTMLExporter.theme=light | |
fi | |
done | |
# Convert .py Databricks notebooks to HTML | |
chmod +x .github/scripts/convert_notebooks.py | |
python3 .github/scripts/convert_notebooks.py | |
# Create simple index page | |
python3 << 'EOF' | |
import os | |
import markdown | |
# Read README.md | |
readme_content = "" | |
if os.path.exists('README.md'): | |
with open('README.md', 'r') as f: | |
readme_content = markdown.markdown(f.read()) | |
# Get repository name and format title | |
repo_name = os.environ.get('GITHUB_REPOSITORY', '').split('/')[-1] | |
title = ' '.join(word.capitalize() for word in repo_name.split('-')) + ' Accelerator' | |
# Find notebook files (.py and .ipynb) | |
notebook_files = [] | |
if os.path.exists('site'): | |
for f in os.listdir('site'): | |
if f.endswith('.html') and f != 'index.html': | |
notebook_files.append(f[:-5]) # Remove .html | |
# Create index.html | |
html = f'''<!DOCTYPE html> | |
<html> | |
<head> | |
<title>{title}</title> | |
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600&display=swap" rel="stylesheet"> | |
<style> | |
body {{ font-family: 'DM Sans', sans-serif; margin: 0; padding: 0; background-color: #f5f5f5; }} | |
.header {{ background: #fff; padding: 20px; border-bottom: 1px solid #eee; display: flex; align-items: center; gap: 20px; position: fixed; top: 0; width: 100%; z-index: 1000; }} | |
.logo {{ height: 24px; }} | |
.title {{ font-size: 24px; font-weight: 600; flex: 1; text-align: center; }} | |
.github-link {{ background: #f5f5f5; padding: 8px 16px; border-radius: 6px; text-decoration: none; color: #333; }} | |
.main-container {{ display: flex; margin-top: 80px; min-height: calc(100vh - 80px); }} | |
.sidebar {{ width: 250px; background: #f8f9fa; padding: 20px; position: fixed; left: 0; top: 80px; height: calc(100vh - 80px); overflow-y: auto; }} | |
.content {{ flex: 1; padding: 20px; margin-left: 250px; }} | |
.content-container {{ background: #fff; padding: 40px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); margin: 20px; font-size: 14px; line-height: 1.6; }} | |
.nav-link {{ display: block; padding: 8px 12px; margin: 4px 0; text-decoration: none; color: #333; border-radius: 4px; }} | |
.nav-link:hover {{ background: #e9ecef; }} | |
.nav-link.active {{ background: #007bff; color: white; }} | |
/* Match nbconvert styling */ | |
.content-container h1 {{ color: #1F2937; font-size: 28px; margin-bottom: 20px; }} | |
.content-container h2 {{ color: #1F2937; font-size: 22px; margin-top: 30px; margin-bottom: 15px; }} | |
.content-container h3 {{ color: #1F2937; font-size: 18px; margin-top: 25px; margin-bottom: 12px; }} | |
.content-container p {{ margin-bottom: 15px; color: #374151; }} | |
.content-container code {{ background: #f8f9fa; padding: 2px 6px; border-radius: 4px; font-family: 'Monaco', 'Consolas', monospace; color: #e91e63; }} | |
.content-container pre {{ background: #f8f9fa; padding: 15px; border-radius: 6px; overflow-x: auto; border: 1px solid #e5e7eb; }} | |
.content-container ul, .content-container ol {{ margin-bottom: 15px; padding-left: 25px; }} | |
.content-container li {{ margin-bottom: 8px; }} | |
.content-container a {{ color: #2563eb; text-decoration: none; }} | |
.content-container a:hover {{ text-decoration: underline; }} | |
</style> | |
</head> | |
<body> | |
<div class="header"> | |
<img src="https://databricks-prod-cloudfront.cloud.databricks.com/static/ddd080df888c63d3c68438635badd32f0c91e40f31fe8fa2ed73da63df3598e3/media/databricks.a424ad6e.svg" class="logo" alt="Databricks"> | |
<div class="title">{title}</div> | |
<a href="{os.environ.get('GITHUB_SERVER_URL', '')}/{os.environ.get('GITHUB_REPOSITORY', '')}" class="github-link">View Full Project Code on GitHub</a> | |
</div> | |
<div class="main-container"> | |
<div class="sidebar"> | |
<h3>📚 Notebooks</h3> | |
<a href="index.html" class="nav-link active">Home</a> | |
''' | |
# Add notebook links - sorted for consistency | |
for notebook in sorted(notebook_files): | |
if notebook != 'index': | |
html += f' <a href="{notebook}.html" class="nav-link">{notebook}</a>\n' | |
html += f''' | |
</div> | |
<div class="content"> | |
<div class="content-container"> | |
{readme_content} | |
</div> | |
</div> | |
</div> | |
</body> | |
</html>''' | |
with open('site/index.html', 'w') as f: | |
f.write(html) | |
# Add sidebar to each notebook | |
for notebook in notebook_files: | |
if notebook != 'index': | |
with open(f'site/{notebook}.html', 'r') as f: | |
original_content = f.read() | |
# Extract body content from nbconvert output | |
import re | |
body_match = re.search(r'<body[^>]*>(.*?)</body>', original_content, re.DOTALL) | |
if body_match: | |
notebook_body = body_match.group(1) | |
else: | |
notebook_body = original_content | |
# Extract head content (styles, etc) from nbconvert output | |
head_match = re.search(r'<head[^>]*>(.*?)</head>', original_content, re.DOTALL) | |
if head_match: | |
notebook_head = head_match.group(1) | |
else: | |
notebook_head = '' | |
# Create wrapped notebook with sidebar and original nbconvert styling | |
wrapped = f'''<!DOCTYPE html> | |
<html> | |
<head> | |
<title>{notebook} - {title}</title> | |
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600&display=swap" rel="stylesheet"> | |
{notebook_head} | |
<style> | |
body {{ font-family: 'DM Sans', sans-serif; margin: 0; padding: 0; background-color: #f5f5f5; }} | |
.header {{ background: #fff; padding: 20px; border-bottom: 1px solid #eee; display: flex; align-items: center; gap: 20px; position: fixed; top: 0; width: 100%; z-index: 1000; }} | |
.logo {{ height: 24px; }} | |
.title {{ font-size: 24px; font-weight: 600; flex: 1; text-align: center; }} | |
.github-link {{ background: #f5f5f5; padding: 8px 16px; border-radius: 6px; text-decoration: none; color: #333; }} | |
.main-container {{ display: flex; margin-top: 80px; min-height: calc(100vh - 80px); }} | |
.sidebar {{ width: 250px; background: #f8f9fa; padding: 20px; position: fixed; left: 0; top: 80px; height: calc(100vh - 80px); overflow-y: auto; }} | |
.content {{ flex: 1; padding: 20px; margin-left: 250px; max-width: calc(100% - 250px); }} | |
.nav-link {{ display: block; padding: 8px 12px; margin: 4px 0; text-decoration: none; color: #333; border-radius: 4px; }} | |
.nav-link:hover {{ background: #e9ecef; }} | |
.nav-link.active {{ background: #007bff; color: white; }} | |
/* Ensure nbconvert styles work properly and match notebook styling */ | |
.content code, .content pre {{ font-family: 'Monaco', 'Consolas', monospace; color: #1F2937; }} | |
.content .container {{ max-width: none; }} | |
/* Make notebook content have same white container style as index */ | |
.notebook-container {{ background: #fff; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); margin: 20px; padding: 40px; }} | |
</style> | |
</head> | |
<body> | |
<div class="header"> | |
<img src="https://databricks-prod-cloudfront.cloud.databricks.com/static/ddd080df888c63d3c68438635badd32f0c91e40f31fe8fa2ed73da63df3598e3/media/databricks.a424ad6e.svg" class="logo" alt="Databricks"> | |
<div class="title">{title}</div> | |
<a href="{os.environ.get('GITHUB_SERVER_URL', '')}/{os.environ.get('GITHUB_REPOSITORY', '')}" class="github-link">View Full Project Code on GitHub</a> | |
</div> | |
<div class="main-container"> | |
<div class="sidebar"> | |
<h3>📚 Notebooks</h3> | |
<a href="index.html" class="nav-link">Home</a> | |
''' | |
# Add notebook links with active state - ensure consistency | |
for nb in sorted(notebook_files): | |
if nb != 'index': | |
active = 'active' if nb == notebook else '' | |
wrapped += f' <a href="{nb}.html" class="nav-link {active}">{nb}</a>\n' | |
wrapped += f''' | |
</div> | |
<div class="content"> | |
<div class="notebook-container"> | |
{notebook_body} | |
</div> | |
</div> | |
</div> | |
</body> | |
</html>''' | |
with open(f'site/{notebook}.html', 'w') as f: | |
f.write(wrapped) | |
EOF | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: 'site' | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |