11name : Update doc DB
22
33permissions :
4- contents : read
4+ contents : write
55
66on :
77 workflow_dispatch :
1010 description : Target python version to generate doc db for
1111 type : string
1212 default : " 3.13.9"
13+ ref :
14+ description : Branch to commit to (leave empty for current branch)
15+ type : string
16+ default : " "
1317
1418defaults :
1519 run :
1620 shell : bash
17- working-directory : ./crates/rustpython-doc
1821
1922jobs :
2023 generate :
@@ -30,19 +33,19 @@ jobs:
3033 with :
3134 persist-credentials : false
3235 sparse-checkout : |
33- crates/rustpython- doc
36+ crates/doc
3437
3538 - uses : actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
3639 with :
3740 python-version : ${{ inputs.python-version }}
3841
3942 - name : Generate docs
40- run : python . /generate.py
43+ run : python crates/doc /generate.py
4144
4245 - uses : actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
4346 with :
4447 name : doc-db-${{ inputs.python-version }}-${{ matrix.os }}
45- path : " crates/rustpython- doc/generated/*.json"
48+ path : " crates/doc/generated/*.json"
4649 if-no-files-found : error
4750 retention-days : 7
4851 overwrite : true
@@ -53,26 +56,25 @@ jobs:
5356 steps :
5457 - uses : actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
5558 with :
56- persist-credentials : false
57- sparse-checkout : |
58- crates/rustpython-doc
59+ ref : ${{ inputs.ref || github.ref }}
60+ token : ${{ secrets.AUTO_COMMIT_PAT }}
5961
6062 - name : Download generated doc DBs
6163 uses : actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
6264 with :
6365 pattern : " doc-db-${{ inputs.python-version }}-**"
64- path : crates/rustpython- doc/generated/
66+ path : crates/doc/generated/
6567 merge-multiple : true
6668
6769 - name : Transform JSON
6870 run : |
6971 # Merge all artifacts
70- jq -s "add" --sort-keys generated/*.json > generated/merged.json
72+ jq -s "add" --sort-keys crates/doc/ generated/*.json > crates/doc/ generated/merged.json
7173
7274 # Format merged json for the phf macro
73- jq -r 'to_entries[] | " \(.key | @json) => \(.value | @json),"' generated/merged.json > generated/raw_entries.txt
75+ jq -r 'to_entries[] | " \(.key | @json) => \(.value | @json),"' crates/doc/ generated/merged.json > crates/doc/ generated/raw_entries.txt
7476
75- OUTPUT_FILE='src/data.inc.rs'
77+ OUTPUT_FILE='crates/doc/ src/data.inc.rs'
7678
7779 echo -n '' > $OUTPUT_FILE
7880
@@ -83,13 +85,24 @@ jobs:
8385 echo '' >> $OUTPUT_FILE
8486
8587 echo "pub static DB: phf::Map<&'static str, &'static str> = phf::phf_map! {" >> $OUTPUT_FILE
86- cat generated/raw_entries.txt >> $OUTPUT_FILE
88+ cat crates/doc/ generated/raw_entries.txt >> $OUTPUT_FILE
8789 echo '};' >> $OUTPUT_FILE
8890
8991 - uses : actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
9092 with :
9193 name : doc-db-${{ inputs.python-version }}
92- path : " crates/rustpython- doc/src/data.inc.rs"
94+ path : " crates/doc/src/data.inc.rs"
9395 if-no-files-found : error
9496 retention-days : 7
9597 overwrite : true
98+
99+ - name : Commit and push (non-main branches only)
100+ if : github.ref != 'refs/heads/main' && inputs.ref != 'main'
101+ run : |
102+ git config user.name "github-actions[bot]"
103+ git config user.email "github-actions[bot]@users.noreply.github.com"
104+ if [ -n "$(git status --porcelain)" ]; then
105+ git add crates/doc/src/data.inc.rs
106+ git commit -m "Update doc DB for CPython ${{ inputs.python-version }}"
107+ git push
108+ fi
0 commit comments