-
Notifications
You must be signed in to change notification settings - Fork 0
293 lines (259 loc) · 10.1 KB
/
run-experiment.yml
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
name: Run TestPilot experiment
on:
workflow_dispatch:
inputs:
packages:
description: "Packages to generate tests for"
default: "+benchmarks.txt"
snippetsFrom:
description: "Code snippets source"
default: "doc"
numSnippets:
description: 'Maximum number of snippets to include in each prompt, or "all"'
default: "all"
snippetLength:
description: "Maximum length of each snippet in lines"
default: "20"
temperatures:
description: "Sampling temperatures to try when obtaining completions (whitespace-separated)"
default: "0.0"
model:
description: "Which LLM API to use"
type: "string"
default: "llama-3-70b-instruct"
compareTo:
description: "Run number of previous run to compare to (leave empty to skip comparison)"
default: ""
skipSlowBenchmarks:
description: "Skip slow benchmarks"
type: boolean
default: false
debug_enabled:
type: boolean
description: "Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)"
default: false
# Run every weekday at 2:00 AM UTC
# schedule:
# - cron: '0 2 * * 1-5'
jobs:
setup:
runs-on: ubuntu-latest
outputs:
packages: "${{ steps.parse_packages.outputs.packages }}"
snippetsFrom: "${{ github.event.inputs.snippetsFrom || 'doc' }}"
snippetLength: "${{ github.event.inputs.snippetLength || '20' }}"
temperatures: "${{ github.event.inputs.temperatures || '0.0' }}"
numSnippets: "${{ github.event.inputs.numSnippets || 'all' }}"
model: "${{ github.event.inputs.model || 'llama-3-70b-instruct' }}"
template: './templates/template.hb'
retryTemplate: './templates/retry-template.hb'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 12
- id: parse_packages
run: |
packages=$(node ${GITHUB_WORKSPACE}/.github/parse_packages.js \
${{ github.event.inputs.skipSlowBenchmarks == 'true' && '--skip-slow-benchmarks' || '' }} \
"${{ github.event.inputs.packages || '+benchmarks.txt' }}")
echo "packages=$packages" >> $GITHUB_OUTPUT
benchmark:
needs:
- setup
runs-on: ubuntu-latest
continue-on-error: true
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.setup.outputs.packages) }}
steps:
- uses: actions/checkout@v3
with:
path: testpilot
- name: Install CodeQL 2.17.6
run: |
wget -q https://github.com/github/codeql-action/releases/download/codeql-bundle-v2.17.6/codeql-bundle-linux64.tar.gz
tar xzf codeql-bundle-linux64.tar.gz
echo "$GITHUB_WORKSPACE/codeql" >> $GITHUB_PATH
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 12
- name: Set up TestPilot
run: |
cd testpilot
npm run build
cd ql
codeql pack install
- name: Checkout github package repo
if: ${{ matrix.package.host == 'github.com' }}
uses: actions/checkout@v3
with:
repository: ${{ format('{0}/{1}', matrix.package.owner, matrix.package.repo) }}
ref: ${{ matrix.package.sha }}
path: "source"
- name: Checkout gitlab package repo
if: ${{ matrix.package.host == 'gitlab.com' }}
run: |
git clone ${{ format('https://gitlab.com/{0}/{1}', matrix.package.owner, matrix.package.repo) }} source
cd source
git checkout ${{ matrix.package.sha }}
- name: Determine package name
id: pkg-name
run: |
# name of the package
TESTPILOT_PACKAGE_NAME=$(cat source/${{ matrix.package.path }}/package.json | jq -r .name )
# some packages have a / in their names (looking at you, gitlab-js!)
if [[ "$TESTPILOT_PACKAGE_NAME" == *"/"* ]]; then
TESTPILOT_PACKAGE_NAME=${TESTPILOT_PACKAGE_NAME##*/}
fi
# path to the package within the repo checkout
TESTPILOT_PACKAGE_PATH="$GITHUB_WORKSPACE/$TESTPILOT_PACKAGE_NAME/${{ matrix.package.path }}"
# make sure there isn't already a directory with the same name
if [ -d "$TESTPILOT_PACKAGE_PATH" ]; then
echo "ERROR: $TESTPILOT_PACKAGE_PATH already exists"
exit 1
fi
# rename checkout, since some packages examine its name (looking at you, bluebird!)
mv source $TESTPILOT_PACKAGE_NAME
echo "Package name: $TESTPILOT_PACKAGE_NAME, path: $TESTPILOT_PACKAGE_PATH"
# export environment variables
echo "TESTPILOT_PACKAGE_NAME=$TESTPILOT_PACKAGE_NAME" >> $GITHUB_ENV
echo "TESTPILOT_PACKAGE_PATH=$TESTPILOT_PACKAGE_PATH" >> $GITHUB_ENV
echo "pkgName=$TESTPILOT_PACKAGE_NAME" >> $GITHUB_OUTPUT
- name: Install package, its dependencies, and test packages
run: |
cd $TESTPILOT_PACKAGE_PATH
npm i || npm i --legacy-peer-deps
# if matrix.package.dependencies is not empty, install them
if ! [ -z "${{ matrix.package.dependencies }}" ]; then
npm i ${{ matrix.package.dependencies }}
fi
npm run build || npm run prepack || echo 'Error with npm run build and npm run prepack'
npm i --no-save mocha
- name: Create CodeQL database
if: ${{ needs.setup.outputs.snippetsFrom == 'code' || needs.setup.outputs.snippetsFrom == 'both' }}
run: |
codeql database create --language=javascript "--source-root=$TESTPILOT_PACKAGE_PATH" -- ./db
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
# if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
- name: Generate tests
env:
TESTPILOT_LLM_API_ENDPOINT: '${{ secrets.TESTPILOT_LLM_API_ENDPOINT }}'
TESTPILOT_LLM_AUTH_HEADERS: '${{ secrets.TESTPILOT_LLM_AUTH_HEADERS }}'
run: |
cd testpilot
outputdir="results/$TESTPILOT_PACKAGE_NAME"
mkdir -p $outputdir
echo "Computing package statistics"
node benchmark/package_stats.js "$TESTPILOT_PACKAGE_PATH" > stats.json
echo "Generating tests for $TESTPILOT_PACKAGE_NAME"
export command="node benchmark/run.js \
--outputDir $outputdir \
--package "$TESTPILOT_PACKAGE_PATH" \
--temperatures "${{ needs.setup.outputs.temperatures }}" \
--model ${{ needs.setup.outputs.model }} \
--template ${{ needs.setup.outputs.template }} \
--retryTemplate ${{ needs.setup.outputs.retryTemplate }}"
echo "command: $command"
$command
mv stats.json $outputdir
- name: Calculate edit distance of generated tests
run: |
cd testpilot
outputdir="results/$TESTPILOT_PACKAGE_NAME"
node benchmark/editDistance.js --generatedTestsDir $outputdir --existingTestsDir $TESTPILOT_PACKAGE_PATH --pkgName $TESTPILOT_PACKAGE_NAME
mv similarityReport.json $outputdir
- name: Add non-trivial coverage data
run: |
cd testpilot
./.github/non_trivial_coverage.sh "results/$TESTPILOT_PACKAGE_NAME"
- name: Zip up results
run: |
cd testpilot
zip -r results.zip results
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: results-${{ steps.pkg-name.outputs.pkgName }}
path: "testpilot/results.zip"
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
# if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
combine_output:
name: Combine output from all benchmarks
needs:
- setup
- benchmark
runs-on: ubuntu-latest
steps:
- name: Download output zips
uses: actions/download-artifact@v2
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
# if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
- name: Combine output zips
run: |
mkdir results
for zip in results-*/results.zip
do
unzip -oq $zip
done
zip -r results.zip results
- name: Upload combined output files
uses: actions/upload-artifact@v2
with:
name: results-all
path: results.zip
generate-report:
needs:
- setup
- benchmark
- combine_output
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 12
- name: Set up TestPilot
run: |
npm run build
- name: Download artifacts for this run
uses: actions/download-artifact@v3
with:
name: results-all
path: results
- name: Download artifacts for comparison run
if: ${{ github.event.inputs.compareTo != '' }}
uses: dawidd6/action-download-artifact@v2
with:
run_number: ${{ github.event.inputs.compareTo }}
name: results-all
path: baseline
- name: print toJson(needs.setup.outputs for debugging
run: |
echo '${{ toJson(needs.setup.outputs) }}'
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
- name: Generate report
run: |
cd results
unzip results.zip
cd ..
echo '${{ toJson(needs.setup.outputs) }}' > config.json
if [ -d baseline ]; then
cd baseline
unzip results.zip
cd ..
baseline_artifact=baseline/results
else
baseline_artifact=''
fi
node ${GITHUB_WORKSPACE}/benchmark/generate_report.js ${{ needs.setup.outputs.model }} config.json results/results $baseline_artifact > $GITHUB_STEP_SUMMARY