-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaction.yml
More file actions
144 lines (135 loc) · 5.28 KB
/
action.yml
File metadata and controls
144 lines (135 loc) · 5.28 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
name: 'OpenAPI Diff'
description: 'Compare two OpenAPI specifications and detect breaking changes using openapitools/openapi-diff'
author: 'OpenAPI Tools Community'
branding:
icon: 'git-pull-request'
color: 'blue'
inputs:
old-spec:
description: 'Path or URL to the old/base OpenAPI specification'
required: true
new-spec:
description: 'Path or URL to the new/head OpenAPI specification'
required: true
html:
description: 'Path to write HTML diff report'
required: false
default: ''
markdown:
description: 'Path to write Markdown diff report'
required: false
default: ''
json:
description: 'Path to write JSON diff report'
required: false
default: ''
asciidoc:
description: 'Path to write Asciidoc diff report'
required: false
default: ''
text:
description: 'Path to write plain text diff report'
required: false
default: ''
fail-on-breaking:
description: 'Fail the action if breaking changes are detected'
required: false
default: 'false'
fail-on-changed:
description: 'Fail the action if any changes are detected (breaking or compatible)'
required: false
default: 'false'
headers:
description: 'HTTP headers to use when fetching remote specs via URL (format: "Header1=Value1,Header2=Value2"). Only applies to URL specs, ignored for local files.'
required: false
default: ''
log-level:
description: 'Log level (TRACE, DEBUG, INFO, WARN, ERROR, OFF)'
required: false
default: 'ERROR'
add-pr-comment:
description: 'Add diff results as a PR comment'
required: false
default: 'false'
github-token:
description: 'GitHub token for posting PR comments (required if add-pr-comment is true)'
required: false
default: ''
artifact-name:
description: 'Name for the uploaded artifact containing report files'
required: false
default: 'openapi-diff-report'
outputs:
state:
description: 'Diff state: no_changes, compatible, or incompatible'
value: ${{ steps.diff.outputs.state }}
has-changes:
description: 'Whether any changes were detected (true/false)'
value: ${{ steps.diff.outputs.has_changes }}
is-breaking:
description: 'Whether breaking changes were detected (true/false)'
value: ${{ steps.diff.outputs.is_breaking }}
runs:
using: 'composite'
steps:
- name: Run OpenAPI Diff
id: diff
shell: bash
env:
INPUT_OLD_SPEC: ${{ inputs.old-spec }}
INPUT_NEW_SPEC: ${{ inputs.new-spec }}
INPUT_HTML: ${{ inputs.html }}
INPUT_MARKDOWN: ${{ inputs.markdown }}
INPUT_JSON: ${{ inputs.json }}
INPUT_ASCIIDOC: ${{ inputs.asciidoc }}
INPUT_TEXT: ${{ inputs.text }}
INPUT_FAIL_ON_BREAKING: ${{ inputs.fail-on-breaking }}
INPUT_FAIL_ON_CHANGED: ${{ inputs.fail-on-changed }}
INPUT_HEADERS: ${{ inputs.headers }}
INPUT_LOG_LEVEL: ${{ inputs.log-level }}
run: ${{ github.action_path }}/scripts/run-diff.sh
- name: Get PR number
if: ${{ fromJSON(inputs.add-pr-comment) }}
id: pr-number
shell: bash
run: |
if [[ "${{ github.event_name }}" == "pull_request" || "${{ github.event_name }}" == "pull_request_target" ]]; then
echo "number=${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT"
elif [[ "${{ github.event_name }}" == "workflow_run" ]]; then
echo "number=${{ github.event.workflow_run.pull_requests[0].number }}" >> "$GITHUB_OUTPUT"
fi
- name: Find existing PR comment
if: ${{ fromJSON(inputs.add-pr-comment) && steps.pr-number.outputs.number != '' }}
id: find-comment
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad # v4
with:
token: ${{ inputs.github-token }}
issue-number: ${{ steps.pr-number.outputs.number }}
body-includes: '<!--openapi-diff-workflow-comment-->'
- name: Create PR Comment
if: ${{ fromJSON(inputs.add-pr-comment) && steps.pr-number.outputs.number != '' && steps.find-comment.outputs.comment-id == '' }}
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
with:
token: ${{ inputs.github-token }}
issue-number: ${{ steps.pr-number.outputs.number }}
body-path: ${{ steps.diff.outputs.pr_comment_file }}
- name: Update PR Comment
if: ${{ fromJSON(inputs.add-pr-comment) && steps.pr-number.outputs.number != '' && steps.find-comment.outputs.comment-id != '' }}
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
with:
token: ${{ inputs.github-token }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body-path: ${{ steps.diff.outputs.pr_comment_file }}
- name: Upload report artifacts
if: ${{ steps.diff.outputs.has_changes == 'true' && (inputs.markdown != '' || inputs.json != '' || inputs.html != '' || inputs.text != '' || inputs.asciidoc != '') }}
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
with:
name: ${{ inputs.artifact-name }}
if-no-files-found: ignore
path: |
${{ inputs.markdown }}
${{ inputs.json }}
${{ inputs.html }}
${{ inputs.text }}
${{ inputs.asciidoc }}