-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
119 lines (112 loc) · 4.27 KB
/
Copy pathaction.yml
File metadata and controls
119 lines (112 loc) · 4.27 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
name: "Profile diff"
description: "Profile a pytest suite, script, or callable on base and head, then comment a CPU/memory performance diff on the PR."
branding:
icon: "activity"
color: "purple"
inputs:
target:
description: >
profile_diff run target selector, passed through verbatim. Examples:
'--pytest tests/', '--script path/to/script.py', or
'--callable pkg.mod:func'.
required: true
python-version:
description: "Python version for actions/setup-python."
required: false
default: "3.x"
base-ref:
description: "Git ref or SHA to profile as the base."
required: false
default: ${{ github.event.pull_request.base.sha }}
top:
description: "Keep the top N functions by cumtime."
required: false
default: "30"
threshold-pct:
description: "Ignore cumtime movements below this percentage."
required: false
default: "5"
min-abs-ms:
description: "Ignore cumtime movements below this many milliseconds."
required: false
default: "0"
fail-on-regression:
description: "If 'true', fail the job when any hotspot regresses beyond the threshold."
required: false
default: "false"
github-token:
description: "Token with 'pull-requests: write' used to post the comment."
required: false
default: ${{ github.token }}
pr-number:
description: "PR number to comment on."
required: false
default: ${{ github.event.pull_request.number }}
runs:
using: "composite"
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
- name: Profile head (current checkout)
shell: bash
run: |
set -euo pipefail
export PYTHONPATH="${{ github.action_path }}:${PYTHONPATH:-}"
# The target selector goes LAST so a '--pytest ...' target can forward
# its own flags without colliding with profile_diff's options.
python -m profile_diff run \
--label head --top "${{ inputs.top }}" \
--out "${RUNNER_TEMP}/pd-head.json" \
${{ inputs.target }}
- name: Profile base (${{ inputs.base-ref }})
shell: bash
run: |
set -euo pipefail
export PYTHONPATH="${{ github.action_path }}:${PYTHONPATH:-}"
git fetch --no-tags --depth=1 origin "${{ inputs.base-ref }}" || true
git worktree add --detach "${RUNNER_TEMP}/pd-base" "${{ inputs.base-ref }}"
( cd "${RUNNER_TEMP}/pd-base" && \
python -m profile_diff run \
--label base --top "${{ inputs.top }}" \
--out "${RUNNER_TEMP}/pd-base.json" \
${{ inputs.target }} )
git worktree remove --force "${RUNNER_TEMP}/pd-base"
- name: Compare and render Markdown
shell: bash
run: |
set -euo pipefail
export PYTHONPATH="${{ github.action_path }}:${PYTHONPATH:-}"
python -m profile_diff compare \
"${RUNNER_TEMP}/pd-base.json" "${RUNNER_TEMP}/pd-head.json" \
--threshold-pct "${{ inputs.threshold-pct }}" \
--min-abs-ms "${{ inputs.min-abs-ms }}" \
--top "${{ inputs.top }}" \
--format markdown --out "${RUNNER_TEMP}/pd-diff.md"
echo "----- profile-diff report -----"
cat "${RUNNER_TEMP}/pd-diff.md"
- name: Comment on PR
if: ${{ inputs.github-token != '' && inputs.pr-number != '' }}
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
GITHUB_REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ inputs.pr-number }}
run: |
set -euo pipefail
export PYTHONPATH="${{ github.action_path }}:${PYTHONPATH:-}"
python -m profile_diff comment "${RUNNER_TEMP}/pd-diff.md"
- name: Enforce regression gate
if: ${{ inputs.fail-on-regression == 'true' }}
shell: bash
run: |
set -euo pipefail
export PYTHONPATH="${{ github.action_path }}:${PYTHONPATH:-}"
# Re-run compare purely for its exit code so the comment is posted first.
python -m profile_diff compare \
"${RUNNER_TEMP}/pd-base.json" "${RUNNER_TEMP}/pd-head.json" \
--threshold-pct "${{ inputs.threshold-pct }}" \
--min-abs-ms "${{ inputs.min-abs-ms }}" \
--top "${{ inputs.top }}" \
--format text --fail-on-regression >/dev/null