@@ -6,13 +6,10 @@ import { VALID_TOOLS } from '../src/config';
66import { Benchmark } from '../src/extract' ;
77import { diff , Diff , DiffArray , DiffEdit , DiffNew } from 'deep-diff' ;
88import { getServerUrl } from '../src/git' ;
9- import assert from 'assert' ;
109import deepEq = require( 'deep-equal' ) ;
1110
1211function help ( ) : never {
13- throw new Error (
14- 'Usage: node ci_validate_modification.js before_data.js "benchmark name" [benchmark-data-repository-directory]' ,
15- ) ;
12+ throw new Error ( 'Usage: node ci_validate_modification.js "benchmark name" [benchmark-data-repository-directory]' ) ;
1613}
1714
1815async function exec ( cmd : string ) : Promise < string > {
@@ -28,8 +25,8 @@ async function exec(cmd: string): Promise<string> {
2825 } ) ;
2926}
3027
31- async function readDataJson ( file : string ) : Promise < DataJson > {
32- const content = await fs . readFile ( file , 'utf8' ) ;
28+ async function readDataJsonFromGit ( gitParams : string , ref : string ) : Promise < DataJson > {
29+ const content = await exec ( `git ${ gitParams } show ${ ref } :dev/bench/data.js` ) ;
3330 return JSON . parse ( content . slice ( SCRIPT_PREFIX . length ) ) ;
3431}
3532
@@ -207,7 +204,7 @@ function validateDiff(beforeJson: DataJson, afterJson: DataJson, expectedBenchNa
207204async function main ( ) {
208205 console . log ( 'Start validating modifications by action with args' , process . argv ) ;
209206
210- if ( process . argv . length !== 4 && process . argv . length !== 5 ) {
207+ if ( process . argv . length !== 3 && process . argv . length !== 4 ) {
211208 help ( ) ;
212209 }
213210
@@ -221,19 +218,14 @@ async function main() {
221218 throw new Error ( 'This script must be run at root directory of repository' ) ;
222219 }
223220
224- const beforeDataJs = path . resolve ( process . argv [ 2 ] ) ;
225- const expectedBenchName = process . argv [ 3 ] ;
226- const benchmarkDataDirectory = process . argv [ 4 ] ;
221+ const expectedBenchName = process . argv [ 2 ] ;
222+ const benchmarkDataDirectory = process . argv [ 3 ] ;
227223
228224 const additionalGitParams = benchmarkDataDirectory
229225 ? `--work-tree=${ benchmarkDataDirectory } --git-dir=${ benchmarkDataDirectory } /.git`
230226 : '' ;
231227
232228 console . log ( 'Validating modifications by action' ) ;
233- console . log ( ` data.js before action: ${ beforeDataJs } ` ) ;
234-
235- console . log ( 'Reading data.js before action as JSON' ) ;
236- const beforeJson = await readDataJson ( beforeDataJs ) ;
237229
238230 console . log ( 'Validating current branch' ) ;
239231 const branch = await exec ( `git ${ additionalGitParams } rev-parse --abbrev-ref HEAD` ) ;
@@ -264,18 +256,12 @@ async function main() {
264256 throw new Error ( `Unexpected auto commit message in log '${ latestCommitLog } '` ) ;
265257 }
266258
267- const dataResults = await Promise . allSettled ( [
268- readDataJson ( 'benchmark-data-repository/dev/bench/data.js' ) ,
269- readDataJson ( 'dev/bench/data.js' ) ,
270- ] ) ;
271-
272- const jsonResults = dataResults
273- . filter ( ( res ) : res is PromiseFulfilledResult < DataJson > => res . status === 'fulfilled' )
274- . map ( ( res ) => res . value ) ;
259+ console . log ( 'Reading data.js before action as JSON (HEAD~1)' ) ;
260+ const beforeJson = await readDataJsonFromGit ( additionalGitParams , 'HEAD~1' ) ;
275261
276- assert ( jsonResults . length > 0 && jsonResults . length <= 2 , 'Maximum 2 data.js files should be present in the repo' ) ;
262+ console . log ( 'Reading data.js after action as JSON (HEAD)' ) ;
263+ const afterJson = await readDataJsonFromGit ( additionalGitParams , 'HEAD' ) ;
277264
278- const afterJson = jsonResults [ 0 ] ;
279265 await exec ( `git ${ additionalGitParams } checkout -` ) ;
280266
281267 console . log ( 'Validating data.js both before/after action' ) ;
0 commit comments