-
Notifications
You must be signed in to change notification settings - Fork 3.3k
106 lines (92 loc) · 3.45 KB
/
Copy pathconsistency.yml
File metadata and controls
106 lines (92 loc) · 3.45 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
name: API.md Consistency
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- "sdk/**"
permissions:
contents: read
jobs:
consistency:
if: ${{ !github.event.pull_request.draft }}
runs-on: ubuntu-latest
outputs:
changed_count: ${{ steps.changed.outputs.count || '0' }}
mismatch_count: ${{ steps.consistency.outputs.mismatch_count || '0' }}
missing_count: ${{ steps.consistency.outputs.missing_count || '0' }}
issue_count: ${{ steps.consistency.outputs.issue_count || '0' }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: "20"
- name: Find changed SDK packages
id: changed
env:
API_MD_BASE_REF: ${{ github.event.pull_request.base.ref }}
API_MD_PACKAGES_FILE: .artifacts/affected_package_dirs.txt
API_MD_CHANGED_FILE: .artifacts/changed_package_dirs.txt
shell: bash
run: |
set -euo pipefail
node scripts/api_md_workflow/find_affected.js
- name: Generate API.md for affected packages
if: ${{ steps.changed.outputs.count != '0' }}
env:
API_MD_PACKAGES_FILE: .artifacts/affected_package_dirs.txt
shell: bash
run: |
set -euo pipefail
node scripts/api_md_workflow/regenerate.js
- name: Check API.md consistency
id: consistency
env:
API_MD_PACKAGES_FILE: .artifacts/affected_package_dirs.txt
API_MD_MISMATCHES_FILE: .artifacts/mismatched_api_files.txt
API_MD_MISSING_FILE: .artifacts/missing_api_files.txt
shell: bash
run: |
set -euo pipefail
if [ "${{ steps.changed.outputs.count }}" = "0" ]; then
echo "mismatch_count=0" >> "$GITHUB_OUTPUT"
echo "missing_count=0" >> "$GITHUB_OUTPUT"
echo "issue_count=0" >> "$GITHUB_OUTPUT"
exit 0
fi
node scripts/api_md_workflow/find_mismatches.js
- name: Fail when API.md is out of date
if: ${{ steps.changed.outputs.count != '0' && steps.consistency.outputs.issue_count != '0' }}
shell: bash
run: |
set -euo pipefail
print_issues() {
local title="$1"
local issues_file="$2"
if [ ! -s "$issues_file" ]; then
return
fi
echo "$title"
while IFS= read -r api_file; do
[ -n "$api_file" ] || continue
package_dir="${api_file%/API.md}"
package_name="$(basename "$package_dir")"
echo "- ${package_dir}"
echo " API.md: ${api_file}"
echo " Regenerate: python scripts/generate_api_text.py ${package_name}"
done < "$issues_file"
echo
}
echo "Generated API.md does not match committed API.md, or API.md is missing, for one or more affected packages."
echo
print_issues "Mismatched packages:" ".artifacts/mismatched_api_files.txt"
print_issues "Missing API.md packages:" ".artifacts/missing_api_files.txt"
echo "To regenerate API.md locally, run the command shown for each package from the repository root."
exit 1