Skip to content

Commit 44a5f76

Browse files
authored
[CI] Add nicer OpenAPI diffs (inventree#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
1 parent 547fa17 commit 44a5f76

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

.github/scripts/version_check.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ def check_version_number(version_string, allow_duplicate=False):
9797
)
9898
text = version_file.read_text()
9999
results = re.findall(r"""INVENTREE_API_VERSION = (.*)""", text)
100+
# If 2. args is true lower the version number by 1
101+
if len(sys.argv) > 2 and sys.argv[2] == 'true':
102+
results[0] = str(int(results[0]) - 1)
100103
print(results[0])
101104
exit(0)
102105
# GITHUB_REF_TYPE may be either 'branch' or 'tag'

.github/workflows/qc_checks.yaml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,27 @@ jobs:
164164
name: schema.yml
165165
path: src/backend/InvenTree/schema.yml
166166
- name: Download public schema
167-
if: needs.paths-filter.outputs.api == 'false'
168167
run: |
169168
pip install --require-hashes -r contrib/dev_reqs/requirements.txt >/dev/null 2>&1
170-
version="$(python3 .github/scripts/version_check.py only_version 2>&1)"
169+
version="$(python3 .github/scripts/version_check.py only_version ${{ needs.paths-filter.outputs.api }} 2>&1)"
171170
echo "Version: $version"
172171
url="https://raw.githubusercontent.com/inventree/schema/main/export/${version}/api.yaml"
173172
echo "URL: $url"
174-
curl -s -o api.yaml $url
173+
code=$(curl -s -o api.yaml $url --write-out '%{http_code}' --silent)
174+
if [ "$code" != "200" ]; then
175+
exit 1
176+
fi
175177
echo "Downloaded api.yaml"
178+
- name: Running OpenAPI Spec diff action
179+
id: breaking_changes
180+
uses: oasdiff/oasdiff-action/diff@main
181+
with:
182+
base: 'api.yaml'
183+
revision: 'src/backend/InvenTree/schema.yml'
184+
format: 'html'
185+
- name: Echoing diff to step
186+
run: echo "${{ steps.breaking_changes.outputs.diff }}" >> $GITHUB_STEP_SUMMARY
187+
176188
- name: Check for differences in API Schema
177189
if: needs.paths-filter.outputs.api == 'false'
178190
run: |

0 commit comments

Comments
 (0)