From f8125b571a186a7b783c29be35f5c844f7c29974 Mon Sep 17 00:00:00 2001 From: SonnyBA Date: Wed, 17 Jul 2024 16:23:32 +0200 Subject: [PATCH] [#17] add jobs for checking for changes for OAS files (#420) * [#17] add jobs for checking for changes for OAS files --- .github/workflows/code-quality.yml | 42 ++++++++++++++++++++++++++++++ bin/generate_schema.sh | 4 ++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 75d6fed5..1ed6cc55 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -33,3 +33,45 @@ jobs: - name: Run black run: | black --check src docs + + oas-up-to-date: + name: Check for unexepected OAS changes + runs-on: ubuntu-latest + strategy: + matrix: + version: ['v1', 'v2'] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.11' + - uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Install system packages + run: | + sudo apt-get update \ + && sudo apt-get install -y --no-install-recommends \ + libgdal-dev \ + gdal-bin + + - name: Install dependencies + run: pip install -r requirements/ci.txt + + - name: Generate OAS files + run: ./bin/generate_schema.sh ${{ matrix.version }} openapi-${{ matrix.version }}.yaml + env: + DJANGO_SETTINGS_MODULE: objects.conf.ci + + - name: Check for OAS changes + run: | + diff openapi-${{ matrix.version }}.yaml src/objects/api/${{ matrix.version }}/openapi.yaml + - name: Write failure markdown + if: ${{ failure() }} + run: | + echo 'Run the following command locally and commit the changes' >> $GITHUB_STEP_SUMMARY + echo '' >> $GITHUB_STEP_SUMMARY + echo '```bash' >> $GITHUB_STEP_SUMMARY + echo './bin/generate_schema.sh ${{ matrix.version }}' >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY diff --git a/bin/generate_schema.sh b/bin/generate_schema.sh index ba232545..d24ece5b 100755 --- a/bin/generate_schema.sh +++ b/bin/generate_schema.sh @@ -16,4 +16,6 @@ fi export SCHEMA_PATH=src/objects/api/$1/openapi.yaml -src/manage.py spectacular --file $SCHEMA_PATH --validate --api-version $1 +OUTPUT_FILE=$2 + +src/manage.py spectacular --file ${OUTPUT_FILE:-$SCHEMA_PATH} --validate --api-version $1