-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaction.yml
More file actions
233 lines (215 loc) · 7.83 KB
/
action.yml
File metadata and controls
233 lines (215 loc) · 7.83 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
name: 'Schemathesis'
description: 'Property-based API testing with Schemathesis'
author: 'Dmitry Dygalo <@Stranger6667> | Schemathesis.io'
branding:
icon: 'check-square'
color: 'green'
inputs:
schema:
description: 'API schema location (URL or file path) '
required: true
base-url:
description: 'Override base URL '
required: false
checks:
description: 'Validation checks to run (default: all)'
required: false
default: 'all'
wait-for-schema:
description: 'Schema availability timeout in seconds'
required: false
default: '2'
max-examples:
description: 'Maximum test cases per API operation'
required: false
default: '100'
version:
description: 'Schemathesis version (default: latest)'
required: false
default: 'latest'
hooks:
description: 'Python module path for hooks'
required: false
config-file:
description: 'Path to a `schemathesis.toml` configuration file'
required: false
args:
description: 'Additional CLI arguments'
required: false
authorization:
description: 'Value for the Authorization header (e.g. "Bearer TOKEN")'
required: false
coverage:
description: 'Enable schema coverage tracking with tracecov'
required: false
default: 'true'
coverage-report:
description: 'Upload HTML coverage report as a workflow artifact'
required: false
default: 'true'
coverage-report-path:
description: 'Path to save the HTML coverage report (relative to workspace root)'
required: false
default: 'schema-coverage.html'
coverage-artifact-name:
description: 'Name of the uploaded coverage artifact. Override when using the action multiple times in one workflow to avoid name collisions.'
required: false
default: 'schema-coverage-report'
coverage-pr-comment:
description: 'Post coverage summary as a PR comment (requires pull-requests: write)'
required: false
default: 'true'
coverage-step-summary:
description: 'Write coverage summary to the workflow step summary'
required: false
default: 'true'
runs:
using: 'composite'
steps:
- uses: actions/setup-python@v6
with:
python-version: '3.13'
- uses: astral-sh/setup-uv@v7
with:
version: ">=0.5.0"
- run: |
set -euo pipefail
VERSION='${{ inputs.version }}'
COVERAGE='${{ inputs.coverage }}'
if [[ "$VERSION" == "latest" ]]; then
BASE_SPEC="schemathesis>=4.11.1,<5.0"
else
BASE_SPEC="schemathesis==$VERSION"
fi
if [[ "$COVERAGE" == "true" ]]; then
uv tool install "$BASE_SPEC" --with "tracecov>=0.16.6"
else
uv tool install "$BASE_SPEC"
fi
shell: bash
- run: |
set -euo pipefail
COVERAGE='${{ inputs.coverage }}'
USER_HOOKS='${{ inputs.hooks }}'
HOOK_FILE="/tmp/_st_action_hooks.py"
if [[ "$COVERAGE" == "true" ]]; then
printf '%s' "$USER_HOOKS" > /tmp/_st_user_hooks.txt
{
echo 'import tracecov.schemathesis'
echo 'tracecov.schemathesis.install()'
echo ''
echo 'import os, sys, importlib.util'
echo 'with open("/tmp/_st_user_hooks.txt") as _f:'
echo ' _user_hooks = _f.read()'
echo 'if _user_hooks:'
echo ' if os.path.isfile(_user_hooks):'
echo ' _spec = importlib.util.spec_from_file_location("_hooks", _user_hooks)'
echo ' _mod = importlib.util.module_from_spec(_spec)'
echo ' _spec.loader.exec_module(_mod)'
echo ' else:'
echo ' sys.path.insert(0, os.getcwd())'
echo ' __import__(_user_hooks)'
} > "$HOOK_FILE"
echo "SCHEMATHESIS_HOOKS=$HOOK_FILE" >> "$GITHUB_ENV"
elif [[ -n "$USER_HOOKS" ]]; then
echo "SCHEMATHESIS_HOOKS=$USER_HOOKS" >> "$GITHUB_ENV"
else
echo "SCHEMATHESIS_HOOKS=" >> "$GITHUB_ENV"
fi
shell: bash
- run: |
set -euo pipefail
SCHEMA='${{ inputs.schema }}'
CHECKS='${{ inputs.checks }}'
MAX_EXAMPLES='${{ inputs.max-examples }}'
CONFIG_FILE='${{ inputs.config-file }}'
ARGS='${{ inputs.args }}'
AUTHORIZATION='${{ inputs.authorization }}'
COVERAGE='${{ inputs.coverage }}'
COVERAGE_REPORT_PATH='${{ inputs.coverage-report-path }}'
EVENT='${{ github.event_name }}'
RUN_ID='${{ github.run_id }}'
REPO='${{ github.repository }}'
if [[ "$COVERAGE" == "true" ]]; then
export SCHEMATHESIS_COVERAGE_FORMAT="html,markdown"
export SCHEMATHESIS_COVERAGE_REPORT_HTML_PATH="$COVERAGE_REPORT_PATH"
export SCHEMATHESIS_COVERAGE_REPORT_MARKDOWN_PATH="/tmp/_st_coverage.md"
if [[ "$EVENT" == "pull_request" || "$EVENT" == "pull_request_target" ]]; then
export SCHEMATHESIS_COVERAGE_MARKDOWN_IS_PULL_REQUEST="true"
fi
fi
eval "ARGS_ARRAY=($ARGS)"
CMD=(schemathesis)
if [[ -n "$CONFIG_FILE" ]]; then
CMD+=(--config-file="$CONFIG_FILE")
fi
CMD+=(run
"$SCHEMA"
--generation-database=":memory:"
--max-examples="$MAX_EXAMPLES"
--checks="$CHECKS"
)
if [[ -n "$AUTHORIZATION" ]]; then
CMD+=(-H "Authorization: $AUTHORIZATION")
fi
CMD+=("${ARGS_ARRAY[@]}")
"${CMD[@]}"
shell: bash
env:
SCHEMATHESIS_BASE_URL: ${{ inputs.base-url }}
SCHEMATHESIS_WAIT_FOR_SCHEMA: ${{ inputs.wait-for-schema }}
- if: always()
run: |
COVERAGE='${{ inputs.coverage }}'
STEP_SUMMARY='${{ inputs.coverage-step-summary }}'
if [[ "$COVERAGE" == 'true' && "$STEP_SUMMARY" == 'true' && -f '/tmp/_st_coverage.md' ]]; then
cat /tmp/_st_coverage.md >> "$GITHUB_STEP_SUMMARY"
fi
shell: bash
- uses: actions/upload-artifact@v7
if: always() && inputs.coverage == 'true' && inputs['coverage-report'] == 'true'
with:
name: ${{ inputs.coverage-artifact-name }}
path: ${{ inputs.coverage-report-path }}
if-no-files-found: warn
- if: always()
run: |
COVERAGE='${{ inputs.coverage }}'
PR_COMMENT='${{ inputs.coverage-pr-comment }}'
EVENT='${{ github.event_name }}'
PR_NUMBER='${{ github.event.pull_request.number }}'
REPO='${{ github.repository }}'
RUN_ID='${{ github.run_id }}'
ARTIFACT_NAME='${{ inputs.coverage-artifact-name }}'
MARKER="<!-- tracecov-coverage-report -->"
if [[ "$COVERAGE" != "true" || "$PR_COMMENT" != "true" ]]; then
exit 0
fi
if [[ "$EVENT" != "pull_request" && "$EVENT" != "pull_request_target" ]]; then
exit 0
fi
if [[ ! -f /tmp/_st_coverage.md ]]; then
exit 0
fi
ARTIFACT_ID=$(gh api "repos/$REPO/actions/runs/$RUN_ID/artifacts" \
--jq ".artifacts[] | select(.name == \"$ARTIFACT_NAME\") | .id" 2>/dev/null | head -1)
{
echo "$MARKER"
cat /tmp/_st_coverage.md
if [[ -n "$ARTIFACT_ID" ]]; then
echo ""
echo "[Download full HTML report](https://github.com/$REPO/actions/runs/$RUN_ID/artifacts/$ARTIFACT_ID)"
fi
} > /tmp/_st_pr_body.md
COMMENT_ID=$(gh api "repos/$REPO/issues/$PR_NUMBER/comments" \
--jq ".[] | select(.body | startswith(\"$MARKER\")) | .id" 2>/dev/null | head -1)
if [[ -n "$COMMENT_ID" ]]; then
gh api "repos/$REPO/issues/comments/$COMMENT_ID" \
-X PATCH --field body=@/tmp/_st_pr_body.md || true
else
gh api "repos/$REPO/issues/$PR_NUMBER/comments" \
-X POST --field body=@/tmp/_st_pr_body.md || true
fi
shell: bash
env:
GH_TOKEN: ${{ github.token }}