|
name: Update doc DB |
|
|
|
permissions: |
|
contents: write |
|
|
|
on: |
|
workflow_dispatch: |
|
inputs: |
|
python-version: |
|
description: Target python version to generate doc db for |
|
type: string |
|
default: "3.13.9" |
|
ref: |
|
description: Branch to commit to (leave empty for current branch) |
|
type: string |
|
default: "" |
|
|
|
defaults: |
|
run: |
|
shell: bash |
|
|
|
jobs: |
|
generate: |
|
runs-on: ${{ matrix.os }} |
|
strategy: |
|
matrix: |
|
os: |
|
- ubuntu-latest |
|
- windows-latest |
|
- macos-latest |
|
steps: |
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 |
|
with: |
|
persist-credentials: false |
|
sparse-checkout: | |
|
crates/doc |
|
|
|
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0 |
|
with: |
|
python-version: ${{ inputs.python-version }} |
|
|
|
- name: Generate docs |
|
run: python crates/doc/generate.py |
|
|
|
- uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 |
|
with: |
|
name: doc-db-${{ inputs.python-version }}-${{ matrix.os }} |
|
path: "crates/doc/generated/*.json" |
|
if-no-files-found: error |
|
retention-days: 7 |
|
overwrite: true |
|
|
|
merge: |
|
runs-on: ubuntu-latest |
|
needs: generate |
|
steps: |
|
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 |
|
with: |
|
ref: ${{ inputs.ref || github.ref }} |
|
token: ${{ secrets.AUTO_COMMIT_PAT }} |
|
sparse-checkout: | |
|
crates/doc |
|
|
|
- name: Download generated doc DBs |
|
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 |
|
with: |
|
pattern: "doc-db-${{ inputs.python-version }}-**" |
|
path: crates/doc/generated/ |
|
merge-multiple: true |
|
|
|
- name: Transform JSON |
|
run: | |
|
# Merge all artifacts |
|
jq -s "add" --sort-keys crates/doc/generated/*.json > crates/doc/generated/merged.json |
|
|
|
# Format merged json for the phf macro |
|
jq -r 'to_entries[] | " \(.key | @json) => \(.value | @json),"' crates/doc/generated/merged.json > crates/doc/generated/raw_entries.txt |
|
|
|
OUTPUT_FILE='crates/doc/src/data.inc.rs' |
|
|
|
echo -n '' > $OUTPUT_FILE |
|
|
|
echo '// This file was auto-generated by `.github/workflows/update-doc-db.yml`.' >> $OUTPUT_FILE |
|
echo "// CPython version: ${{ inputs.python-version }}" >> $OUTPUT_FILE |
|
echo '// spell-checker: disable' >> $OUTPUT_FILE |
|
|
|
echo '' >> $OUTPUT_FILE |
|
|
|
echo "pub static DB: phf::Map<&'static str, &'static str> = phf::phf_map! {" >> $OUTPUT_FILE |
|
cat crates/doc/generated/raw_entries.txt >> $OUTPUT_FILE |
|
echo '};' >> $OUTPUT_FILE |
|
|
|
- uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 |
|
with: |
|
name: doc-db-${{ inputs.python-version }} |
|
path: "crates/doc/src/data.inc.rs" |
|
if-no-files-found: error |
|
retention-days: 7 |
|
overwrite: true |
|
|
|
- name: Commit and push (non-main branches only) |
|
if: github.ref != 'refs/heads/main' && inputs.ref != 'main' |
|
run: | |
|
git config user.name "github-actions[bot]" |
|
git config user.email "github-actions[bot]@users.noreply.github.com" |
|
if [ -n "$(git status --porcelain)" ]; then |
|
git add crates/doc/src/data.inc.rs |
|
git commit -m "Update doc DB for CPython ${{ inputs.python-version }}" |
|
git push |
|
fi |