From 26737058443e7f1a9fb9ebcda48abe09e0cb5aab Mon Sep 17 00:00:00 2001 From: Thomas Fish Date: Fri, 6 Sep 2024 18:54:28 +0100 Subject: [PATCH] Update workflows --- .github/workflows/README from docs.yaml | 38 ++++++++++++++++++ .github/workflows/generate_help_docs.yaml | 33 ++++++++++++++++ .github/workflows/generate_readme.yaml | 47 ----------------------- 3 files changed, 71 insertions(+), 47 deletions(-) create mode 100644 .github/workflows/README from docs.yaml create mode 100644 .github/workflows/generate_help_docs.yaml delete mode 100644 .github/workflows/generate_readme.yaml diff --git a/.github/workflows/README from docs.yaml b/.github/workflows/README from docs.yaml new file mode 100644 index 0000000..9952a5a --- /dev/null +++ b/.github/workflows/README from docs.yaml @@ -0,0 +1,38 @@ +name: Generate README + +on: + pull_request: + paths: + - "docs/**/*" + workflow_run: + workflows: + - "generate_help_docs" + +jobs: + make-README: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.12"] + steps: + - uses: actions/checkout@v4 + - name: "Fill template" + working-directory: "docs/" + timeout-minutes: 0.1 + run: | + sub_doc_parts_from() { + template="$1" + directory="$2" + + for file in "$directory"/*; do + if [ -f "$file" ]; then + placeholder="{{ $(echo "${file^^}" | tr ./ _) }}" + echo "Saving $file to $placeholder with expanded environment variables" >&2 + # Export file contents to text following a pattern in template.md, e.g.: + # section/test_file.md would replace "{{ SECTION_TEST_FILE_MD }}"" + template="${template//"$placeholder"/"$(<"$file")"}" + fi + done + echo "$template" + } + sub_doc_parts_from "$(sub_doc_parts_from "$(../README.md diff --git a/.github/workflows/generate_help_docs.yaml b/.github/workflows/generate_help_docs.yaml new file mode 100644 index 0000000..c38677d --- /dev/null +++ b/.github/workflows/generate_help_docs.yaml @@ -0,0 +1,33 @@ +name: Generate README + +on: + pull_request: + paths: + - "src/sim_recon/cli/parsing/*" + - "src/sim_recon/settings/formatting.py" + +jobs: + generate-help-docs: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.12"] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Copy template + run: cp -f docs/template.md README.md + - name: Install (without dependencies) + run: | + python -m pip install --upgrade pip + python -m pip install . --no-deps + - name: Ensure README exists + run: touch README.md + - name: Getting help strings from package + run: | + python -m sim_recon.cli.parsing.otf '--help' >docs/help/sim_otf.txt + python -m sim_recon.cli.parsing.recon '--help' >docs/help/sim_recon.txt + python -m sim_recon.cli.parsing.otf_view '--help' >docs/help/otf_view.txt diff --git a/.github/workflows/generate_readme.yaml b/.github/workflows/generate_readme.yaml deleted file mode 100644 index 2c836d7..0000000 --- a/.github/workflows/generate_readme.yaml +++ /dev/null @@ -1,47 +0,0 @@ -name: Generate README - -on: - pull_request: - paths: - - "docs/*.md" - - "src/sim_recon/cli/parsing.py" - - "src/sim_recon/settings/formatting.py" - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.12"] - steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - name: Copy template - run: cp -f docs/template.md README.md - - name: Install (without dependencies) - run: | - python -m pip install --upgrade pip - python -m pip install . --no-deps - - name: Get argparse help outputs - run: | - export OTF_HELP_OUTPUT=$(python -c "from sim_recon.cli.parsing import parse_otf_args; parse_otf_args(("--help",))") - export RECON_HELP_OUTPUT=$(python -c "from sim_recon.cli.parsing import parse_recon_args; parse_recon_args(("--help",))") - - name: Get sections - run: | - cd docs/ - for file in sections/*; do - if [ -f "$file" ]; then - var_name="$(echo "${file^^}" | tr ./ _)" - echo "Saving $file to $var_name" - # Export file contents to an environment variable named from the path, e.g.: - # 'section/test_file.md' would be 'SECTION_TEST_FILE_MD' - export "${!var_name}"="$(<"$file")" - envsubst < "${!var_name}" # Substitute environment variables into each section (not other sections) - fi - done - - name: Fill template - run: | - envsubst < README.md