forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
123 lines (104 loc) · 3.97 KB
/
update-doc-db.yml
File metadata and controls
123 lines (104 loc) · 3.97 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: Update doc DB
permissions:
contents: write
pull-requests: write
on:
workflow_dispatch:
inputs:
python-version:
description: Target python version to generate doc db for
type: string
default: "3.14.3"
base-ref:
description: Base branch to create the update branch from
type: string
default: "main"
defaults:
run:
shell: bash
jobs:
generate:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
steps:
- uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v6.0.1
with:
persist-credentials: false
sparse-checkout: |
crates/doc
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: ${{ inputs.python-version }}
- name: Generate docs
run: python crates/doc/generate.py
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.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@0c366fd6a839edf440554fa01a7085ccba70ac98 # v6.0.1
with:
ref: ${{ inputs.base-ref }}
token: ${{ secrets.AUTO_COMMIT_PAT }}
- name: Create update branch
env:
PYTHON_VERSION: ${{ inputs.python-version }}
run: git switch -c "update-doc-${PYTHON_VERSION}"
- name: Download generated doc DBs
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
with:
pattern: "doc-db-${{ inputs.python-version }}-**"
path: crates/doc/generated/
merge-multiple: true
- name: Transform JSON
env:
PYTHON_VERSION: ${{ inputs.python-version }}
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: ${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@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.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, push and create PR
env:
GH_TOKEN: ${{ secrets.AUTO_COMMIT_PAT }}
PYTHON_VERSION: ${{ inputs.python-version }}
BASE_REF: ${{ inputs.base-ref }}
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 ${PYTHON_VERSION}"
git push -u origin HEAD
gh pr create \
--base "${BASE_REF}" \
--title "Update doc DB for CPython ${PYTHON_VERSION}" \
--body "Auto-generated by update-doc-db workflow."
fi