From 6e645e4aafa1534a54960754f12fa1a5f68dc222 Mon Sep 17 00:00:00 2001 From: yuejiaointel Date: Mon, 27 Oct 2025 17:10:13 -0700 Subject: [PATCH 1/2] feature: add dev doc logic --- .github/scripts/doc_release.sh | 148 ++++++++++++++++++----------- .github/workflows/docs-release.yml | 28 +++++- 2 files changed, 121 insertions(+), 55 deletions(-) diff --git a/.github/scripts/doc_release.sh b/.github/scripts/doc_release.sh index 883a0ebc8d..de6cbe1a2c 100644 --- a/.github/scripts/doc_release.sh +++ b/.github/scripts/doc_release.sh @@ -19,6 +19,21 @@ BUILD_DIR="doc/_build/scikit-learn-intelex" STORAGE_BRANCH="doc_archive" +# Parse command line arguments +IS_DEV_MODE=false +while [[ $# -gt 0 ]]; do + case $1 in + --dev) + IS_DEV_MODE=true + shift + ;; + *) + echo "Unknown option: $1" + exit 1 + ;; + esac +done + # Check if TEMP_DOC_FOLDER is set if [ -z "$TEMP_DOC_FOLDER" ]; then echo "::error::TEMP_DOC_FOLDER environment variable is not set!" @@ -53,24 +68,57 @@ sync_from_branch $STORAGE_BRANCH sync_from_branch "gh-pages" ##### Prepare new doc ##### -# Copy the new built version to $TEMP_DOC_FOLDER -mkdir -p $TEMP_DOC_FOLDER/$SHORT_DOC_VERSION -cp -R doc/_build/scikit-learn-intelex/$SHORT_DOC_VERSION/* $TEMP_DOC_FOLDER/$SHORT_DOC_VERSION/ - -# Update latest -rm -rf $TEMP_DOC_FOLDER/latest -mkdir -p $TEMP_DOC_FOLDER/latest -cp -R doc/_build/scikit-learn-intelex/$SHORT_DOC_VERSION/* $TEMP_DOC_FOLDER/latest/ +if [ "$IS_DEV_MODE" = true ]; then + # Dev mode: Build and update dev documentation + echo "Building dev documentation..." + + # Find the built documentation directory + BUILT_VERSION_DIR=$(find $BUILD_DIR -mindepth 1 -maxdepth 1 -type d | head -n 1) + if [ -z "$BUILT_VERSION_DIR" ]; then + echo "::error: No version directory found in build output!" + exit 1 + fi + + # Update dev folder + rm -rf $TEMP_DOC_FOLDER/dev + mkdir -p $TEMP_DOC_FOLDER/dev + cp -R $BUILT_VERSION_DIR/* $TEMP_DOC_FOLDER/dev/ +else + # Release mode: Copy from dev to create new release version + echo "Creating release documentation for version $SHORT_DOC_VERSION from dev..." + + if [ ! -d "$TEMP_DOC_FOLDER/dev" ]; then + echo "::error: Dev documentation not found! Cannot create release." + exit 1 + fi + + # Create versioned folder from dev + mkdir -p $TEMP_DOC_FOLDER/$SHORT_DOC_VERSION + cp -R $TEMP_DOC_FOLDER/dev/* $TEMP_DOC_FOLDER/$SHORT_DOC_VERSION/ + + # Update latest + rm -rf $TEMP_DOC_FOLDER/latest + mkdir -p $TEMP_DOC_FOLDER/latest + cp -R $TEMP_DOC_FOLDER/dev/* $TEMP_DOC_FOLDER/latest/ +fi -# Copy index.html -cp doc/_build/scikit-learn-intelex/index.html $TEMP_DOC_FOLDER/ +# Copy index.html if it exists +if [ -f "$BUILD_DIR/index.html" ]; then + cp $BUILD_DIR/index.html $TEMP_DOC_FOLDER/ +fi # Generate versions.json -mkdir -p $TEMP_DOC_FOLDER echo "[" > $TEMP_DOC_FOLDER/versions.json -# Add latest entry first -echo ' {"name": "latest", "version": "'$SHORT_DOC_VERSION'", "url": "/scikit-learn-intelex/latest/"},' >> $TEMP_DOC_FOLDER/versions.json -# Add all year.month folders +# Add dev entry if it exists +if [ -d "$TEMP_DOC_FOLDER/dev" ]; then + echo ' {"name": "dev (next release)", "version": "dev", "url": "/scikit-learn-intelex/dev/"},' >> $TEMP_DOC_FOLDER/versions.json +fi +# Add latest entry if it exists +if [ -d "$TEMP_DOC_FOLDER/latest" ]; then + LATEST_VERSION=$(find $TEMP_DOC_FOLDER -mindepth 1 -maxdepth 1 -type d -name "[0-9][0-9][0-9][0-9].[0-9]*" | sort -rV | head -n 1 | xargs basename 2>/dev/null || echo "latest") + echo ' {"name": "latest", "version": "'$LATEST_VERSION'", "url": "/scikit-learn-intelex/latest/"},' >> $TEMP_DOC_FOLDER/versions.json +fi +# Add all versioned folders for version in $(ls -d $TEMP_DOC_FOLDER/[0-9][0-9][0-9][0-9].[0-9]* 2>/dev/null || true); do version=$(basename "$version") echo ' {"name": "'$version'", "version": "'$version'", "url": "/scikit-learn-intelex/'$version'/"},' @@ -84,43 +132,37 @@ ls -la $TEMP_DOC_FOLDER/ cat $TEMP_DOC_FOLDER/versions.json git checkout -- .github/scripts/doc_release.sh -##### Archive to doc_archive branch ##### -echo "Archiving version $SHORT_DOC_VERSION to branch $STORAGE_BRANCH..." -git config user.name "github-actions[bot]" -git config user.email "github-actions[bot]@users.noreply.github.com" -CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) - -# Check if storage branch exists -if git ls-remote --heads origin "$STORAGE_BRANCH" | grep -q "$STORAGE_BRANCH"; then - echo "Storage branch exists, fetching it..." - git fetch origin $STORAGE_BRANCH - git checkout $STORAGE_BRANCH - - # Add only the new version directory - mkdir -p $SHORT_DOC_VERSION - rsync -av $TEMP_DOC_FOLDER/$SHORT_DOC_VERSION/ $SHORT_DOC_VERSION/ - git add $SHORT_DOC_VERSION - git commit -m "Add documentation for version $SHORT_DOC_VERSION" -else - echo "Creating new storage branch with all current versions..." - # Create an empty orphan branch - git checkout --orphan $STORAGE_BRANCH - git rm -rf . - - # Copy only version folders - for version_dir in $(find $TEMP_DOC_FOLDER -maxdepth 1 -type d -name "[0-9][0-9][0-9][0-9].[0-9]*" 2>/dev/null); do - version=$(basename "$version_dir") - mkdir -p $version - rsync -av "$version_dir/" $version/ - done - - # Git only add version folders - git add -- [0-9][0-9][0-9][0-9].[0-9]* - git commit -m "Initialize doc archive branch with all versions" -fi - -# Push changes -git push origin $STORAGE_BRANCH +##### Archive to doc_archive branch (release mode only) ##### +if [ "$IS_DEV_MODE" = false ]; then + echo "Archiving version $SHORT_DOC_VERSION to branch $STORAGE_BRANCH..." + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + + if git ls-remote --heads origin "$STORAGE_BRANCH" | grep -q "$STORAGE_BRANCH"; then + echo "Storage branch exists, fetching it..." + git fetch origin $STORAGE_BRANCH + git checkout $STORAGE_BRANCH + + mkdir -p $SHORT_DOC_VERSION + rsync -av $TEMP_DOC_FOLDER/$SHORT_DOC_VERSION/ $SHORT_DOC_VERSION/ + git add $SHORT_DOC_VERSION + git commit -m "Add documentation for version $SHORT_DOC_VERSION" + else + echo "Creating new storage branch..." + git checkout --orphan $STORAGE_BRANCH + git rm -rf . + + for version_dir in $(find $TEMP_DOC_FOLDER -maxdepth 1 -type d -name "[0-9][0-9][0-9][0-9].[0-9]*" 2>/dev/null); do + version=$(basename "$version_dir") + mkdir -p $version + rsync -av "$version_dir/" $version/ + done + + git add -- [0-9][0-9][0-9][0-9].[0-9]* + git commit -m "Initialize doc archive branch with all versions" + fi -# Return to original branch -git checkout $CURRENT_BRANCH \ No newline at end of file + git push origin $STORAGE_BRANCH + git checkout $CURRENT_BRANCH +fi \ No newline at end of file diff --git a/.github/workflows/docs-release.yml b/.github/workflows/docs-release.yml index 90001530a2..3ff5f9245d 100644 --- a/.github/workflows/docs-release.yml +++ b/.github/workflows/docs-release.yml @@ -19,6 +19,18 @@ on: push: tags: - '[0-9][0-9][0-9][0-9]\.[0-9][0-9]?\.[0-9]' # Trigger on tag pushes + pull_request: + # Trigger when PR is merged + types: [closed] + branches: + - main + paths: + - 'doc/**' + - 'sklearnex/**' + - 'daal4py/**' + - 'onedal/**' + - '.github/workflows/docs-release.yml' + - '.github/scripts/doc_release.sh' workflow_dispatch: inputs: doc_version: @@ -29,6 +41,8 @@ permissions: read-all jobs: build-docs: + # Skip if PR was closed without merging + if: github.event_name != 'pull_request' || github.event.pull_request.merged == true runs-on: ubuntu-24.04 permissions: contents: write @@ -59,9 +73,13 @@ jobs: if [ -n "${{ github.event.inputs.doc_version }}" ]; then export DOC_VERSION="${{ github.event.inputs.doc_version }}" echo "Manual dispatch detected with version: $DOC_VERSION" - else + elif [ "${{ github.ref_type }}" = "tag" ]; then export DOC_VERSION="${GITHUB_REF#refs/tags/}" echo "Tag trigger detected with version: $DOC_VERSION" + else + echo "Push to main branch detected, building dev documentation" + echo "IS_DEV_BUILD=true" >> $GITHUB_ENV + exit 0 fi # Error out if cannot find version if [ -z "$DOC_VERSION" ]; then @@ -72,7 +90,9 @@ jobs: # export env var in other files echo "DOC_VERSION=$DOC_VERSION" >> $GITHUB_ENV echo "SHORT_DOC_VERSION=$SHORT_DOC_VERSION" >> $GITHUB_ENV + echo "IS_DEV_BUILD=false" >> $GITHUB_ENV - name: Checkout release branch + if: env.IS_DEV_BUILD == 'false' run: | if git checkout $DOC_VERSION 2>/dev/null; then echo "Successfully checked out tag $DOC_VERSION." @@ -103,7 +123,11 @@ jobs: - name: Prepare Documentation for Deployment run: | chmod +x .github/scripts/doc_release.sh - ./.github/scripts/doc_release.sh + if [ "${{ env.IS_DEV_BUILD }}" = "true" ]; then + ./.github/scripts/doc_release.sh --dev + else + ./.github/scripts/doc_release.sh + fi - name: Upload artifact for GitHub Pages uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0 From dc0f603126af66cd21ac99eafe8caff80af24944 Mon Sep 17 00:00:00 2001 From: yuejiaointel Date: Tue, 28 Oct 2025 23:05:39 -0700 Subject: [PATCH 2/2] fix: add dev archive --- .github/scripts/doc_release.sh | 65 +++++++++++++++++++++--------- .github/workflows/docs-release.yml | 3 ++ doc/build-doc.sh | 2 +- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/.github/scripts/doc_release.sh b/.github/scripts/doc_release.sh index de6cbe1a2c..1fafd6d0df 100644 --- a/.github/scripts/doc_release.sh +++ b/.github/scripts/doc_release.sh @@ -40,12 +40,6 @@ if [ -z "$TEMP_DOC_FOLDER" ]; then exit 1 fi -# Ensure the build directory exists -if [ ! -d "$BUILD_DIR" ]; then - echo "::error: Documentation build directory not found!" - exit 1 -fi - rm -rf $TEMP_DOC_FOLDER mkdir -p $TEMP_DOC_FOLDER @@ -72,17 +66,21 @@ if [ "$IS_DEV_MODE" = true ]; then # Dev mode: Build and update dev documentation echo "Building dev documentation..." - # Find the built documentation directory - BUILT_VERSION_DIR=$(find $BUILD_DIR -mindepth 1 -maxdepth 1 -type d | head -n 1) - if [ -z "$BUILT_VERSION_DIR" ]; then - echo "::error: No version directory found in build output!" + # Ensure the build directory exists + if [ ! -d "$BUILD_DIR" ]; then + echo "::error: Documentation build directory not found!" + exit 1 + fi + + # Copy dev documentation from build directory + if [ ! -d "$BUILD_DIR/dev" ]; then + echo "::error: Dev documentation not found in build directory!" exit 1 fi - # Update dev folder rm -rf $TEMP_DOC_FOLDER/dev mkdir -p $TEMP_DOC_FOLDER/dev - cp -R $BUILT_VERSION_DIR/* $TEMP_DOC_FOLDER/dev/ + cp -R $BUILD_DIR/dev/* $TEMP_DOC_FOLDER/dev/ else # Release mode: Copy from dev to create new release version echo "Creating release documentation for version $SHORT_DOC_VERSION from dev..." @@ -102,8 +100,8 @@ else cp -R $TEMP_DOC_FOLDER/dev/* $TEMP_DOC_FOLDER/latest/ fi -# Copy index.html if it exists -if [ -f "$BUILD_DIR/index.html" ]; then +# Copy root index.html if it exists (only in dev mode, as release mode doesn't build) +if [ "$IS_DEV_MODE" = true ] && [ -f "$BUILD_DIR/index.html" ]; then cp $BUILD_DIR/index.html $TEMP_DOC_FOLDER/ fi @@ -132,12 +130,41 @@ ls -la $TEMP_DOC_FOLDER/ cat $TEMP_DOC_FOLDER/versions.json git checkout -- .github/scripts/doc_release.sh -##### Archive to doc_archive branch (release mode only) ##### -if [ "$IS_DEV_MODE" = false ]; then +##### Archive to doc_archive branch ##### +git config user.name "github-actions[bot]" +git config user.email "github-actions[bot]@users.noreply.github.com" +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + +if [ "$IS_DEV_MODE" = true ]; then + # Dev mode: Archive dev documentation + echo "Archiving dev documentation to branch $STORAGE_BRANCH..." + + if git ls-remote --heads origin "$STORAGE_BRANCH" | grep -q "$STORAGE_BRANCH"; then + echo "Storage branch exists, updating dev documentation..." + git fetch origin $STORAGE_BRANCH + git checkout $STORAGE_BRANCH + + rm -rf dev + mkdir -p dev + rsync -av $TEMP_DOC_FOLDER/dev/ dev/ + git add dev + git commit -m "Update dev documentation" || echo "No changes to commit for dev" + else + echo "Creating new storage branch with dev documentation..." + git checkout --orphan $STORAGE_BRANCH + git rm -rf . + + mkdir -p dev + rsync -av $TEMP_DOC_FOLDER/dev/ dev/ + git add dev + git commit -m "Initialize doc archive branch with dev documentation" + fi + + git push origin $STORAGE_BRANCH + git checkout $CURRENT_BRANCH +else + # Release mode: Archive versioned documentation echo "Archiving version $SHORT_DOC_VERSION to branch $STORAGE_BRANCH..." - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) if git ls-remote --heads origin "$STORAGE_BRANCH" | grep -q "$STORAGE_BRANCH"; then echo "Storage branch exists, fetching it..." diff --git a/.github/workflows/docs-release.yml b/.github/workflows/docs-release.yml index 3ff5f9245d..fee1803337 100644 --- a/.github/workflows/docs-release.yml +++ b/.github/workflows/docs-release.yml @@ -79,6 +79,7 @@ jobs: else echo "Push to main branch detected, building dev documentation" echo "IS_DEV_BUILD=true" >> $GITHUB_ENV + echo "SHORT_DOC_VERSION=dev" >> $GITHUB_ENV exit 0 fi # Error out if cannot find version @@ -107,11 +108,13 @@ jobs: pip install -r dependencies-dev pip install -r requirements-doc.txt - name: Build daal4py/sklearnex + if: env.IS_DEV_BUILD == 'true' run: | export DALROOT=$(dirname $(dirname $(which python))) export LD_LIBRARY_PATH=$(dirname $(dirname $(which python)))/lib:$LD_LIBRARY_PATH ./conda-recipe/build.sh - name: Build scikit-learn-intelex Documentation + if: env.IS_DEV_BUILD == 'true' run: | export LD_LIBRARY_PATH=$(dirname $(dirname $(which python)))/lib:$LD_LIBRARY_PATH cd doc diff --git a/doc/build-doc.sh b/doc/build-doc.sh index 14cab0555d..53ba9ec54d 100755 --- a/doc/build-doc.sh +++ b/doc/build-doc.sh @@ -49,7 +49,7 @@ if [[ "$*" == *"--gh-pages"* ]]; then export SOURCEDIR=sources sphinx-build -b html $SPHINXOPTS $SOURCEDIR $BUILDDIR/$SPHINXPROJ/$DOC_VERSION - echo "" >> $BUILDDIR/$SPHINXPROJ/index.html + echo "" >> $BUILDDIR/$SPHINXPROJ/index.html else make html fi