-
Notifications
You must be signed in to change notification settings - Fork 7
118 lines (106 loc) · 3.87 KB
/
openapi-breaking-changes.yml
File metadata and controls
118 lines (106 loc) · 3.87 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: OpenAPI Breaking Changes
on:
pull_request:
branches: [ main ]
paths:
- 'openapi.yaml'
- 'openapi/**'
workflow_dispatch:
permissions:
contents: read
pull-requests: write
issues: write
jobs:
detect:
name: Detect breaking changes
runs-on: ubuntu-latest
steps:
- name: Checkout base spec
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha }}
path: base
- name: Checkout head spec
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
path: head
- name: Install oasdiff
env:
OASDIFF_VERSION: 1.16.0
OASDIFF_SHA256: 2f424431c441a85e2d73ff884609f55c98c283ca2ce3d88537a7a029379dd521
run: |
curl -fsSL \
"https://github.com/oasdiff/oasdiff/releases/download/v${OASDIFF_VERSION}/oasdiff_${OASDIFF_VERSION}_linux_amd64.tar.gz" \
-o /tmp/oasdiff.tgz
echo "${OASDIFF_SHA256} /tmp/oasdiff.tgz" | sha256sum -c -
tar -xzf /tmp/oasdiff.tgz -C /tmp oasdiff
sudo mv /tmp/oasdiff /usr/local/bin/oasdiff
oasdiff --version
- name: Run oasdiff breaking
id: oasdiff
run: |
set +e
oasdiff breaking \
base/openapi.yaml head/openapi.yaml \
--format markdown \
--fail-on ERR > breaking.md
status=$?
echo "status=$status" >> "$GITHUB_OUTPUT"
if [ "$status" -ne 0 ] && [ -s breaking.md ]; then
echo "has_breaking=true" >> "$GITHUB_OUTPUT"
else
echo "has_breaking=false" >> "$GITHUB_OUTPUT"
fi
- name: Build comment body
id: body
if: steps.oasdiff.outputs.has_breaking == 'true'
run: |
{
echo 'body<<COMMENT_EOF'
echo '## :warning: Breaking OpenAPI changes detected'
echo ''
echo 'This PR introduces breaking changes to `openapi.yaml`:'
echo ''
cat breaking.md
echo ''
echo '---'
echo '_Detected by [oasdiff](https://github.com/oasdiff/oasdiff). This PR will need approval from an API reviewer before merge._'
echo 'COMMENT_EOF'
} >> "$GITHUB_OUTPUT"
- name: Ensure breaking-change label exists
if: steps.oasdiff.outputs.has_breaking == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: |
gh label create "breaking-change" \
--color B60205 \
--description "Introduces a breaking change to the OpenAPI spec" \
2>/dev/null || true
- name: Add breaking-change label
if: steps.oasdiff.outputs.has_breaking == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: gh pr edit "$PR_NUMBER" --add-label "breaking-change"
- name: Remove breaking-change label if previously set
if: steps.oasdiff.outputs.has_breaking == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: gh pr edit "$PR_NUMBER" --remove-label "breaking-change" || true
- name: Upsert PR comment (breaking)
if: steps.oasdiff.outputs.has_breaking == 'true'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: oasdiff-breaking-changes
message: ${{ steps.body.outputs.body }}
- name: Clear PR comment (no breaking)
if: steps.oasdiff.outputs.has_breaking == 'false'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: oasdiff-breaking-changes
delete: true