diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml index 70d6a678..c8b97037 100644 --- a/.github/workflows/code_quality.yml +++ b/.github/workflows/code_quality.yml @@ -54,3 +54,52 @@ jobs: run: pip install -r requirements/ci.txt - name: Run flake8 run: flake8 src + + generate-oas-files: + name: Generate and upload OAS files for all components + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.10' + - uses: actions/setup-node@v4 + with: + node-version: '16' + + - name: Install dependencies + run: pip install -r requirements/ci.txt + + - name: Generate OAS files + run: ./bin/generate_schema.sh openapi.yaml + env: + DJANGO_SETTINGS_MODULE: nrc.conf.ci + + - name: Store generated OAS files + uses: actions/upload-artifact@v4 + with: + name: open-notificaties-oas + path: openapi.yaml + retention-days: 1 + + oas-up-to-date: + name: Check for unexepected OAS changes + needs: tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Download generated OAS + uses: actions/download-artifact@v4 + with: + name: open-notificaties-oas + - name: Check for OAS changes + run: | + diff openapi.yaml src/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' >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY diff --git a/bin/generate_schema.sh b/bin/generate_schema.sh index a90a15ff..8cedc8cb 100755 --- a/bin/generate_schema.sh +++ b/bin/generate_schema.sh @@ -4,11 +4,13 @@ set -e -if [[ -z "$VIRTUAL_ENV" ]]; then +OUTPUT_FILE=$1 + +if [[ -z "$VIRTUAL_ENV" ]] && [[ ! -v GITHUB_ACTIONS ]]; then echo "You need to activate your virtual env before running this script" exit 1 fi echo "Generating OAS schema" src/manage.py spectacular \ - --file ./src/openapi.yaml + --file ${OUTPUT_FILE:-./src/openapi.yaml}