Skip to content

Commit 0efb2b0

Browse files
authored
Merge branch 'main' into fix-git-release-title
2 parents f3b6d7a + 0e6317d commit 0efb2b0

31 files changed

+1065
-211
lines changed

.github/actions/mypy/action.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: 'MyPy'
2+
author: 'EnricoMi'
3+
description: 'A GitHub Action that runs mypy'
4+
5+
runs:
6+
using: 'composite'
7+
steps:
8+
- name: Set up Python
9+
uses: actions/setup-python@v4
10+
with:
11+
python-version: "3.x"
12+
- run: |
13+
python -m pip install --upgrade pip
14+
pip install -e .
15+
pip install -r requirements/types.txt
16+
shell: bash
17+
- uses: liskin/gh-problem-matcher-wrap@v2
18+
with:
19+
action: add
20+
linters: mypy
21+
- run: mypy --show-column-numbers github tests
22+
shell: bash
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: 'Pre-commit'
2+
author: 'EnricoMi'
3+
description: 'A GitHub Action that runs pre-commit'
4+
5+
runs:
6+
using: 'composite'
7+
steps:
8+
- uses: actions/setup-python@v4
9+
with:
10+
python-version: "3.x"
11+
# FIXME: pin pre-commit<4 pending PyCQA/docformatter#287
12+
- name: install pre-commit
13+
run: python -m pip install 'pre-commit<4'
14+
shell: bash
15+
- name: show environment
16+
run: python -m pip freeze --local
17+
shell: bash
18+
- uses: actions/cache@v4
19+
with:
20+
path: ~/.cache/pre-commit
21+
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
22+
- name: run pre-commit
23+
run: pre-commit run --show-diff-on-failure --color=always --all-files
24+
shell: bash
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: 'Sort classes'
2+
author: 'EnricoMi'
3+
description: 'A GitHub Action that sorts classes'
4+
5+
runs:
6+
using: 'composite'
7+
steps:
8+
- name: Set up Python
9+
uses: actions/setup-python@v4
10+
with:
11+
python-version: "3.12"
12+
- name: Set up dependencies
13+
run: |
14+
pip install -r requirements/scripts.txt
15+
shell: bash
16+
- name: Sort classes
17+
shell: bash
18+
run: |
19+
# Sort classes
20+
set -euo pipefail
21+
22+
echo "::group::Sort classes"
23+
python scripts/openapi.py index github openapi.index
24+
python scripts/sort_class.py openapi.index $(jq -r ".indices.class_to_descendants.GithubObject | @tsv" < openapi.index)
25+
echo "::endgroup::"

.github/workflows/auto-fix.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Auto Fix
2+
on:
3+
workflow_dispatch:
4+
permissions: {}
5+
6+
jobs:
7+
sort:
8+
name: "sort classes"
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: ./.github/actions/sort-classes
15+
continue-on-error: true
16+
- name: Commit and push changes
17+
run: |
18+
# Commit and push changes
19+
git config --local user.name "${{ github.actor }}"
20+
git config --local user.email "github-action-${{ github.actor }}@users.noreply.github.com"
21+
git commit -a -m "Sorting classes" || true
22+
git fetch origin $GITHUB_REF_NAME
23+
git rebase origin/$GITHUB_REF_NAME
24+
git push origin HEAD:$GITHUB_REF_NAME
25+
26+
mypy:
27+
runs-on: ubuntu-latest
28+
permissions:
29+
contents: write
30+
steps:
31+
- uses: actions/checkout@v4
32+
- uses: ./.github/actions/mypy
33+
continue-on-error: true
34+
- name: Commit and push changes
35+
run: |
36+
# Commit and push changes
37+
git config --local user.name "${{ github.actor }}"
38+
git config --local user.email "github-action-${{ github.actor }}@users.noreply.github.com"
39+
git commit -a -m "Fixing MyPy" || true
40+
git fetch origin $GITHUB_REF_NAME
41+
git rebase origin/$GITHUB_REF_NAME
42+
git push origin HEAD:$GITHUB_REF_NAME
43+
44+
pre-commit-fix:
45+
runs-on: ubuntu-latest
46+
permissions:
47+
contents: write
48+
steps:
49+
- uses: actions/checkout@v4
50+
- uses: ./.github/actions/pre-commit
51+
continue-on-error: true
52+
- name: Commit and push changes
53+
run: |
54+
# Commit and push changes
55+
git config --local user.name "${{ github.actor }}"
56+
git config --local user.email "github-action-${{ github.actor }}@users.noreply.github.com"
57+
git commit -a -m "Fixing pre-compile" || true
58+
git fetch origin $GITHUB_REF_NAME
59+
git rebase origin/$GITHUB_REF_NAME
60+
git push origin HEAD:$GITHUB_REF_NAME

.github/workflows/ci.yml

Lines changed: 141 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
env:
1010
openapi_api: api.github.com
1111
openapi_version: 2022-11-28
12+
permissions: {}
1213

1314
jobs:
1415
build:
@@ -67,6 +68,56 @@ jobs:
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"

.github/workflows/lint.yml

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,20 @@ on:
66
- release-v*
77
pull_request:
88
merge_group:
9+
permissions: {}
910

1011
jobs:
1112
mypy:
1213
runs-on: ubuntu-latest
1314
steps:
1415
- uses: actions/checkout@v4
15-
- name: Set up Python
16-
uses: actions/setup-python@v4
17-
with:
18-
python-version: "3.x"
19-
- run: |
20-
python -m pip install --upgrade pip
21-
pip install -e .
22-
pip install -r requirements/types.txt
23-
- uses: liskin/gh-problem-matcher-wrap@v2
24-
with:
25-
action: add
26-
linters: mypy
27-
- run: mypy --show-column-numbers github tests
16+
- uses: ./.github/actions/mypy
2817

2918
pre-commit:
3019
runs-on: ubuntu-latest
3120
steps:
3221
- uses: actions/checkout@v4
33-
- uses: actions/setup-python@v4
34-
with:
35-
python-version: "3.x"
36-
# FIXME: pin pre-commit<4 pending PyCQA/docformatter#287
37-
- name: install pre-commit
38-
run: python -m pip install 'pre-commit<4'
39-
- name: show environment
40-
run: python -m pip freeze --local
41-
- uses: actions/cache@v4
42-
with:
43-
path: ~/.cache/pre-commit
44-
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
45-
- name: run pre-commit
46-
run: pre-commit run --show-diff-on-failure --color=always --all-files
22+
- uses: ./.github/actions/pre-commit
4723

4824
docs:
4925
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)