diff --git a/openapi/diff-optic/action.yaml b/openapi/diff-optic/action.yaml new file mode 100644 index 0000000..7bb3e24 --- /dev/null +++ b/openapi/diff-optic/action.yaml @@ -0,0 +1,21 @@ +name: Compare OpenAPI specs +inputs: + openapi-uri-original: + description: URI (file or URL) to the original OpenAPI spec ("before") + required: true + openapi-uri-updated: + description: URI (file or URL) to the updated OpenAPI spec ("after") + required: true + optic-yaml-path: + description: (Optional) Path to an Optic YAML file, for customizing the Optic diff ruleset + required: false + +runs: + using: composite + steps: + - shell: bash + run: ${{ github.action_path }}/run.sh + env: + OPENAPI_URI_ORIGINAL: ${{ inputs.openapi-uri-original }} + OPENAPI_URI_UPDATED: ${{ inputs.openapi-uri-updated }} + OPTIC_YAML_PATH: ${{ inputs.optic-yaml-path }} diff --git a/openapi/diff-optic/run.sh b/openapi/diff-optic/run.sh new file mode 100755 index 0000000..0c798df --- /dev/null +++ b/openapi/diff-optic/run.sh @@ -0,0 +1,42 @@ +#!/bin/bash +set -xe + +echo "🔍 Checking for API breaking changes..." + +npm install -g @useoptic/optic + +OPTIC_ARGS=(diff "${OPENAPI_URI_ORIGINAL}" "${OPENAPI_URI_UPDATED}") + +if [ -n "${OPTIC_YAML_PATH}" ]; then + OPTIC_ARGS+=(--standard "${OPTIC_YAML_PATH}") +fi + +if ! optic "${OPTIC_ARGS[@]}" --severity error 2>/dev/null; then + echo "❌ Breaking API changes detected!" + BREAKING_CHANGES=true +else + echo "✅ No breaking API changes" +fi + +echo "" +echo "==================================================================" + +if [ "$BREAKING_CHANGES" = true ]; then + echo "❌ API BREAKING CHANGES DETECTED!" + echo "" + echo "🚨 This PR contains potentially breaking changes:" + echo " • .NET assembly API changes, or" + echo " • HTTP endpoint route changes, or" + echo " • Removed HTTP endpoints" + echo "" + echo "If these changes are intentional:" + echo "1. 📈 Update version numbers appropriately" + echo "2. 📝 Document breaking changes in your PR description" + echo "3. 🤔 Consider the impact on existing API consumers" + echo "4. 📧 Notify teams that depend on these APIs" + echo "" + exit 1 +else + echo "✅ API COMPATIBILITY CHECK PASSED!" + echo "No breaking changes detected in HTTP endpoints." +fi