|
| 1 | +name: Update doc DB |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: read |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + python-version: |
| 10 | + description: Target python version to generate doc db for |
| 11 | + type: string |
| 12 | + default: "3.13.9" |
| 13 | + |
| 14 | +defaults: |
| 15 | + run: |
| 16 | + shell: bash |
| 17 | + working-directory: ./crates/rustpython-doc |
| 18 | + |
| 19 | +jobs: |
| 20 | + generate: |
| 21 | + runs-on: ${{ matrix.os }} |
| 22 | + strategy: |
| 23 | + matrix: |
| 24 | + os: |
| 25 | + - ubuntu-latest |
| 26 | + - windows-latest |
| 27 | + - macos-latest |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 30 | + with: |
| 31 | + persist-credentials: false |
| 32 | + sparse-checkout: | |
| 33 | + crates/rustpython-doc |
| 34 | +
|
| 35 | + - uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0 |
| 36 | + with: |
| 37 | + python-version: ${{ inputs.python-version }} |
| 38 | + |
| 39 | + - name: Generate docs |
| 40 | + run: python ./generate.py |
| 41 | + |
| 42 | + - uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 |
| 43 | + with: |
| 44 | + name: doc-db-${{ inputs.python-version }}-${{ matrix.os }} |
| 45 | + path: "crates/rustpython-doc/generated/*.json" |
| 46 | + if-no-files-found: error |
| 47 | + retention-days: 7 |
| 48 | + overwrite: true |
| 49 | + |
| 50 | + merge: |
| 51 | + runs-on: ubuntu-latest |
| 52 | + needs: generate |
| 53 | + steps: |
| 54 | + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 55 | + with: |
| 56 | + persist-credentials: false |
| 57 | + sparse-checkout: | |
| 58 | + crates/rustpython-doc |
| 59 | +
|
| 60 | + - name: Download generated doc DBs |
| 61 | + uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 |
| 62 | + with: |
| 63 | + pattern: "doc-db-${{ inputs.python-version }}-**" |
| 64 | + path: crates/rustpython-doc/generated/ |
| 65 | + merge-multiple: true |
| 66 | + |
| 67 | + - name: Transform JSON |
| 68 | + run: | |
| 69 | + # Merge all artifacts |
| 70 | + jq -s "add" --sort-keys generated/*.json > generated/merged.json |
| 71 | +
|
| 72 | + # Format merged json for the phf macro |
| 73 | + jq -r 'to_entries[] | " \(.key | @json) => \(.value | @json),"' generated/merged.json > generated/raw_entries.txt |
| 74 | +
|
| 75 | + OUTPUT_FILE='src/data.inc.rs' |
| 76 | +
|
| 77 | + echo -n '' > $OUTPUT_FILE |
| 78 | +
|
| 79 | + echo '// This file was auto-generated by `.github/workflows/update-doc-db.yml`.' >> $OUTPUT_FILE |
| 80 | + echo "// CPython version: ${{ inputs.python-version }}" >> $OUTPUT_FILE |
| 81 | + echo '// spell-checker: disable' >> $OUTPUT_FILE |
| 82 | +
|
| 83 | + echo '' >> $OUTPUT_FILE |
| 84 | +
|
| 85 | + echo "pub static DB: phf::Map<&'static str, &'static str> = phf::phf_map! {" >> $OUTPUT_FILE |
| 86 | + cat generated/raw_entries.txt >> $OUTPUT_FILE |
| 87 | + echo '};' >> $OUTPUT_FILE |
| 88 | +
|
| 89 | + - uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 |
| 90 | + with: |
| 91 | + name: doc-db-${{ inputs.python-version }} |
| 92 | + path: "crates/rustpython-doc/src/data.inc.rs" |
| 93 | + if-no-files-found: error |
| 94 | + retention-days: 7 |
| 95 | + overwrite: true |
0 commit comments