Generate README with GH Actions #5
Workflow file for this run
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
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 |