Repository navigation
165 lines (145 loc) · 5.24 KB
/
Copy pathupdate-doc-db.yml
File metadata and controls
165 lines (145 loc) · 5.24 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: Update doc DB
permissions: {}
on:
workflow_dispatch:
inputs:
python-version:
description: Target python version to generate doc db for
type: string
default: "3.15.0"
base-ref:
description: Base branch to create the update branch from
type: string
default: "main"
artifact-only:
description: Generate artifacts from main without pushing or creating a PR
type: boolean
default: false
defaults:
run:
shell: bash
jobs:
generate:
permissions:
contents: read
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
steps:
- name: Validate artifact-only source
if: ${{ inputs.artifact-only }}
env:
BASE_REF: ${{ inputs.base-ref }}
run: |
if [ "$GITHUB_REF" != "refs/heads/main" ] || [ "$BASE_REF" != "main" ]; then
echo 'Artifact-only generation requires the main workflow ref and main base.' >&2
exit 1
fi
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
ref: ${{ github.sha }}
sparse-checkout: |
crates/doc
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: ${{ inputs.python-version }}
- name: Generate docs
run: python crates/doc/generate.py
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
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
outputs:
base-sha: ${{ steps.base.outputs.sha }}
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
ref: ${{ inputs.artifact-only && github.sha || inputs.base-ref }}
- name: Record merge base
id: base
run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Download generated doc DBs
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
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 as a sorted const slice
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'
# shellcheck disable=SC2016
{
echo '// This file was auto-generated by `.github/workflows/update-doc-db.yml`.'
echo "// CPython version: ${PYTHON_VERSION}"
echo '// spell-checker: disable'
echo ''
echo '#[rustfmt::skip]'
echo 'pub const DB: &[(&str, &str)] = &['
cat crates/doc/generated/raw_entries.txt
echo '];'
} > "$OUTPUT_FILE"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: doc-db-${{ inputs.python-version }}
path: "crates/doc/src/data.inc.rs"
if-no-files-found: error
retention-days: 7
overwrite: true
publish:
if: ${{ !inputs.artifact-only }}
runs-on: ubuntu-latest
needs: merge
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: true
ref: ${{ needs.merge.outputs.base-sha }}
- name: Create update branch
run: git switch -c "update-doc-${PYTHON_VERSION}"
env:
PYTHON_VERSION: ${{ inputs.python-version }}
- name: Download merged doc DB
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: doc-db-${{ inputs.python-version }}
path: crates/doc/src/
- name: Commit, push and create PR
env:
GH_TOKEN: ${{ github.token }}
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