Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: 'Test OpenAPI Spec Diff Action'
on: push
jobs:
oas_diff_job:
runs-on: ubuntu-latest
name: A job to test OpenAPI Spec diff action
steps:
- name: checkout
uses: actions/checkout@v3
- name: Running OpenAPI Spec diff action
id: test_ete
uses: ./diff
with:
base: 'specs/base.yaml'
revision: 'specs/revision.yaml'
format: 'text'
oas_diff_breaking_changes_job:
runs-on: ubuntu-latest
name: A job to test OpenAPI Spec breaking changes
steps:
- name: checkout
uses: actions/checkout@v3
- name: Running OpenAPI Spec check breaking action
id: test_breaking_changes
uses: ./check-breaking
with:
base: https://raw.githubusercontent.com/Tufin/oasdiff/main/data/openapi-test1.yaml
revision: https://raw.githubusercontent.com/Tufin/oasdiff/main/data/openapi-test3.yaml
oas_diff_breaking_changes_latest_job:
runs-on: ubuntu-latest
name: A job to test latest release of OpenAPI Spec breaking changes action
steps:
- name: checkout
uses: actions/checkout@v3
- name: Running OpenAPI Spec check breaking latest action
id: test_breaking_changes
uses: oasdiff/oasdiff-action/check-breaking@latest
with:
base: https://raw.githubusercontent.com/Tufin/oasdiff/main/data/openapi-test1.yaml
revision: https://raw.githubusercontent.com/Tufin/oasdiff/main/data/openapi-test3.yaml
22 changes: 1 addition & 21 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
.idea/*
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
# oasdiff-action
# oasdiff-action
[![CI](https://github.com/oasdiff/oasdiff-action/actions/workflows/test.yaml/badge.svg)](https://github.com/oasdiff/oasdiff-action/actions)

GitHub actions for comparing OpenAPI specs and detect breaking changes, based on [oasdiff](https://github.com/Tufin/oasdiff) tool

## How to use?
Depend on your use case:

### Find diff
Copy and paste the following snippet into your build .yml file:
```
- name: Running OpenAPI Spec diff action
id: test_ete
uses: oasdiff/oasdiff-action/diff@latest
with:
base: 'specs/base.yaml'
revision: 'specs/revision.yaml'
format: 'text'
fail-on-diff: false
```

### Check for breaking API changes, and fail if any are found
Copy and paste the following snippet into your build .yml file:
```
- name: Running OpenAPI Spec diff action
id: test_ete
uses: oasdiff/oasdiff-action/check-breaking@latest
with:
base: https://raw.githubusercontent.com/Tufin/oasdiff/main/data/openapi-test1.yaml
revision: https://raw.githubusercontent.com/Tufin/oasdiff/main/data/openapi-test3.yaml
fail-on-diff: true
```
3 changes: 3 additions & 0 deletions check-breaking/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM tufin/oasdiff:main
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
20 changes: 20 additions & 0 deletions check-breaking/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: 'OpenAPI Spec Diff'
description: 'Detect breaking changes in OpenAPI Specification 3'
inputs:
base:
description: 'Path of original OpenAPI spec in YAML or JSON format'
required: true
revision:
description: 'Path of revised OpenAPI spec in YAML or JSON format'
required: true
fail-on-diff:
description: 'Fail with exit code 1 if a difference is found'
required: false
default: false
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.base }}
- ${{ inputs.revision }}
- ${{ inputs.fail-on-diff }}
15 changes: 15 additions & 0 deletions check-breaking/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
set -e

readonly base="$1"
readonly revision="$2"
readonly fail_on_diff="$3"

echo "running oasdiff check for breaking-changes... base: $base, revision: $revision, fail_on_diff: $fail_on_diff"

if [ "$fail_on_diff" = "true" ]
then
oasdiff -check-breaking -fail-on-diff -base "$base" -revision "$revision"
else
oasdiff -check-breaking -base "$base" -revision "$revision"
fi
3 changes: 3 additions & 0 deletions diff/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM tufin/oasdiff:main
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
25 changes: 25 additions & 0 deletions diff/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: 'OpenAPI Spec Diff'
description: 'A diff tool for OpenAPI Specification 3'
inputs:
base:
description: 'Path of original OpenAPI spec in YAML or JSON format'
required: true
revision:
description: 'Path of revised OpenAPI spec in YAML or JSON format'
required: true
format:
description: 'Output format'
required: false
default: 'yaml'
fail-on-diff:
description: 'Fail with exit code 1 if a difference is found'
required: false
default: false
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.base }}
- ${{ inputs.revision }}
- ${{ inputs.format }}
- ${{ inputs.fail-on-diff }}
16 changes: 16 additions & 0 deletions diff/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
set -e

readonly base="$1"
readonly revision="$2"
readonly format="$3"
readonly fail_on_diff="$4"

echo "running oasdiff... base: $base, revision: $revision, format: $format, fail_on_diff: $fail_on_diff"

if [ "$fail_on_diff" = "true" ]
then
oasdiff -fail-on-diff -format "$format" -base "$base" -revision "$revision"
else
oasdiff -format "$format" -base "$base" -revision "$revision"
fi
111 changes: 111 additions & 0 deletions specs/base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
responses:
'200':
description: A paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
'201':
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
Loading