-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yaml
More file actions
99 lines (86 loc) · 3.51 KB
/
action.yaml
File metadata and controls
99 lines (86 loc) · 3.51 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
91
92
93
94
95
96
97
98
99
name: "Validate OpenAPI spec against TOMP-API"
description: "Compare a candidate OpenAPI spec against the TOMP-API reference and fail the build on breaking changes."
author: "Bas Matthee <basmatthee@gmail.com>"
inputs:
candidate_spec:
description: "Path to your OpenAPI YAML file (relative to workspace)"
required: true
version_tag:
description: "TOMP-API release tag (e.g., v1.6.1). Defaults to latest."
required: false
fail_on_breaking_changes:
description: "Fail if breaking changes are found"
required: false
default: "true"
fail_on_non_breaking_changes:
description: "Fail if non-breaking changes are found"
required: false
default: "false"
show_unclassified:
description: "Show unclassified changes"
required: false
default: "true"
runs:
using: "composite"
steps:
- name: Prepare working directory
run: |
export DIFFDIR="/tmp/openapi-diff"
echo "DIFFDIR=$DIFFDIR" >> "$GITHUB_ENV"
mkdir -p "$DIFFDIR"
cp "${{ github.workspace }}/${{ inputs.candidate_spec }}" "$DIFFDIR/openapi.yaml"
shell: bash
- name: Fetch TOMP-API reference spec
run: |
VERSION="${{ inputs.version_tag }}"
if [[ -z "$VERSION" ]]; then
VERSION=$(curl -s https://api.github.com/repos/TOMP-WG/TOMP-API/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
fi
echo "📦 Using TOMP-API version: $VERSION"
curl -fsSL "https://raw.githubusercontent.com/TOMP-WG/TOMP-API/$VERSION/TOMP-API.yaml" \
-o "/tmp/openapi-diff/TOMP-API-reference.yaml"
chmod a+r /tmp/openapi-diff/*.yaml
shell: bash
- name: Bundle specs with Redocly
run: |
npm install --no-fund --no-audit --loglevel=error -g @redocly/cli
redocly bundle /tmp/openapi-diff/openapi.yaml -o /tmp/openapi-diff/openapi-bundled.yaml > /dev/null
redocly bundle /tmp/openapi-diff/TOMP-API-reference.yaml -o /tmp/openapi-diff/TOMP-API-reference-bundled.yaml > /dev/null
shell: bash
- name: Run openapi-diff
run: |
echo "🧪 Running openapi-diff..."
docker_output=$(mktemp)
docker run --rm \
-v /tmp/openapi-diff:/specs \
openapitools/openapi-diff:latest \
/specs/TOMP-API-reference-bundled.yaml /specs/openapi-bundled.yaml \
> /tmp/openapi-diff/diff_result.txt 2>"$docker_output" || {
echo "exit_code=$?" >> "$GITHUB_OUTPUT"
}
echo "🧪 Diff Result:"
cat /tmp/openapi-diff/diff_result.txt
shell: bash
- name: Fail on configured diff results
run: |
RESULT=$(cat /tmp/openapi-diff/diff_result.txt)
FAIL=false
if [[ "$RESULT" == *"API changes broke backward compatibility"* && "${{ inputs.fail_on_breaking_changes }}" == "true" ]]; then
echo "❌ Breaking changes detected!"
FAIL=true
fi
if [[ "$RESULT" == *"API changes are backward compatible"* && "${{ inputs.fail_on_non_breaking_changes }}" == "true" ]]; then
echo "⚠️ Non-breaking changes present!"
FAIL=true
fi
if [[ "$RESULT" == *"UNCLASSIFIED"* && "${{ inputs.show_unclassified }}" == "true" ]]; then
echo "❓ Unclassified changes detected:"
echo "$RESULT" | grep UNCLASSIFIED
fi
if [[ "$FAIL" == "true" ]]; then
echo "💥 Spec comparison failed based on your config."
exit 1
else
echo "✅ Spec comparison passed."
fi
shell: bash