Repository navigation
103 lines (90 loc) · 3.98 KB
/
Copy pathopenapi-diff.yml
File metadata and controls
103 lines (90 loc) · 3.98 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
# SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: MIT
name: OpenAPI diff
on:
pull_request:
paths:
- 'openapi-full.json'
permissions:
contents: read
concurrency:
group: openapi-diff-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
openapi-diff:
runs-on: ubuntu-latest-low
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Fetch base commit
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: git fetch --depth=1 origin "$BASE_SHA"
- name: Annotate breaking changes
uses: oasdiff/oasdiff-action/breaking@9e56cf8b3aff7edb326d5767d3d23f96127e20c3 # v0.1.21
with:
base: '${{ github.event.pull_request.base.sha }}:openapi-full.json'
revision: 'HEAD:openapi-full.json'
review: false
- name: List breaking changes
uses: oasdiff/oasdiff-action/changelog@9e56cf8b3aff7edb326d5767d3d23f96127e20c3 # v0.1.21
with:
base: '${{ github.event.pull_request.base.sha }}:openapi-full.json'
revision: 'HEAD:openapi-full.json'
level: WARN
format: markdown
output-to-file: oasdiff-breaking.md
review: false
- name: List all changes
uses: oasdiff/oasdiff-action/diff@9e56cf8b3aff7edb326d5767d3d23f96127e20c3 # v0.1.21
with:
base: '${{ github.event.pull_request.base.sha }}:openapi-full.json'
revision: 'HEAD:openapi-full.json'
format: markdown
output-to-file: oasdiff-diff.md
- name: Build comment
run: |
breaking=$(grep -vE '^# API Changelog|^## API Changes$|^No (changes detected|changelog changes)$' oasdiff-breaking.md | sed 's/^### /#### /; /./,$!d' | cat -s)
{
echo '<!-- openapi-diff -->'
echo '## OpenAPI changes'
echo
echo '### Breaking changes'
echo
if [ -n "$(echo "$breaking" | tr -d '[:space:]')" ]; then echo "$breaking"; else echo 'None'; fi
echo
# Deeply nested lists stop indenting on GitHub, so section bodies go into code blocks
awk '
function flush() { sub(/\n+$/, "\n", body); if (body != "") printf "<details><summary>Show changes</summary>\n\n```\n%s```\n\n</details>\n\n", body; body = "" }
/^### / { flush(); print; print ""; next }
/^-+$/ { next }
/^[[:space:]]*$/ { if (body != "") body = body "\n"; next }
{ sub(/ +$/, ""); body = body $0 "\n" }
END { flush() }
' oasdiff-diff.md
} > "$RUNNER_TEMP/body.md"
# Comment body limit is 65536 characters
cp "$RUNNER_TEMP/body.md" "$GITHUB_STEP_SUMMARY"
if [ "$(wc -c < "$RUNNER_TEMP/body.md")" -gt 60000 ]; then
head -c 60000 "$GITHUB_STEP_SUMMARY" > "$RUNNER_TEMP/body.md"
printf '\n\n…truncated, see the workflow summary for the full diff.\n' >> "$RUNNER_TEMP/body.md"
fi
# Fork PRs only get a read-only token, they rely on the workflow summary
- name: Post or update comment
if: github.event.pull_request.head.repo.full_name == github.repository
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
PR: ${{ github.event.pull_request.number }}
run: |
id=$(gh api --paginate "repos/$REPO/issues/$PR/comments" --jq '.[] | select(.user.login == "github-actions[bot]" and (.body | startswith("<!-- openapi-diff -->"))) | .id' | head -n1)
if [ -n "$id" ]; then
gh api -X PATCH "repos/$REPO/issues/comments/$id" -F "body=@$RUNNER_TEMP/body.md" > /dev/null
else
gh pr comment "$PR" --repo "$REPO" --body-file "$RUNNER_TEMP/body.md"
fi