From 6dd4367f1aeb2f4dbb393ac970e90d54f7153a26 Mon Sep 17 00:00:00 2001 From: Paul Wright <5154224+pwright@users.noreply.github.com> Date: Mon, 10 Jun 2024 14:02:15 +0100 Subject: [PATCH] Define published files in yaml and only render those files (#243) use workflow yaml as source of nav links --- .github/workflows/asciidoc-convert-check.yml | 1 + Makefile | 2 +- README.adoc | 7 ++- scripts/convert-adoc.sh | 0 scripts/convert-all.py | 58 ++++++++++++++++++++ scripts/convert-all.sh | 17 ------ 6 files changed, 66 insertions(+), 19 deletions(-) mode change 100644 => 100755 scripts/convert-adoc.sh create mode 100644 scripts/convert-all.py delete mode 100644 scripts/convert-all.sh diff --git a/.github/workflows/asciidoc-convert-check.yml b/.github/workflows/asciidoc-convert-check.yml index 9df28b8..6881872 100644 --- a/.github/workflows/asciidoc-convert-check.yml +++ b/.github/workflows/asciidoc-convert-check.yml @@ -46,6 +46,7 @@ jobs: "overview/resources.adoc" "overview/routing.adoc" "overview/security.adoc" + "overview/load.adoc" "kubernetes/deployment-concerns.adoc" ) for file in "${files[@]}"; do diff --git a/Makefile b/Makefile index edc300d..77383ea 100644 --- a/Makefile +++ b/Makefile @@ -23,4 +23,4 @@ export PYTHONPATH := python .PHONY: generate-preview generate-preview: - bash ./scripts/convert-all.sh + python ./scripts/convert-all.py ./scripts/convert-adoc.sh .github/workflows/asciidoc-convert-check.yml diff --git a/README.adoc b/README.adoc index 1de1471..7798429 100644 --- a/README.adoc +++ b/README.adoc @@ -22,7 +22,12 @@ If you want to preview changes for more complex contributions, follow this proce . Start the build: + ---- -$ bash scripts/convert-all.sh +$ python scripts/convert-all.py ./scripts/convert +-adoc.sh .github/workflows/asciidoc-convert-check.yml ---- +* `convert-adoc.sh` converts each adoc to HTML +* `.github/workflows/asciidoc-convert-check.yml` is the single source of truth about which adoc files are published, see [GitHub: Source code for the Skupper project website]( https://github.com/skupperproject/skupper-website ). + + . See the `build` directory for the HTML output. diff --git a/scripts/convert-adoc.sh b/scripts/convert-adoc.sh old mode 100644 new mode 100755 diff --git a/scripts/convert-all.py b/scripts/convert-all.py new file mode 100644 index 0000000..c6c2c8e --- /dev/null +++ b/scripts/convert-all.py @@ -0,0 +1,58 @@ +import yaml +import subprocess +import os +import argparse + +# Function to parse command-line arguments +def parse_args(): + parser = argparse.ArgumentParser(description="Process AsciiDoc files using a specified script.") + parser.add_argument('script', help="Path to the script to process AsciiDoc files.") + parser.add_argument('yaml_file', help="Path to the YAML file containing the list of AsciiDoc files.") + return parser.parse_args() + +# Function to read the YAML content from a file +def read_yaml(yaml_file): + with open(yaml_file, 'r') as file: + return yaml.safe_load(file) + +# Function to retrieve AsciiDoc files list +def get_asciidoc_files(data): + asciidoc_files = [] + # Navigate through the nested dictionary to find the 'files' list + for job_name, job_details in data.get('jobs', {}).items(): + steps = job_details.get('steps', []) + for step in steps: + if step.get('name') == 'Convert specified AsciiDoc files to HTML': + run_content = step.get('run', '') + if 'files=(' in run_content: + start = run_content.find('files=(') + len('files=(') + end = run_content.find(')', start) + files_list = run_content[start:end].strip().split('\n') + # Clean and add the files to the list + for file in files_list: + clean_file = file.strip().strip('"') + if clean_file: + asciidoc_files.append(clean_file) + return asciidoc_files + +# Function to run the specified script against each AsciiDoc file +def process_asciidoc_file(script, file): + # Check if the script exists + if not os.path.exists(script): + print(f"Script not found: {script}") + return + # Execute the script with the file as an argument using bash + result = subprocess.run(['bash', script, file], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + print(result.stdout) # Print or handle the output as needed + if result.stderr: + print(f"Error processing {file}: {result.stderr}") + +def main(): + args = parse_args() + data = read_yaml(args.yaml_file) + asciidoc_files = get_asciidoc_files(data) + for file in asciidoc_files: + process_asciidoc_file(args.script, file) + +if __name__ == "__main__": + main() diff --git a/scripts/convert-all.sh b/scripts/convert-all.sh deleted file mode 100644 index 773fc54..0000000 --- a/scripts/convert-all.sh +++ /dev/null @@ -1,17 +0,0 @@ -bash scripts/convert-adoc.sh \ -cli/index.adoc \ -cli/tokens.adoc \ -cli/podman.adoc \ -cli/native-security-options.adoc \ -yaml/index.adoc \ -operator/index.adoc \ -console/index.adoc \ -policy/index.adoc \ -troubleshooting/index.adoc \ -overview/connectivity.adoc \ -overview/glossary.adoc \ -overview/index.adoc \ -overview/resources.adoc \ -overview/routing.adoc \ -overview/security.adoc \ -kubernetes/deployment-concerns.adoc