Skip to content

Commit

Permalink
Fix the repos_file_branch macro and multiversion wf (#307)
Browse files Browse the repository at this point in the history
* Fix the repos_file_branch macro

* Create python script for fix_index step

* Apply suggestions from code review

Co-authored-by: Sai Kishor Kothakota <[email protected]>

---------

Co-authored-by: Sai Kishor Kothakota <[email protected]>
  • Loading branch information
christophfroehlich and saikishor authored May 14, 2024
1 parent 23542bb commit 54d1641
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
15 changes: 3 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ multiversion: Makefile
@echo Step 3: Deleting temporary commits
./make_help_scripts/delete_tmp_commits.py
@echo Step 4: Create correct index + legacy master version
@echo "<html><head><meta http-equiv=\"refresh\" content=\"0; url=rolling/index.html\" /></head></html>" > "$(BUILDDIR)"/html/index.html
# legacy, renamed Rolling version from "master" to "rolling"
@cp -r "$(BUILDDIR)"/html/rolling/ "$(BUILDDIR)"/html/master
@echo "<html><head><meta http-equiv=\"refresh\" content=\"0; url=../rolling/index.html\" /></head></html>" > "$(BUILDDIR)"/html/master/index.html
./make_help_scripts/fix_index.py --build-dir $(BUILDDIR)

multiversion-with-errors: Makefile
@echo Building multi version documentation without API
Expand All @@ -95,10 +92,7 @@ multiversion-with-errors: Makefile
@echo Step 3: Deleting temporary commits
./make_help_scripts/delete_tmp_commits.py
@echo Step 4: Create correct index + legacy master version
@echo "<html><head><meta http-equiv=\"refresh\" content=\"0; url=rolling/index.html\" /></head></html>" > "$(BUILDDIR)"/html/index.html
# legacy, renamed Rolling version from "master" to "rolling"
@cp -r "$(BUILDDIR)"/html/rolling/ "$(BUILDDIR)"/html/master
@echo "<html><head><meta http-equiv=\"refresh\" content=\"0; url=../rolling/index.html\" /></head></html>" > "$(BUILDDIR)"/html/master/index.html
./make_help_scripts/fix_index.py --build-dir $(BUILDDIR)

multiversion-with-api: Makefile
@echo Building multi version documentation with API
Expand All @@ -113,10 +107,7 @@ multiversion-with-api: Makefile
@echo Step 5: Building multiversion API
./make_help_scripts/create_api_multi_version.py
@echo Step 6: Create correct index + legacy master version
@echo "<html><head><meta http-equiv=\"refresh\" content=\"0; url=rolling/index.html\" /></head></html>" > "$(BUILDDIR)"/html/index.html
# legacy, renamed Rolling version from "master" to "rolling"
@cp -r "$(BUILDDIR)"/html/rolling/ "$(BUILDDIR)"/html/master
@echo "<html><head><meta http-equiv=\"refresh\" content=\"0; url=../rolling/index.html\" /></head></html>" > "$(BUILDDIR)"/html/master/index.html
./make_help_scripts/fix_index.py --build-dir $(BUILDDIR)

.PHONY: help Makefile html-with-errors html-with-api multiversion multiversion-with-api multiversion-with-errors html-all-subrepos html-all-subrepos-with-api html-all-subrepos-with-errors linkcheck-all-subrepos-with-api

Expand Down
6 changes: 3 additions & 3 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
copyright = "{}, {}".format(time.strftime("%Y"), author)

# Adjust those to change ros distribution
# you might also need to white list branch
# you might also need to white list branch (see smv_branch_whitelist)
ros_distro = "rolling"
distro_title = "Rolling"
distro_title_full = "Rolling Ridley"
repos_file_branch = "rolling" # for single version only
repos_file_branch = "master" # sets macro REPOS_FILE_BRANCH (will be overridden with multiversion)

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -341,7 +341,7 @@ def smv_rewrite_configs(app, config):
# this map is used to match branches of control.ros.org to REPOS_FILE_BRANCH macro
subrepo_branch = {
base_branch: "master",
"jazzy": "jazzy",
"jazzy": "master",
"iron": "iron",
"humble": "humble",
"foxy": "foxy",
Expand Down
39 changes: 39 additions & 0 deletions make_help_scripts/fix_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3
# Copyright (c) 2023 ros2_control maintainers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import os
import shutil
import deploy_defines

def fix_index(base_branch, builddir):

# Create the index.html file in the html directory
with open(os.path.join(builddir, 'html', 'index.html'), 'w') as f:
f.write(f'<html><head><meta http-equiv="refresh" content="0; url={base_branch}/index.html" /></head></html>')

# Copy the contents of the base_branch directory to the master directory
shutil.copytree(os.path.join(builddir, 'html', base_branch), os.path.join(builddir, 'html', 'master'), dirs_exist_ok=True)

# Patch the index.html file in the master directory
with open(os.path.join(builddir, 'html', 'master', 'index.html'), 'w') as f:
f.write(f'<html><head><meta http-equiv="refresh" content="0; url=../{base_branch}/index.html" /></head></html>')

if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Fix index.')
parser.add_argument('--build-dir', required=True, help='Build directory.')

args = parser.parse_args()
fix_index(deploy_defines.base_branch, args.build_dir)

0 comments on commit 54d1641

Please sign in to comment.