generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #355 from okp4/ci/documentation-bundles
ci(workflow): add generate-doc-bundles workflow
- Loading branch information
Showing
1 changed file
with
77 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: 📦 Generate Documentation Bundles | ||
|
||
on: | ||
workflow_call: | ||
|
||
concurrency: | ||
group: generate-doc-bundles-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
generate-doc-bundles: | ||
runs-on: ubuntu-22.04 | ||
strategy: | ||
matrix: | ||
bundles: | ||
- name: "whitepaper-tech-faq" | ||
sources: | ||
- "docs/whitepaper/**/*.md" | ||
- "docs/technical-documentation/**/*.md" | ||
- "docs/faq/**/*.md" | ||
- name: "tutorial-validator" | ||
sources: | ||
- "docs/tutorials/**/*.md" | ||
- "docs/nodes/**/*.md" | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.12" | ||
|
||
- name: Install Dependencies | ||
run: | | ||
pip install python-frontmatter | ||
pip install justext | ||
- name: Generate Documentation Bundle | ||
shell: python | ||
env: | ||
SOURCES: ${{ toJSON(matrix.bundles.sources) }} | ||
BUNDLE: ${{ matrix.bundles.name }} | ||
run: | | ||
import os | ||
import glob | ||
import json | ||
import frontmatter | ||
import justext | ||
sources = json.loads(os.environ["SOURCES"]) | ||
output_filename = f"{os.environ["BUNDLE"]}-bundle.md" | ||
print(f"⚡️ Generating {output_filename}") | ||
with open(output_filename, "a") as output_file: | ||
for source in sources: | ||
print(f"🔎 looking for {source}") | ||
files = glob.glob(source, recursive=True) | ||
for file_path in files: | ||
print(f"🔁 merging {file_path}") | ||
with open(file_path, "r") as input_file: | ||
_, content = frontmatter.parse(input_file.read()) | ||
paragraphs = justext.justext(content, justext.get_stoplist("English")) | ||
for paragraph in paragraphs: | ||
if not paragraph.is_boilerplate: | ||
output_file.write(paragraph.text) | ||
output_file.write("\n") | ||
output_file.write("\n") | ||
print(f"📦 bundle {output_filename} generated") | ||
- name: Upload Documentation Bundle as Artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: ${{ matrix.bundles.name }}-bundle | ||
path: ${{ matrix.bundles.name }}-bundle.md |