Skip to content

Commit 21a8267

Browse files
david-cortes-intelyuejiaointelgithub-actions[bot]
authored
fix: use upload github action to public site (#2459) (#2497)
* fix: use upload github action to public site * fix: allow tag trigger with also year.month * test: test tag trigger * test: test tag trigger * .github/workflows/docs-release.yml * fix: don't copy gh-pages everytime, only copy parts don't exist * fix:move prepare script to doc_release.sh * fix:test checkout * fix:test upload pages artifact only has v3 * fix: fetch gh-apges if we have one * fix: use eaceiris/actions-gh-pages@v3 to keep old files when upload new ones * fix: use a intermediate unprotected branch for all doc archives * fix: fix archive * fix: fix archive * fix: remove doc from switcher url in conf and archive enture folder * fix: remove +x changes in doc relase before archive step * fix: move permission and use exact commit id for github actions * fix: use env var for _site folder and use doc folders for archive branch * fix: delete everything for new doc arvhice branch * fix: remove untracked files * fix: only add verison folders to git first time doc archive * fix: move TEMP_DOC_FOLDER to yml and make sure it is im tmp * fix: move env to jobs * fix: still need git rm for firs ttime doc archive creation * fix: remove doc * fix: allow manual trigger * fix: workflow dispatch add input requriement * fix: don't force input on workflow dispatch * test: test older python version doc build warning * fix: force doc version input * fix: remove unused dependency --------- Co-authored-by: yuejiaointel <108152493+yuejiaointel@users.noreply.github.com> Co-authored-by: yuejiaointel <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 211e127 commit 21a8267

File tree

2 files changed

+137
-60
lines changed

2 files changed

+137
-60
lines changed

.github/scripts/doc_release.sh

Lines changed: 96 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,56 +16,111 @@
1616
# limitations under the License.
1717
#===============================================================================
1818

19-
# Ensure the build directory exists
2019
BUILD_DIR="doc/_build/scikit-learn-intelex"
20+
STORAGE_BRANCH="doc_archive"
21+
22+
# Check if TEMP_DOC_FOLDER is set
23+
if [ -z "$TEMP_DOC_FOLDER" ]; then
24+
echo "::error::TEMP_DOC_FOLDER environment variable is not set!"
25+
exit 1
26+
fi
27+
28+
# Ensure the build directory exists
2129
if [ ! -d "$BUILD_DIR" ]; then
2230
echo "::error: Documentation build directory not found!"
2331
exit 1
2432
fi
2533

26-
# Copy built documentation to a temp location
27-
DEPLOY_DIR="/tmp/gh-pages-deploy"
28-
mkdir -p "$DEPLOY_DIR"
29-
cp -R "$BUILD_DIR"/* "$DEPLOY_DIR"
30-
ls $DEPLOY_DIR
34+
rm -rf $TEMP_DOC_FOLDER
35+
mkdir -p $TEMP_DOC_FOLDER
3136

32-
# Checkout gh-pages branch
33-
if ! git checkout gh-pages; then
34-
echo "::error:: Could not checkout gh-pages branch!"
35-
exit 1
36-
fi
37+
##### Get archived version folders from doc_archive and gh-pages #####
38+
# Function to sync content from a branch to the temp folder
39+
sync_from_branch() {
40+
local branch_name=$1
41+
42+
if git ls-remote --heads origin $branch_name | grep -q $branch_name; then
43+
echo "$branch_name branch exists, syncing content..."
44+
git fetch origin $branch_name:$branch_name
45+
git worktree add branch_sync $branch_name
46+
rsync -av --ignore-existing branch_sync/ $TEMP_DOC_FOLDER/
47+
git worktree remove branch_sync --force
48+
else
49+
echo "$branch_name branch does not exist, skipping sync."
50+
fi
51+
}
52+
sync_from_branch $STORAGE_BRANCH
53+
sync_from_branch "gh-pages"
3754

38-
# Move the new versioned folder to the correct location
39-
rm -Rf latest
40-
cp -R "$DEPLOY_DIR/$SHORT_DOC_VERSION" "$SHORT_DOC_VERSION"
41-
cp -R "$DEPLOY_DIR/$SHORT_DOC_VERSION" latest
42-
cp "$DEPLOY_DIR/index.html" .
43-
if ! diff -r "$SHORT_DOC_VERSION" latest > /dev/null; then
44-
echo "::error: Content mismatch between $SHORT_DOC_VERSION and latest directories"
45-
echo "Differences found:"
46-
diff -r "$SHORT_DOC_VERSION" latest
47-
exit 1
48-
fi
55+
##### Prepare new doc #####
56+
# Copy the new built version to $TEMP_DOC_FOLDER
57+
mkdir -p $TEMP_DOC_FOLDER/$SHORT_DOC_VERSION
58+
cp -R doc/_build/scikit-learn-intelex/$SHORT_DOC_VERSION/* $TEMP_DOC_FOLDER/$SHORT_DOC_VERSION/
4959

50-
# Generate versions.json by scanning for year.month folders
51-
rm -f doc/versions.json
52-
mkdir -p doc
53-
echo "[" > doc/versions.json
60+
# Update latest
61+
rm -rf $TEMP_DOC_FOLDER/latest
62+
mkdir -p $TEMP_DOC_FOLDER/latest
63+
cp -R doc/_build/scikit-learn-intelex/$SHORT_DOC_VERSION/* $TEMP_DOC_FOLDER/latest/
64+
65+
# Copy index.html
66+
cp doc/_build/scikit-learn-intelex/index.html $TEMP_DOC_FOLDER/
67+
68+
# Generate versions.json
69+
mkdir -p $TEMP_DOC_FOLDER
70+
echo "[" > $TEMP_DOC_FOLDER/versions.json
5471
# Add latest entry first
55-
echo ' {"name": "latest", "version": "'$SHORT_DOC_VERSION'", "url": "/scikit-learn-intelex/latest/"},' >> doc/versions.json
72+
echo ' {"name": "latest", "version": "'$SHORT_DOC_VERSION'", "url": "/scikit-learn-intelex/latest/"},' >> $TEMP_DOC_FOLDER/versions.json
5673
# Add all year.month folders
57-
for version in $(ls -d [0-9][0-9][0-9][0-9].[0-9]* 2>/dev/null || true); do
58-
echo ' {"name": "'$version'", "version": "'$version'", "url": "/scikit-learn-intelex/'$version'/"},'
59-
done | sort -rV >> doc/versions.json
74+
for version in $(ls -d $TEMP_DOC_FOLDER/[0-9][0-9][0-9][0-9].[0-9]* 2>/dev/null || true); do
75+
version=$(basename "$version")
76+
echo ' {"name": "'$version'", "version": "'$version'", "url": "/scikit-learn-intelex/'$version'/"},'
77+
done | sort -rV >> $TEMP_DOC_FOLDER/versions.json
6078
# Remove trailing comma and close array
61-
sed -i '$ s/,$//' doc/versions.json
62-
echo "]" >> doc/versions.json
63-
cat doc/versions.json
64-
65-
# Commit and push changes
66-
git add -A "$SHORT_DOC_VERSION"
67-
git add -A latest
68-
git add doc/versions.json
69-
git add index.html
70-
git commit . -m "Automatic doc update for version $DOC_VERSION"
71-
git push origin gh-pages
79+
sed -i '$ s/,$//' $TEMP_DOC_FOLDER/versions.json
80+
echo "]" >> $TEMP_DOC_FOLDER/versions.json
81+
82+
# Display the content for verification
83+
ls -la $TEMP_DOC_FOLDER/
84+
cat $TEMP_DOC_FOLDER/versions.json
85+
git checkout -- .github/scripts/doc_release.sh
86+
87+
##### Archive to doc_archive branch #####
88+
echo "Archiving version $SHORT_DOC_VERSION to branch $STORAGE_BRANCH..."
89+
git config user.name "github-actions[bot]"
90+
git config user.email "github-actions[bot]@users.noreply.github.com"
91+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
92+
93+
# Check if storage branch exists
94+
if git ls-remote --heads origin "$STORAGE_BRANCH" | grep -q "$STORAGE_BRANCH"; then
95+
echo "Storage branch exists, fetching it..."
96+
git fetch origin $STORAGE_BRANCH
97+
git checkout $STORAGE_BRANCH
98+
99+
# Add only the new version directory
100+
mkdir -p $SHORT_DOC_VERSION
101+
rsync -av $TEMP_DOC_FOLDER/$SHORT_DOC_VERSION/ $SHORT_DOC_VERSION/
102+
git add $SHORT_DOC_VERSION
103+
git commit -m "Add documentation for version $SHORT_DOC_VERSION"
104+
else
105+
echo "Creating new storage branch with all current versions..."
106+
# Create an empty orphan branch
107+
git checkout --orphan $STORAGE_BRANCH
108+
git rm -rf .
109+
110+
# Copy only version folders
111+
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
112+
version=$(basename "$version_dir")
113+
mkdir -p $version
114+
rsync -av "$version_dir/" $version/
115+
done
116+
117+
# Git only add verison folders
118+
git add -- [0-9][0-9][0-9][0-9].[0-9]*
119+
git commit -m "Initialize doc archive branch with all versions"
120+
fi
121+
122+
# Push changes
123+
git push origin $STORAGE_BRANCH
124+
125+
# Return to original branch
126+
git checkout $CURRENT_BRANCH

.github/workflows/docs-release.yml

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,50 @@ on:
1919
push:
2020
tags:
2121
- '[0-9][0-9][0-9][0-9]\.[0-9][0-9]?\.[0-9]' # Trigger on tag pushes
22+
workflow_dispatch:
23+
inputs:
24+
doc_version:
25+
description: 'Tag version (e.g. 2024.10.0)'
26+
required: true
27+
28+
permissions: read-all
2229

23-
permissions:
24-
contents: write
25-
2630
jobs:
2731
build-docs:
2832
runs-on: ubuntu-24.04
29-
33+
permissions:
34+
contents: write
35+
pages: write
36+
id-token: write
37+
environment:
38+
name: github-pages
39+
url: ${{ steps.deployment.outputs.page_url }}
40+
env:
41+
TEMP_DOC_FOLDER: /tmp/_site
42+
3043
steps:
3144
- name: Checkout Repository
32-
uses: actions/checkout@v4
45+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3346
with:
3447
fetch-depth: 0 # Ensures all tags are fetched
3548

3649
- name: Set Up Python
37-
uses: actions/setup-python@v5
50+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
3851
with:
39-
python-version: "3.13"
52+
python-version: "3.11"
4053

4154
- name: Install System Dependencies
4255
run: sudo apt-get update && sudo apt-get install -y clang-format pandoc
4356

4457
- name: Extract Tag Version
4558
run: |
46-
export DOC_VERSION="${GITHUB_REF#refs/tags/}"
59+
if [ -n "${{ github.event.inputs.doc_version }}" ]; then
60+
export DOC_VERSION="${{ github.event.inputs.doc_version }}"
61+
echo "Manual dispatch detected with version: $DOC_VERSION"
62+
else
63+
export DOC_VERSION="${GITHUB_REF#refs/tags/}"
64+
echo "Tag trigger detected with version: $DOC_VERSION"
65+
fi
4766
# Error out if cannot find version
4867
if [ -z "$DOC_VERSION" ]; then
4968
echo "::error: Failed to determine documentation version."
@@ -77,17 +96,20 @@ jobs:
7796
export LD_LIBRARY_PATH=$(dirname $(dirname $(which python)))/lib:$LD_LIBRARY_PATH
7897
cd doc
7998
./build-doc.sh --gh-pages
80-
- name: Deploy Documentation to gh-pages
81-
env:
82-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99+
100+
- name: Setup Pages
101+
uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5.0.0
102+
103+
- name: Prepare Documentation for Deployment
83104
run: |
84-
# Copy the script to a temp location
85-
# Otherwise it will get lost after switch branch
86-
cp .github/scripts/doc_release.sh /tmp/doc_release.sh
105+
chmod +x .github/scripts/doc_release.sh
106+
./.github/scripts/doc_release.sh
87107
88-
# Set git auth for push changes
89-
git config --global user.name "GitHub Actions"
90-
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
108+
- name: Upload artifact for GitHub Pages
109+
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1
110+
with:
111+
path: ${{ env.TEMP_DOC_FOLDER }}
91112

92-
chmod +x /tmp/doc_release.sh
93-
/tmp/doc_release.sh
113+
- name: Deploy to GitHub Pages
114+
id: deployment
115+
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5

0 commit comments

Comments
 (0)