Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
121 lines (114 loc) · 4.8 KB
/
Copy pathaction.yml
File metadata and controls
121 lines (114 loc) · 4.8 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
name: typescript-perf
description: Measure what your TypeScript types cost on each pull request, against the base branch and your budget.
author: Martin Ferret
branding:
icon: activity
color: blue
inputs:
project:
description: tsconfig to measure, relative to working-directory.
default: tsconfig.json
working-directory:
description: Directory of the project (where tsconfig.json and node_modules are).
default: .
runs:
description: Measured runs per side. More runs, tighter numbers, longer job.
default: "3"
base:
description: Git ref to compare with. Default, the pull request's base branch.
default: ""
fail-on:
description: Fail when a metric grows more than this, e.g. "instantiations:5%,checkTimeMs:15%". Empty, never fail on the comparison.
default: ""
fail-on-budget:
description: Fail the job when typescript-perf.config.ts has a budget and it is exceeded.
default: "true"
comment:
description: Post (and update) one comment on the pull request with the results.
default: "true"
why:
description: Attribute instantiation changes to declarations (one trace per side; slower).
default: "false"
version:
description: typescript-perf version to run.
default: "0.2.1"
github-token:
description: Token used to post the comment. Needs pull-requests write.
default: ${{ github.token }}
outputs:
report:
description: Path to the JSON report (schema typescript-perf/v1).
value: ${{ steps.run.outputs.report }}
failed:
description: '"true" when --fail-on or the budget failed.'
value: ${{ steps.run.outputs.failed }}
runs:
using: composite
steps:
- name: Fetch the base ref
shell: bash
working-directory: ${{ inputs.working-directory }}
env:
BASE: ${{ inputs.base || github.base_ref }}
run: |
if [ -z "$BASE" ]; then echo "::error::typescript-perf: no base ref (set the 'base' input outside pull requests)"; exit 2; fi
git fetch --no-tags --depth=1 origin "$BASE"
- name: Compare with the base branch
id: run
shell: bash
working-directory: ${{ inputs.working-directory }}
env:
BASE: ${{ inputs.base || github.base_ref }}
PROJECT: ${{ inputs.project }}
RUNS: ${{ inputs.runs }}
FAIL_ON: ${{ inputs.fail-on }}
WHY: ${{ inputs.why }}
VERSION: ${{ inputs.version }}
OUT: ${{ runner.temp }}/typescript-perf
run: |
mkdir -p "$OUT"
args=(compare "origin/$BASE" --project "$PROJECT" --runs "$RUNS")
[ -n "$FAIL_ON" ] && args+=(--fail-on "$FAIL_ON")
[ "$WHY" = "true" ] && args+=(--why)
set +e
npx --yes "typescript-perf@$VERSION" "${args[@]}" --markdown --json-file "$OUT/report.json" > "$OUT/comment.md"
code=$?
set -e
if [ "$code" -ge 2 ] || [ ! -s "$OUT/report.json" ]; then echo "::error::typescript-perf failed (exit $code)"; cat "$OUT/comment.md"; exit 2; fi
echo "report=$OUT/report.json" >> "$GITHUB_OUTPUT"
echo "failed=$([ "$code" = 1 ] && echo true || echo false)" >> "$GITHUB_OUTPUT"
cat "$OUT/comment.md" >> "$GITHUB_STEP_SUMMARY"
- name: Comment on the pull request
if: inputs.comment == 'true' && github.event.pull_request.number
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
PR: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
BODY_FILE: ${{ runner.temp }}/typescript-perf/comment.md
run: |
# One sticky comment, found by its <!-- typescript-perf --> marker.
id=$(gh api "repos/$REPO/issues/$PR/comments" --paginate --jq '.[] | select(.body | startswith("<!-- typescript-perf -->")) | .id' | head -n1)
if [ -n "$id" ]; then
gh api -X PATCH "repos/$REPO/issues/comments/$id" -F "body=@$BODY_FILE" > /dev/null
else
gh api -X POST "repos/$REPO/issues/$PR/comments" -F "body=@$BODY_FILE" > /dev/null
fi
- name: Upload the report
uses: actions/upload-artifact@v4
with:
name: typescript-perf-report
path: ${{ runner.temp }}/typescript-perf/
if-no-files-found: ignore
- name: Outcome
shell: bash
env:
FAILED: ${{ steps.run.outputs.failed }}
FAIL_ON_BUDGET: ${{ inputs.fail-on-budget }}
FAIL_ON: ${{ inputs.fail-on }}
REPORT: ${{ steps.run.outputs.report }}
run: |
if [ "$FAILED" != "true" ]; then exit 0; fi
budget=$(node -e 'const r=require(process.env.REPORT);process.stdout.write(String(r.comparison.failures.length===0&&r.budget&&!r.budget.passed))')
if [ "$budget" = "true" ] && [ "$FAIL_ON_BUDGET" != "true" ]; then echo "typescript-perf: budget exceeded (not failing: fail-on-budget is false)"; exit 0; fi
echo "::error::typescript-perf: see the report"; exit 1