99env :
1010 openapi_api : api.github.com
1111 openapi_version : 2022-11-28
12+ permissions : {}
1213
1314jobs :
1415 build :
6768 run : false
6869 shell : bash
6970
71+ index :
72+ name : " Check verbs"
73+ needs : " test_success"
74+ if : github.event_name == 'pull_request'
75+ runs-on : ubuntu-latest
76+ steps :
77+ - uses : actions/checkout@v3
78+ with :
79+ path : head
80+ - uses : actions/checkout@v3
81+ with :
82+ ref : ${{ github.event.pull_request.base.sha }}
83+ path : base
84+ - name : Set up Python
85+ uses : actions/setup-python@v4
86+ with :
87+ python-version : " 3.12"
88+ - name : Set up dependencies
89+ run : |
90+ pip install -r head/requirements/scripts.txt
91+ - name : Check verbs
92+ shell : bash
93+ run : |
94+ # Check verbs
95+ set -euo pipefail
96+
97+ echo "::group::Head verb checking:"
98+ python head/scripts/openapi.py index --check-verbs head/github openapi.head.index | tee verbs.head.txt
99+ echo "::endgroup::"
100+
101+ echo "::group::Base verb checking:"
102+ python head/scripts/openapi.py index --check-verbs base/github openapi.base.index | tee verbs.base.txt
103+ echo "::endgroup::"
104+
105+ if ! (diff verbs.base.txt verbs.head.txt > diff.txt)
106+ then
107+ echo ""
108+ echo "Difference:"
109+ cat diff.txt
110+ echo ""
111+ echo "To fix this revisit the verbs in :calls: doc-string line of the respective method."
112+ echo ""
113+ echo "Fix warnings like 'Not found any … call in …' by adding the method name "
114+ echo "and verb to the 'known method verbs' section in github/openapi.index.json."
115+ echo ""
116+ echo "Fix warnings like 'Method … is known to call …' by fixing "
117+ echo "the doc-string or github/openapi.index.json."
118+ false
119+ fi
120+
70121 schemas :
71122 name : " Add schemas"
72123 needs : " test_success"
@@ -88,7 +139,11 @@ jobs:
88139 run : |
89140 pip install -r head/requirements/scripts.txt
90141 - name : Add schemas
142+ shell : bash
91143 run : |
144+ # Add schemas
145+ set -euo pipefail
146+
92147 python head/scripts/openapi.py fetch ${{ env.openapi_api }} ${{ env.openapi_version }} openapi.json
93148
94149 echo "::group::Head schema suggestions:"
@@ -101,8 +156,29 @@ jobs:
101156 python head/scripts/openapi.py suggest schemas openapi.json openapi.base.index | tee schemas.base.txt
102157 echo "::endgroup::"
103158
104- echo "Difference:"
105- diff schemas.base.txt schemas.head.txt
159+ if ! (diff schemas.base.txt schemas.head.txt > diff.txt)
160+ then
161+ echo ""
162+ echo "Difference:"
163+ cat diff.txt
164+ echo ""
165+ (grep -E -e "^> Class \w+:$" diff.txt | sed -E -e "s/^> Class (\w+):$/\1/" || true) | while read class
166+ do
167+ echo "::group::Add schema to $class:"
168+ python head/scripts/openapi.py suggest schemas --add openapi.json openapi.head.index "$class" > /dev/null
169+ (cd head; git diff; git reset --hard --quiet HEAD)
170+ echo "::endgroup::"
171+ done
172+ echo ""
173+ echo "Run the following commands to add the suggested schemas:"
174+ echo "python3 -m venv venv"
175+ echo "source venv/bin/activate"
176+ echo "pip install -r requirements/scripts.txt"
177+ echo python scripts/openapi.py fetch api.github.com 2022-11-28 openapi.json
178+ echo python scripts/openapi.py index github openapi.json openapi.index
179+ echo python scripts/openapi.py suggest schemas --add openapi.json openapi.index $(grep -E -e "^> Class \w+:$" diff.txt | sed -E -e "s/^> Class (\w+):$/\1/")
180+ false
181+ fi
106182
107183 implementations :
108184 name : " Implement schemas"
@@ -125,7 +201,11 @@ jobs:
125201 run : |
126202 pip install -r head/requirements/scripts.txt
127203 - name : Add implementations
204+ shell : bash
128205 run : |
206+ # Add implementations
207+ set -euo pipefail
208+
129209 python head/scripts/openapi.py fetch ${{ env.openapi_api }} ${{ env.openapi_version }} openapi.json
130210
131211 echo "::group::Head implementations:"
@@ -138,32 +218,73 @@ jobs:
138218 python head/scripts/openapi.py --dry-run apply --tests base/github openapi.json openapi.base.index | tee implementation.base.txt
139219 echo "::endgroup::"
140220
141- echo "Difference:"
142- diff implementation.base.txt implementation.head.txt
221+ if ! (diff <(sed -E -e "s/^[@]{2} .+ [@]{2}$/…/" -e "s%[(]base/github/%(github/%" -e "s%Test base/%Test %" implementation.base.txt) <(sed -E -e "s/^[@]{2} .+ [@]{2}$/…/" -e "s%[(]head/github/%(github/%" -e "s%Test head/%Test %" implementation.head.txt) > diff.txt)
222+ then
223+ echo ""
224+ echo "Difference:"
225+ cat diff.txt
226+ echo ""
227+ (grep -E -e "^> Class \w+ changed$" diff.txt | sed -E -e "s/^> Class (\w+) changed$/\1/" || true) | while read class
228+ do
229+ echo "::group::Apply schema to $class:"
230+ python head/scripts/openapi.py apply --tests --new-schemas create-class head/github openapi.json openapi.head.index "$class" > /dev/null
231+ (cd head; git diff; git reset --hard --quiet HEAD)
232+ echo "::endgroup::"
233+ done
234+ echo ""
235+ echo "Run the following commands to apply the schemas:"
236+ echo "python3 -m venv venv"
237+ echo "source venv/bin/activate"
238+ echo "pip install -r requirements/scripts.txt"
239+ echo python scripts/openapi.py fetch api.github.com 2022-11-28 openapi.json
240+ echo python scripts/openapi.py index github openapi.index
241+ echo python scripts/openapi.py apply --tests --new-schemas create-class github openapi.json openapi.index $(grep -E -e "^> Class \w+:$" diff.txt | sed -E -e "s/^> Class (\w+):$/\1/")
242+ (grep -E -e "^> Test .+ changed$" diff.txt | sed -E -e "s/^> Test (.+) changed$/\1/" || true) | while read test
243+ do
244+ echo python scripts/prepare-for-update-assertions.py "$test" testAttributes
245+ echo bash scripts/update-assertions.sh "$test" testAttributes
246+ done
247+ echo pre-commit run --all-files
248+ echo ""
249+ echo "You may need to fix the tests afterwards:"
250+ echo pip install . -r requirements/test.txt
251+ echo pytest tests
252+ echo
253+ false
254+ fi
143255
144256 sort :
145257 name : " Sort classes"
146258 needs : " test_success"
147259 runs-on : ubuntu-latest
148260 steps :
149261 - uses : actions/checkout@v3
150- - name : Set up Python
151- uses : actions/setup-python@v4
152- with :
153- python-version : " 3.12"
154- - name : Set up dependencies
155- run : |
156- pip install -r requirements/scripts.txt
157- - name : Sort classes
262+ - uses : ./.github/actions/sort-classes
263+ - name : changes
158264 run : |
159- echo "::group::Sort classes"
160- python scripts/openapi.py fetch ${{ env.openapi_api }} ${{ env.openapi_version }} openapi.json
161- python scripts/openapi.py index github openapi.json openapi.index
162- python scripts/sort_class.py openapi.index $(jq -r ".indices.class_to_descendants.GithubObject | @tsv" < openapi.index)
163- echo "::endgroup::"
164-
165- echo "Changes:"
166- git diff
265+ if ! (git diff --exit-code > diff.txt)
266+ then
267+ echo ""
268+ echo "Changes:"
269+ cat diff.txt
270+ git reset --hard --quiet HEAD
271+ echo ""
272+ echo "To fix this, run the following commands:"
273+ echo "python3 -m venv venv"
274+ echo "source venv/bin/activate"
275+ echo "pip install -r requirements/scripts.txt"
276+ echo python scripts/openapi.py index github openapi.index
277+ for class in $(jq -r ".indices.class_to_descendants.GithubObject | @tsv" < openapi.index)
278+ do
279+ python scripts/sort_class.py openapi.index $class > /dev/null
280+ if ! git diff --quiet --exit-code
281+ then
282+ echo python scripts/sort_class.py openapi.index $class
283+ git reset --hard --quiet HEAD
284+ fi
285+ done
286+ false
287+ fi
167288
168289 event_file :
169290 name : " Event File"
0 commit comments