Repository navigation
182 lines (163 loc) · 6.84 KB
/
Copy pathopenapi-diff-dockerless.yml
File metadata and controls
182 lines (163 loc) · 6.84 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: OpenAPI-Diff (Dockerless)
on:
workflow_call:
inputs:
path-filters:
description: 'Space-separated list of path filter expressions, e.g. \"openapi/**/*.yaml openapi/**/*.yml\"'
type: string
required: true
rule-overwrites:
description: 'JSON structure for rule overwrites, where the OAS rule names (see https://github.com/stoplightio/spectral/blob/develop/docs/reference/openapi-rules.md) are keys, and severity (see https://github.com/stoplightio/spectral/blob/develop/docs/guides/4a-rules.md#severity) are values, e.g. { "info-license": "info", "license-url": "off" }'
type: string
default: '{}'
linter-only:
description: 'Flag to control whether only the linter is run, without the OpenAPI diff. Optional, defaults to false'
type: boolean
required: false
default: false
env:
GITHUB_SERVER_URL: ${{ github.server_url }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_REF: ${{ github.ref }}
GITHUB_SHA: ${{ github.sha }}
GITHUB_WORKSPACE: ${{ github.workspace }}
# The event that triggered the GitHub action, e.g. push or pull_request.
GITHUB_EVENT_NAME: ${{ github.event_name }}
CURRENT_HASH: ${{ github.event.after }}
PREVIOUS_HASH: ${{ github.event.before }}
# The base_ref or target branch of the pull request in a workflow run.
# This property is only available when the event that triggers a workflow run is a pull_request.
GITHUB_BASE_REF: ${{ github.base_ref }}
# The head_ref or source branch of the pull request in a workflow run.
# This property is only available when the event that triggers a workflow run is a pull_request.
GITHUB_HEAD_REF: ${{ github.head_ref }}
jobs:
changed-files:
name: Detect changed OpenAPI files
runs-on: ubuntu-latest
outputs:
matrix-added-files: ${{ steps.added-files-to-matrix.outputs.matrix }}
matrix-changed-files: ${{ steps.changed-files-to-matrix.outputs.matrix }}
steps:
- name: Checkout Git Repository
uses: actions/checkout@v3
with:
# all history for all branches and tags
fetch-depth: 0
- name: Checkout Reusable Workflow for Scripts
uses: actions/checkout@v3
with:
repository: edgar-philipp/openapi-diff
path: workflow-repo
- name: Identify Added OpenAPI files
id: list-added-files
run: ${GITHUB_WORKSPACE}/workflow-repo/scripts/list_changed_files.sh
shell: bash
env:
PATH_FILTERS: ${{ inputs.path-filters }}
OPERATION: 'Added'
- name: Identify Changed OpenAPI files
id: list-changed-files
run: ${GITHUB_WORKSPACE}/workflow-repo/scripts/list_changed_files.sh
shell: bash
env:
PATH_FILTERS: ${{ inputs.path-filters }}
OPERATION: 'Changed'
- name: Transform added files into GitHub matrix (special JSON format)
id: added-files-to-matrix
run: ${GITHUB_WORKSPACE}/workflow-repo/scripts/transform_to_github_matrix.sh
shell: bash
env:
CHANGED_FILES: ${{ steps.list-added-files.outputs.changed_files }}
- name: Transform changed files into GitHub matrix (special JSON format)
id: changed-files-to-matrix
run: ${GITHUB_WORKSPACE}/workflow-repo/scripts/transform_to_github_matrix.sh
shell: bash
env:
CHANGED_FILES: ${{ steps.list-changed-files.outputs.changed_files }}
openapi-linter:
name: Lint new OpenAPI files
needs: changed-files
if: ${{ toJson(fromJson(needs.changed-files.outputs.matrix-added-files)) != '{}' }}
runs-on: ubuntu-latest
# Matrix will spawn a separate job instance for every added file
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.changed-files.outputs.matrix-added-files) }}
steps:
- name: Checkout Git Repository
uses: actions/checkout@v3
- name: Checkout Reusable Workflow for Scripts
uses: actions/checkout@v3
with:
repository: edgar-philipp/openapi-diff
path: workflow-repo
- name: Add custom Spectral rules
id: custom-spectral-rules
run: ${GITHUB_WORKSPACE}/workflow-repo/scripts/lint_rules.sh
shell: bash
env:
JSON_INPUT: ${{ toJson(fromJson(inputs.rule-overwrites)) }}
- name: Install Spectral Linter
id: install-linter
run: ${GITHUB_WORKSPACE}/workflow-repo/scripts/lint_checkout_dockerless.sh
shell: bash
- name: Run Spectral Linter
id: run-linter
run: ${GITHUB_WORKSPACE}/workflow-repo/node_modules/".bin"/spectral lint ${{ matrix.file }} -r workflow-repo/linter/spectral.yml -o linter.out 2>linter.out
shell: bash
- name: Linter Report
id: linter-report
if: ${{ success() || failure() }}
run: ${GITHUB_WORKSPACE}/workflow-repo/scripts/lint_report.sh
shell: bash
env:
LINT_RESULT: linter.out
diff-detection:
name: Diff on OpenAPI file
needs: changed-files
if: ${{ toJson(fromJson(needs.changed-files.outputs.matrix-changed-files)) != '{}' }}
runs-on: ubuntu-latest
# Matrix will spawn a separate job instance for every changed file
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.changed-files.outputs.matrix-changed-files) }}
steps:
- name: Checkout Git Repository
uses: actions/checkout@v3
with:
# all history for all branches and tags
fetch-depth: 0
- name: Checkout Reusable Workflow for Scripts
uses: actions/checkout@v3
with:
repository: edgar-philipp/openapi-diff
path: workflow-repo
- name: Add custom Spectral rules
id: custom-spectral-rules
run: ${GITHUB_WORKSPACE}/workflow-repo/scripts/lint_rules.sh
shell: bash
env:
JSON_INPUT: ${{ toJson(fromJson(inputs.rule-overwrites)) }}
- name: Install Spectral Linter
id: install-linter
run: ${GITHUB_WORKSPACE}/workflow-repo/scripts/lint_checkout_dockerless.sh
shell: bash
- name: Run Spectral Linter
id: run-linter
run: ${GITHUB_WORKSPACE}/workflow-repo/node_modules/".bin"/spectral lint ${{ matrix.file }} -r workflow-repo/linter/spectral.yml -o linter.out 2>linter.out
shell: bash
- name: Linter Report
id: linter-report
if: ${{ success() || failure() }}
run: ${GITHUB_WORKSPACE}/workflow-repo/scripts/lint_report.sh
shell: bash
env:
LINT_RESULT: linter.out
- name: Verify Diffs on OpenAPI File
id: diff-file
if: ${{ inputs.linter-only == false && (success() || failure()) }}
run: ${GITHUB_WORKSPACE}/workflow-repo/scripts/openapi_diff.sh
shell: bash
env:
CHANGED_FILE: ${{ matrix.file }}