Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
93 lines (93 loc) · 3.89 KB
/
Copy pathaction.yml
File metadata and controls
93 lines (93 loc) · 3.89 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
name: traceperf
description: Fail a pull request that adds database queries or HTTP calls per request (an N+1), and comment what changed
branding:
icon: activity
color: orange
inputs:
run:
description: 'Arguments for `traceperf run`: the app and its paths, e.g. "dist/server.js --path /orders --path /users/1". Leave empty to use traceperf.config.json.'
required: false
default: ''
test:
description: 'Run this test command under `traceperf test` instead of `traceperf run`, e.g. "npm test": counts the calls per request your tests make'
required: false
default: ''
baseline:
description: Committed baseline file (create it with `npx traceperf run ... --save-baseline perf-baseline.json`)
required: false
default: perf-baseline.json
comment:
description: Post (and update) one comment on the pull request with the result
required: false
default: 'true'
fail:
description: Fail the job when a route makes more calls per request than the baseline
required: false
default: 'true'
version:
description: traceperf version to run (npm version or range, or the path of a local build)
required: false
default: '1'
github-token:
description: Token for the comment (needs pull-requests write permission)
required: false
default: ${{ github.token }}
outputs:
regressed:
description: '"true" when a route makes more calls per request than the baseline'
value: ${{ steps.run.outputs.regressed }}
runs:
using: composite
steps:
- id: run
shell: bash
env:
TP_ARGS: ${{ inputs.run }}
TP_TEST: ${{ inputs.test }}
TP_BASELINE: ${{ inputs.baseline }}
TP_VERSION: ${{ inputs.version }}
run: |
report="$RUNNER_TEMP/traceperf.md"
set +e
# shellcheck disable=SC2086 # the arguments are a word list on purpose
case "$TP_VERSION" in
# A local build (this repository's own CI tests the action with it)
./*|/*) cli=(node "$TP_VERSION/dist/cli.js") ;;
*) cli=(npx --yes "traceperf@$TP_VERSION") ;;
esac
if [ -n "$TP_TEST" ]; then
# shellcheck disable=SC2086 # the test command is a word list on purpose
"${cli[@]}" test --baseline "$TP_BASELINE" --markdown "$report" -- $TP_TEST
else
"${cli[@]}" run $TP_ARGS --baseline "$TP_BASELINE" --markdown "$report"
fi
code=$?
set -e
if [ ! -s "$report" ]; then
printf '### traceperf: the run failed before it produced a report (exit %s)\n\nSee the job log.\n' "$code" > "$report"
fi
cat "$report" >> "$GITHUB_STEP_SUMMARY"
echo "report=$report" >> "$GITHUB_OUTPUT"
echo "code=$code" >> "$GITHUB_OUTPUT"
if [ "$code" -ne 0 ]; then echo "regressed=true" >> "$GITHUB_OUTPUT"; else echo "regressed=false" >> "$GITHUB_OUTPUT"; fi
- if: inputs.comment == 'true' && github.event_name == 'pull_request'
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
REPORT: ${{ steps.run.outputs.report }}
PR: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
# One comment per PR, updated on every push (found by its marker)
body="$(printf '<!-- traceperf-action -->\n%s' "$(cat "$REPORT")")"
id="$(gh api "repos/$REPO/issues/$PR/comments" --paginate --jq '.[] | select(.body | startswith("<!-- traceperf-action -->")) | .id' | head -n 1)"
if [ -n "$id" ]; then
gh api --method PATCH "repos/$REPO/issues/comments/$id" -f body="$body" > /dev/null
else
gh api --method POST "repos/$REPO/issues/$PR/comments" -f body="$body" > /dev/null
fi
- if: inputs.fail == 'true' && steps.run.outputs.code != '0'
shell: bash
run: |
echo "traceperf: more calls per request than ${{ inputs.baseline }}, or the run failed (see the report above)"
exit 1