From 44a5f76213d7a5c5e322dc3281b8bdc3db1d75ae Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Wed, 17 Jul 2024 15:45:26 +0200 Subject: [PATCH] [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 --- .github/scripts/version_check.py | 3 +++ .github/workflows/qc_checks.yaml | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/scripts/version_check.py b/.github/scripts/version_check.py index 68e2ff1e25..9e81d3885c 100644 --- a/.github/scripts/version_check.py +++ b/.github/scripts/version_check.py @@ -97,6 +97,9 @@ if __name__ == '__main__': ) text = version_file.read_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]) exit(0) # GITHUB_REF_TYPE may be either 'branch' or 'tag' diff --git a/.github/workflows/qc_checks.yaml b/.github/workflows/qc_checks.yaml index 4df56dd40d..afbf24635e 100644 --- a/.github/workflows/qc_checks.yaml +++ b/.github/workflows/qc_checks.yaml @@ -164,15 +164,27 @@ jobs: name: schema.yml path: src/backend/InvenTree/schema.yml - name: Download public schema - if: needs.paths-filter.outputs.api == 'false' run: | 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" url="https://raw.githubusercontent.com/inventree/schema/main/export/${version}/api.yaml" 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" + - 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 if: needs.paths-filter.outputs.api == 'false' run: |