From 4ddd5d0bdc51935d32b1a7bf6651131ea9b5c4f7 Mon Sep 17 00:00:00 2001 From: dvkruchinin Date: Fri, 20 Aug 2021 12:30:20 +0300 Subject: [PATCH 1/4] GH pages --- .github/workflows/github_pages.yml | 43 +++++++++++++++++++ site/build_docs.py | 68 ++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 .github/workflows/github_pages.yml create mode 100644 site/build_docs.py diff --git a/.github/workflows/github_pages.yml b/.github/workflows/github_pages.yml new file mode 100644 index 0000000000..9abe9d54eb --- /dev/null +++ b/.github/workflows/github_pages.yml @@ -0,0 +1,43 @@ +name: Github pages + +on: + push: + branches: + - develop + +jobs: + deploy: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + fetch-depth: 0 + + - name: Setup Hugo + uses: peaceiris/actions-hugo@v2 + with: + hugo-version: '0.83.1' + extended: true + + - name: Setup Node + uses: actions/setup-node@v2 + with: + node-version: '14.x' + + - name: Install npm packages + working-directory: ./site + run: | + npm ci + + - name: Build docs + run: | + pip install gitpython packaging + python site/build_docs.py + + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./public + force_orphan: true diff --git a/site/build_docs.py b/site/build_docs.py new file mode 100644 index 0000000000..d649af4625 --- /dev/null +++ b/site/build_docs.py @@ -0,0 +1,68 @@ +# Copyright (C) 2021 Intel Corporation +# +# SPDX-License-Identifier: MIT + +import os +from packaging import version +import subprocess + +import git + +MINIMUM_VERSION='1.5.0' + +def prepare_tags(repo): + tags = {} + for tag in repo.tags: + tag_version = version.parse(tag.name) + if tag_version >= version.Version(MINIMUM_VERSION) and not tag_version.is_prerelease: + release_version = (tag_version.major, tag_version.minor) + if not release_version in tags or tag_version > version.parse(tags[release_version].name): + tags[release_version] = tag + + return tags.values() + +def generate_versioning_config(filename, versions, url_prefix=''): + def write_version_item(file_object, version, url): + file_object.write('[[params.versions]]\n') + file_object.write('version = "{}"\n'.format(version)) + file_object.write('url = "{}"\n\n'.format(url)) + + with open(filename, 'w') as f: + write_version_item(f, 'develop', '{}/'.format(url_prefix)) + for v in versions: + write_version_item(f, v, '{}/{}'.format(url_prefix, v)) + +def generate_docs(repo, output_dir, tags): + def run_hugo(content_loc, destination_dir): + subprocess.run([ # nosec + 'hugo', + '--destination', + destination_dir, + '--config', + 'config.toml,versioning.toml', + ], + cwd=content_loc, + ) + + cwd = repo.working_tree_dir + content_loc = os.path.join(cwd, 'site') + if not os.path.exists(output_dir): + os.makedirs(output_dir) + + generate_versioning_config(os.path.join(cwd, 'site', 'versioning.toml'), (t.name for t in tags)) + run_hugo(content_loc, output_dir) + + generate_versioning_config(os.path.join(cwd, 'site', 'versioning.toml'), (t.name for t in tags), '/..') + for tag in tags: + repo.git.checkout(tag.name) + destination_dir = os.path.join(output_dir, tag.name) + os.makedirs(destination_dir) + run_hugo(content_loc, destination_dir) + +if __name__ == "__main__": + repo_root = os.getcwd() + repo = git.Repo(repo_root) + output_dir = os.path.join(repo_root, 'public') + + tags = prepare_tags(repo) + generate_docs(repo, output_dir, tags) From 24fbcf9c40e738ddb7c040aa2a163a07bc842201 Mon Sep 17 00:00:00 2001 From: dvkruchinin Date: Fri, 20 Aug 2021 12:39:28 +0300 Subject: [PATCH 2/4] Fix isort issue --- site/build_docs.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/site/build_docs.py b/site/build_docs.py index d649af4625..c32d081320 100644 --- a/site/build_docs.py +++ b/site/build_docs.py @@ -3,9 +3,8 @@ # SPDX-License-Identifier: MIT import os -from packaging import version import subprocess - +from packaging import version import git MINIMUM_VERSION='1.5.0' From adb48a85167964ec510600c0db0a53a817ff4991 Mon Sep 17 00:00:00 2001 From: dvkruchinin Date: Fri, 20 Aug 2021 12:41:40 +0300 Subject: [PATCH 3/4] isort fix --- site/build_docs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/site/build_docs.py b/site/build_docs.py index c32d081320..75e05f12cb 100644 --- a/site/build_docs.py +++ b/site/build_docs.py @@ -4,6 +4,7 @@ import os import subprocess + from packaging import version import git From 0b9f79e0a78517ba8fdd4532caa2997c50a8185c Mon Sep 17 00:00:00 2001 From: dvkruchinin Date: Fri, 20 Aug 2021 12:53:54 +0300 Subject: [PATCH 4/4] Update build_docs.py --- site/build_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/build_docs.py b/site/build_docs.py index 75e05f12cb..21c3f1bfaa 100644 --- a/site/build_docs.py +++ b/site/build_docs.py @@ -54,7 +54,7 @@ def run_hugo(content_loc, destination_dir): generate_versioning_config(os.path.join(cwd, 'site', 'versioning.toml'), (t.name for t in tags), '/..') for tag in tags: - repo.git.checkout(tag.name) + repo.git.checkout(tag.name, '--', 'site/content/en/docs') destination_dir = os.path.join(output_dir, tag.name) os.makedirs(destination_dir) run_hugo(content_loc, destination_dir)