-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate documentation for different versions
Fixes #36
- Loading branch information
1 parent
76e207f
commit be1a8f6
Showing
4 changed files
with
136 additions
and
42 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,123 @@ | ||
name: Doxygen | ||
name: Documentation workflow | ||
|
||
permissions: | ||
contents: write | ||
|
||
env: | ||
BUILD_DIR: ${{github.workspace}}/build | ||
SELECTOR_FILE_NAME: version_selector.html | ||
SELECTOR_ID: versionSelector | ||
GIT_USER_NAME: 'Oleksandr Koval' | ||
GIT_USER_EMAIL: 'OleksandrKvl@users.noreply.github.com' | ||
|
||
on: | ||
# to update docs/git-main | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
# to publish docs/<release-version> | ||
release: | ||
types: [released] | ||
|
||
jobs: | ||
build: | ||
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. | ||
# You can convert this to a matrix build if you need cross-platform coverage. | ||
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix | ||
publish-docs: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install deps | ||
run: | | ||
sudo apt install -y cmake | ||
sudo apt install -y wget | ||
wget -nv https://www.doxygen.nl/files/doxygen-1.10.0.linux.bin.tar.gz | ||
tar -xzf doxygen-1.10.0.linux.bin.tar.gz | ||
echo "$(pwd)/doxygen-1.10.0/bin" >> $GITHUB_PATH | ||
- name: CMake configuration | ||
run: | | ||
cmake -B ${{github.workspace}}/build \ | ||
-D CMAKE_C_COMPILER=/usr/bin/gcc-11 \ | ||
-D CMAKE_CXX_COMPILER=/usr/bin/g++-11 \ | ||
-D SBEPP_BUILD_SBEPPC=OFF \ | ||
-D SBEPP_BUILD_DOCS=ON | ||
- name: CMake build | ||
run: | | ||
cmake --build ${{github.workspace}}/build \ | ||
--target doc | ||
- name: Moving Files | ||
run: | | ||
mv ${{github.workspace}}/build/doc/html ./doc/html | ||
- name: Deploy to Github Pages | ||
uses: peaceiris/actions-gh-pages@v3 | ||
|
||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./doc/html | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install deps | ||
shell: bash | ||
run: | | ||
sudo apt install -y cmake | ||
sudo apt install -y wget | ||
wget -nv https://www.doxygen.nl/files/doxygen-1.10.0.linux.bin.tar.gz | ||
tar -xzf doxygen-1.10.0.linux.bin.tar.gz | ||
echo "$(pwd)/doxygen-1.10.0/bin" >> $GITHUB_PATH | ||
- name: CMake configure | ||
run: cmake -B $BUILD_DIR | ||
|
||
- name: CMake build | ||
run: cmake --build $BUILD_DIR --target doc | ||
|
||
- name: Get docs version | ||
id: get-docs-version | ||
run: | | ||
subdir=$(basename $(find $BUILD_DIR/doc/docs -mindepth 1 -maxdepth 1 -type d | head -n 1)) | ||
echo "version=$subdir" >> $GITHUB_OUTPUT | ||
- name: Update redirect HTML | ||
if: github.event_name == 'release' | ||
run: | | ||
mkdir $BUILD_DIR/doc/docs/redirect | ||
cat << EOF > $BUILD_DIR/doc/docs/redirect/index.html | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="refresh" content="0; url=${{ steps.get-docs-version.outputs.version }}/index.html"> | ||
<title>Redirecting...</title> | ||
</head> | ||
<body> | ||
<p>If you are not redirected automatically, <a href="${{ steps.get-docs-version.outputs.version }}/index.html">click here</a>.</p> | ||
</body> | ||
</html> | ||
EOF | ||
- name: Deploy release docs | ||
if: github.event_name == 'release' | ||
uses: peaceiris/actions-gh-pages@v4 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ${{ env.BUILD_DIR }}/doc/docs/${{ steps.get-docs-version.outputs.version }} | ||
destination_dir: ${{ steps.get-docs-version.outputs.version }} | ||
|
||
- name: Deploy redirect page | ||
if: github.event_name == 'release' | ||
uses: peaceiris/actions-gh-pages@v4 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ${{ env.BUILD_DIR }}/doc/docs/redirect | ||
keep_files: true | ||
|
||
- name: Deploy git-main docs | ||
if: github.event_name == 'push' | ||
uses: peaceiris/actions-gh-pages@v4 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ${{ env.BUILD_DIR }}/doc/docs/${{ steps.get-docs-version.outputs.version }} | ||
destination_dir: git-main | ||
|
||
# Update version_selector.html | ||
- name: Pull gh-pages | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: gh-pages | ||
|
||
- name: Discover versions | ||
run: | | ||
# Enumerate directories and store them in a variable | ||
dirs=$(find . -mindepth 1 -maxdepth 1 -type d | sort -rV) | ||
# Create HTML | ||
echo '<select id="$SELECTOR_ID">' > $SELECTOR_FILE_NAME | ||
for dir in $dirs; do | ||
if [[ "$(basename "$dir")" != .* ]]; then | ||
version=$(basename "$dir") | ||
echo " <option value=\"$version\">$version</option>" >> $SELECTOR_FILE_NAME | ||
fi | ||
done | ||
echo '</select>' >> $SELECTOR_FILE_NAME | ||
|
||
- name: Push selector | ||
run: | | ||
git config --global user.name $GIT_USER_NAME | ||
git config --global user.email $GIT_USER_EMAIL | ||
if [[ -n "$(git diff --exit-code $SELECTOR_FILE_NAME)" ]]; then | ||
git add $SELECTOR_FILE_NAME | ||
git commit -m "Update version selector" | ||
git push origin gh-pages | ||
else | ||
echo "$SELECTOR_FILE_NAME has not been changed. Skipping push." | ||
fi |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) 2024, Oleksandr Koval | ||
|
||
$(function () { | ||
$.get('/version_selector.html', function (data) { | ||
// Inject version selector HTML into the page | ||
$('#projectnumber').html(data); | ||
|
||
// Event listener to handle version selection | ||
document.getElementById('versionSelector').addEventListener('change', function () { | ||
var selectedVersion = this.value; | ||
window.location.href = '/' + selectedVersion + '/index.html'; | ||
|
||
}); | ||
|
||
// Set the selected option based on the current version | ||
var currentVersion = window.location.pathname.split('/')[1]; | ||
$('#versionSelector').val(currentVersion); | ||
}); | ||
}); |