Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit 043a27f

Browse files
author
Hendrik van Antwerpen
committed
Try to prevent unnecessary runs
1 parent 8fb0dd0 commit 043a27f

File tree

1 file changed

+81
-22
lines changed

1 file changed

+81
-22
lines changed

.github/workflows/perf.yml

Lines changed: 81 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,70 @@ on:
66
env:
77
BASE_REPO: ${{ github.event.pull_request.base.repo.owner.login }}/${{ github.event.pull_request.base.repo.name }}
88
BASE_SHA: ${{ github.event.pull_request.base.sha }}
9-
BASE_MASSIF_OUT: base-perf.out
10-
BASE_REPORT: base-perf.txt
9+
BASE_DIR: base
1110
BASE_ARTIFACT: base-perf-results
1211
HEAD_REPO: ${{ github.event.pull_request.head.repo.owner.login }}/${{ github.event.pull_request.head.repo.name }}
1312
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
14-
HEAD_MASSIF_OUT: head-perf.out
15-
HEAD_REPORT: head-perf.txt
13+
HEAD_DIR: head
1614
HEAD_ARTIFACT: head-perf-results
1715
TEST_REPO: microsoft/TypeScript
1816
TEST_REF: v4.9.5
1917
TEST_DIR: test
2018
TEST_SRC: src/compiler
19+
MASSIF_OUT: perf.out
20+
MASSIF_REPORT: perf.txt
2121
TSSG_TS: tree-sitter-stack-graphs-typescript
2222

2323
jobs:
24+
##
25+
## Determine relevant changes
26+
##
27+
changes:
28+
runs-on: ubuntu-latest
29+
outputs:
30+
base-sha: ${{ env.BASE_SHA }}
31+
head-sha: ${{ env.HEAD_SHA }}
32+
done: ${{ steps.done.outputs.cache-hit }}
33+
steps:
34+
- name: "Checkout base code"
35+
uses: actions/checkout@v3
36+
with:
37+
repository: ${{ env.BASE_REPO }}
38+
ref: ${{ env.BASE_SHA }}
39+
path: ${{ env.BASE_DIR }}
40+
fetch-depth: 0
41+
- name: Find last relevant base commit
42+
run: |
43+
printf 'BASE_SHA=%s\n' "$(git rev-list -1 ${{ env.BASE_SHA }} -- stack-graphs)" >> $GITHUB_ENV
44+
working-directory: ${{ env.BASE_DIR }}
45+
- name: "Checkout head code"
46+
uses: actions/checkout@v3
47+
with:
48+
repository: ${{ env.HEAD_REPO }}
49+
ref: ${{ env.HEAD_SHA }}
50+
path: ${{ env.HEAD_DIR }}
51+
fetch-depth: 0
52+
- name: "Find last relevant head commit"
53+
run: |
54+
printf 'HEAD_SHA=%s\n' "$(git rev-list -1 ${{ env.HEAD_SHA }} -- stack-graphs)" >> $GITHUB_ENV
55+
working-directory: ${{ env.HEAD_DIR }}
56+
- name: "Check cached status"
57+
id: done
58+
uses: actions/cache/restore@v3
59+
with:
60+
path: done
61+
key: ${{ runner.os }}-perf-tested-${{ env.BASE_REPO }}@${{ env.BASE_SHA }}-${{ env.HEAD_REPO }}@${{ env.HEAD_SHA }}-${{ env.TEST_REPO }}@${{ env.TEST_REF }}/${{ env.TEST_SRC }}
62+
lookup-only: 'true'
63+
2464
##
2565
## Base performance
2666
##
2767
base-perf:
2868
runs-on: ubuntu-latest
69+
needs: changes
70+
if: needs.changes.outputs.done != 'true'
2971
env:
30-
BASE_DIR: base
72+
BASE_SHA: ${{ needs.changes.outputs.base-sha }}
3173
steps:
3274
#
3375
# Install tools
@@ -62,8 +104,8 @@ jobs:
62104
id: cache-base-result
63105
uses: actions/cache@v3
64106
with:
65-
path: ${{ env.BASE_MASSIF_OUT }}
66-
key: ${{ runner.os }}-${{ env.BASE_REPO }}@${{ env.BASE_SHA }}-${{ env.TEST_REPO }}@${{ env.TEST_REF }}/${{ env.TEST_SRC }}
107+
path: ${{ env.MASSIF_OUT }}
108+
key: ${{ runner.os }}-perf-result-${{ env.BASE_REPO }}@${{ env.BASE_SHA }}-${{ env.TEST_REPO }}@${{ env.TEST_REF }}/${{ env.TEST_SRC }}
67109
#
68110
# Build code
69111
#
@@ -88,10 +130,10 @@ jobs:
88130
run: |
89131
valgrind \
90132
--tool=massif \
91-
--massif-out-file=${{ env.BASE_MASSIF_OUT }} \
133+
--massif-out-file=${{ env.MASSIF_OUT }} \
92134
${{ env.BASE_DIR }}/target/release/${{ env.TSSG_TS }} \
93135
analyze --max-file-time=30 --hide-error-details -- ${{ env.TEST_DIR }}/${{ env.TEST_SRC }}
94-
ms_print ${{ env.BASE_MASSIF_OUT }} > ${{ env.BASE_REPORT }}
136+
ms_print ${{ env.MASSIF_OUT }} > ${{ env.MASSIF_REPORT }}
95137
#
96138
# Upload results
97139
#
@@ -100,15 +142,17 @@ jobs:
100142
with:
101143
name: ${{ env.BASE_ARTIFACT }}
102144
path: |
103-
${{ env.BASE_MASSIF_OUT }}
104-
${{ env.BASE_REPORT }}
145+
${{ env.MASSIF_OUT }}
146+
${{ env.MASSIF_REPORT }}
105147
##
106148
## Head performance
107149
##
108150
head-perf:
109151
runs-on: ubuntu-latest
152+
needs: changes
153+
if: needs.changes.outputs.done != 'true'
110154
env:
111-
HEAD_DIR: head
155+
HEAD_SHA: ${{ needs.changes.outputs.head-sha }}
112156
steps:
113157
#
114158
# Install tools
@@ -143,8 +187,8 @@ jobs:
143187
id: cache-head-result
144188
uses: actions/cache@v3
145189
with:
146-
path: ${{ env.HEAD_MASSIF_OUT }}
147-
key: ${{ runner.os }}-${{ env.HEAD_REPO }}@${{ env.HEAD_SHA}}-${{ env.TEST_REPO }}@${{ env.TEST_REF }}/${{ env.TEST_SRC }}
190+
path: ${{ env.MASSIF_OUT }}
191+
key: ${{ runner.os }}-perf-result-${{ env.HEAD_REPO }}@${{ env.HEAD_SHA }}-${{ env.TEST_REPO }}@${{ env.TEST_REF }}/${{ env.TEST_SRC }}
148192
#
149193
# Build code
150194
#
@@ -169,10 +213,10 @@ jobs:
169213
run: |
170214
valgrind \
171215
--tool=massif \
172-
--massif-out-file=${{ env.HEAD_MASSIF_OUT }} \
216+
--massif-out-file=${{ env.MASSIF_OUT }} \
173217
${{ env.HEAD_DIR }}/target/release/${{ env.TSSG_TS }} \
174218
analyze --max-file-time=30 --hide-error-details -- ${{ env.TEST_DIR }}/${{ env.TEST_SRC }}
175-
ms_print ${{ env.HEAD_MASSIF_OUT }} > ${{ env.HEAD_REPORT }}
219+
ms_print ${{ env.MASSIF_OUT }} > ${{ env.MASSIF_REPORT }}
176220
#
177221
# Upload results
178222
#
@@ -181,17 +225,21 @@ jobs:
181225
with:
182226
name: ${{ env.HEAD_ARTIFACT }}
183227
path: |
184-
${{ env.HEAD_MASSIF_OUT }}
185-
${{ env.HEAD_REPORT }}
228+
${{ env.MASSIF_OUT }}
229+
${{ env.MASSIF_REPORT }}
186230
##
187231
## Performance summary
188232
##
189233
perf-summary:
190234
runs-on: ubuntu-latest
191235
needs:
236+
- changes
192237
- base-perf
193238
- head-perf
239+
if: needs.changes.outputs.done != 'true'
194240
env:
241+
BASE_SHA: ${{ needs.changes.outputs.base-sha }}
242+
HEAD_SHA: ${{ needs.changes.outputs.head-sha }}
195243
SRC_DIR: src
196244
COMMENT_JSON: perf-summary.json
197245
steps:
@@ -209,12 +257,16 @@ jobs:
209257
uses: actions/download-artifact@v3
210258
with:
211259
name: ${{ env.BASE_ARTIFACT }}
260+
path: ${{ env.BASE_ARTIFACT }}
212261
- run: ls -l
262+
working-directory: ${{ env.BASE_ARTIFACT }}
213263
- name: Download head results
214264
uses: actions/download-artifact@v3
215265
with:
216266
name: ${{ env.HEAD_ARTIFACT }}
267+
path: ${{ env.HEAD_ARTIFACT }}
217268
- run: ls -l
269+
working-directory: ${{ env.HEAD_ARTIFACT }}
218270
#
219271
# Create report
220272
#
@@ -226,16 +278,23 @@ jobs:
226278
- name: Generate summary
227279
run: |
228280
${{ env.SRC_DIR }}/script/ci-perf-summary-md \
229-
${{ env.BASE_MASSIF_OUT }} \
230-
${{ env.HEAD_MASSIF_OUT }} \
231-
'Comparing base ${{ env.BASE_REPO }}@${{ env.BASE_SHA }} with head ${{ env.HEAD_REPO }}@${{ env.HEAD_SHA }} on [${{ env.TEST_REPO }}@${{ env.TEST_REF }}](${{ github.server_url }}/${{ env.TEST_REPO }}/tree/${{ env.TEST_REF }}). For details see [workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) artifacts.' \
281+
${{ env.BASE_ARTIFACT }}/${{ env.MASSIF_OUT }} \
282+
${{ env.HEAD_ARTIFACT }}/${{ env.MASSIF_OUT }} \
283+
'Comparing base ${{ env.BASE_REPO }}@${{ env.BASE_SHA }} with head ${{ env.HEAD_REPO }}@${{ env.HEAD_SHA }} on [${{ env.TEST_REPO }}@${{ env.TEST_REF }}](${{ github.server_url }}/${{ env.TEST_REPO }}/tree/${{ env.TEST_REF }}). For details see [workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) artifacts. _Note that performance is tested on the last commits with changes in `stack-graphs`._' \
232284
| ${{ env.SRC_DIR }}/script/ci-comment-json > ${{ env.COMMENT_JSON }}
233285
- name: Add summary comment to PR
234286
run: |
235287
curl \
236288
-X POST \
237289
-H "Accept: application/vnd.github+json" \
238-
-H "Authorization: Bearer ${{ github.TOKEN }}" \
290+
-H "Authorization: Bearer ${{ github.token }}" \
239291
-H "X-GitHub-Api-Version: 2022-11-28" \
240292
${{ github.event.pull_request.comments_url }} \
241293
-d '@${{ env.COMMENT_JSON }}'
294+
- name: Create status marker
295+
run: touch done
296+
- name: "Cache status"
297+
uses: actions/cache/save@v3
298+
with:
299+
path: done
300+
key: ${{ runner.os }}-perf-tested-${{ env.BASE_REPO }}@${{ env.BASE_SHA }}-${{ env.HEAD_REPO }}@${{ env.HEAD_SHA }}-${{ env.TEST_REPO }}@${{ env.TEST_REF }}/${{ env.TEST_SRC }}

0 commit comments

Comments
 (0)