[CI] Add nicer OpenAPI diffs (#7002)

* add diff action

* Update api_version.py

* always diff schemas

* move model lookup to subpath

* Add diff to step summary

* fix arg name

* use echo step instead

* split action and fail curl

* fail if download not possible

* capture code

* remove wrong syntax

* decrease download number

* revert qc

* extend version_check

* fix exit cond

* fix link

* add dummy change

* Update api_version.py

* use html for format
This commit is contained in:
Matthias Mair 2024-07-17 15:45:26 +02:00 committed by GitHub
parent 547fa179c5
commit 44a5f76213
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 3 deletions

View File

@ -97,6 +97,9 @@ if __name__ == '__main__':
) )
text = version_file.read_text() text = version_file.read_text()
results = re.findall(r"""INVENTREE_API_VERSION = (.*)""", text) results = re.findall(r"""INVENTREE_API_VERSION = (.*)""", text)
# If 2. args is true lower the version number by 1
if len(sys.argv) > 2 and sys.argv[2] == 'true':
results[0] = str(int(results[0]) - 1)
print(results[0]) print(results[0])
exit(0) exit(0)
# GITHUB_REF_TYPE may be either 'branch' or 'tag' # GITHUB_REF_TYPE may be either 'branch' or 'tag'

View File

@ -164,15 +164,27 @@ jobs:
name: schema.yml name: schema.yml
path: src/backend/InvenTree/schema.yml path: src/backend/InvenTree/schema.yml
- name: Download public schema - name: Download public schema
if: needs.paths-filter.outputs.api == 'false'
run: | run: |
pip install --require-hashes -r contrib/dev_reqs/requirements.txt >/dev/null 2>&1 pip install --require-hashes -r contrib/dev_reqs/requirements.txt >/dev/null 2>&1
version="$(python3 .github/scripts/version_check.py only_version 2>&1)" version="$(python3 .github/scripts/version_check.py only_version ${{ needs.paths-filter.outputs.api }} 2>&1)"
echo "Version: $version" echo "Version: $version"
url="https://raw.githubusercontent.com/inventree/schema/main/export/${version}/api.yaml" url="https://raw.githubusercontent.com/inventree/schema/main/export/${version}/api.yaml"
echo "URL: $url" echo "URL: $url"
curl -s -o api.yaml $url code=$(curl -s -o api.yaml $url --write-out '%{http_code}' --silent)
if [ "$code" != "200" ]; then
exit 1
fi
echo "Downloaded api.yaml" echo "Downloaded api.yaml"
- name: Running OpenAPI Spec diff action
id: breaking_changes
uses: oasdiff/oasdiff-action/diff@main
with:
base: 'api.yaml'
revision: 'src/backend/InvenTree/schema.yml'
format: 'html'
- name: Echoing diff to step
run: echo "${{ steps.breaking_changes.outputs.diff }}" >> $GITHUB_STEP_SUMMARY
- name: Check for differences in API Schema - name: Check for differences in API Schema
if: needs.paths-filter.outputs.api == 'false' if: needs.paths-filter.outputs.api == 'false'
run: | run: |