-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (88 loc) · 3.55 KB
/
Copy pathpipeline_docs.yml
File metadata and controls
103 lines (88 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# 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