First version of pipeline doc generator finished. Through github acti… #11
This file contains hidden or 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
| # Changes to consider: | |
| # The workflow is triggered manually or on push. Could change this to trigger on pull request to main/dev branches instead, to ensure docs are generated before merging. | |
| name: Pipeline Docs Generation | |
| on: | |
| pull_request: | |
| paths: &doc_paths | |
| - src/pipelines/**/*.py | |
| - .github/scripts/pipeline_docs_ast.py | |
| - .github/scripts/pipeline_docs_latex_gen.py | |
| - .github/workflows/pipeline_docs.yml | |
| push: | |
| branches: pipeline-docs | |
| paths: *doc_paths | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| generate-docs: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Retrieve modified/new files | |
| id: get_files | |
| shell: bash | |
| run: | | |
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
| base_sha="${{ github.event.pull_request.base.sha }}" | |
| git diff --name-only "$base_sha" "${{ github.sha }}" > modified_files.txt | |
| elif [[ "${{ github.event_name }}" == "push" && "${{ github.event.before }}" != "" && "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]] && git cat-file -e "${{ github.event.before }}" 2>/dev/null; then | |
| git diff --name-only "${{ github.event.before }}" "${{ github.sha }}" > modified_files.txt | |
| else | |
| git ls-files 'src/pipelines/*.py' 'src/pipelines/**/*.py' > modified_files.txt | |
| fi | |
| cat modified_files.txt | |
| - name: Retrieve pipeline python files | |
| id: get_pipeline_files | |
| shell: bash | |
| run: | | |
| grep '^src/pipelines/.*\.py$' modified_files.txt > pipeline_scripts.txt || true | |
| if [ -s pipeline_scripts.txt ]; then | |
| cat pipeline_scripts.txt | |
| else | |
| echo "no_scripts=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Exit if no pipeline scripts | |
| if: steps.get_pipeline_files.outputs.no_scripts == 'true' | |
| run: exit 0 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Generate pipeline docs | |
| shell: bash | |
| run: | | |
| mkdir -p docs/pipelines | |
| rm -f docs/pipelines/.gitkeep | |
| while IFS= read -r script; do | |
| [[ -f "$script" ]] || continue | |
| stem="$(basename "$script" .py)" | |
| tex_out="docs/pipelines/${stem}.tex" | |
| json_payload="$(python .github/scripts/pipeline_docs_ast.py "$script")" | |
| if printf '%s' "$json_payload" | python -c "import json, sys; payload = json.load(sys.stdin); sys.exit(0 if 'error' not in payload else 1)" | |
| then | |
| printf '%s' "$json_payload" | python .github/scripts/pipeline_docs_latex_gen.py "$tex_out" | |
| fi | |
| done < pipeline_scripts.txt | |
| - name: Commit generated docs | |
| if: steps.get_pipeline_files.outputs.no_scripts != 'true' && github.event_name != 'pull_request' | |
| shell: bash | |
| run: | | |
| if git diff --quiet -- docs/pipelines; then | |
| exit 0 | |
| fi | |
| git config user.name "github-actions" | |
| git config user.email "github-actions@github.com" | |
| git add docs/pipelines | |
| git diff --cached --quiet || git commit -m "Update pipeline docs" | |
| git push | |
| - name: Upload generated docs | |
| if: steps.get_pipeline_files.outputs.no_scripts != 'true' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pipeline-docs | |
| path: docs/pipelines | |
| if-no-files-found: ignore |