-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
90 lines (78 loc) · 3.09 KB
/
action.yml
File metadata and controls
90 lines (78 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: 'AutoGuard-diff Action'
description: 'Runs OpenAPI-diff on multiple profile specifications'
inputs:
profiles:
default: 'default'
old_dir:
required: true
new_dir:
required: true
runs:
using: 'composite'
steps:
- name: 'Run OpenAPI-diff'
id: 'diff_step'
run: |
set +e
EMPTY_OAS='{ "openapi" : "3.0.1", "info" : { "title" : "", "description" : "Spring Profile: ???", "version" : "" }, "paths" : { }, "components" : { "schemas" : { } }}'
echo $EMPTY_OAS > empty.json
OLD_FILES=$(find "$OLD_DIR" -type f | sed "s|$OLD_DIR/||" | sort)
NEW_FILES=$(find "$NEW_DIR" -type f | sed "s|$NEW_DIR/||" | sort)
printf "%s\n" $OLD_FILES > old_files
printf "%s\n" $NEW_FILES > new_files
COMMON_FILES=$(comm -12 old_files new_files)
OTHER_FILES=$(comm -3 old_files new_files)
STATUS=0
mkdir oas_diff
echo "Analyzing existing configurations"
for p in ${COMMON_FILES[@]}; do
docker run --rm -t \
-v $(pwd):/specs \
openapitools/openapi-diff:latest --fail-on-incompatible --html "/specs/oas_diff/$p.html" /specs/$OLD_DIR/$p /specs/$NEW_DIR/$p
EXIT_CODE=$?
if [ $EXIT_CODE -eq 1 ]; then
echo "::error::Breaking changes detected in profile $p"
fi
STATUS=$((STATUS + EXIT_CODE))
done
for p in ${OTHER_FILES[@]}; do
if [ -f "$OLD_DIR/$p" ]; then
echo "Analyzing deleted configurations"
docker run --rm -t \
-v $(pwd):/specs \
openapitools/openapi-diff:latest --fail-on-incompatible --html "/specs/oas_diff/$p.html" /specs/$OLD_DIR/$p /specs/empty.json
EXIT_CODE=$?
if [ $EXIT_CODE -eq 1 ]; then
echo "::error::Breaking changes detected in profile $p"
fi
STATUS=$((STATUS + EXIT_CODE))
else
echo "Analyzing added configurations"
docker run --rm -t \
-v $(pwd):/specs \
openapitools/openapi-diff:latest --fail-on-incompatible --html "/specs/oas_diff/$p.html" /specs/empty.json /specs/$NEW_DIR/$p
EXIT_CODE=$?
if [ $EXIT_CODE -eq 1 ]; then
echo "::error::Breaking changes detected in profile $p"
fi
STATUS=$((STATUS + EXIT_CODE))
fi
done
set -e
echo "status=$STATUS" >> "$GITHUB_OUTPUT"
shell: bash
env:
OLD_DIR: ${{inputs.old_dir}}
NEW_DIR: ${{inputs.new_dir}}
- name: 'Upload specifications'
uses: actions/upload-artifact@v4
with:
name: 'OpenAPI differences'
path: oas_diff/*.html
- name: 'Check breaking info'
shell: bash
run: |
if [ "${{steps.diff_step.outputs.status}}" -gt 0 ]; then
echo "::error::Breaking changes detected"
exit 1
fi