File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,23 +15,14 @@ const DIFFERENT_DIGEST = `sha256:${"0".repeat(64)}`;
1515
1616function dockerRunCommandContaining ( dockerfile : string , signature : string ) : string {
1717 const signatureIndex = dockerfile . indexOf ( signature ) ;
18- if ( signatureIndex === - 1 ) {
19- throw new Error ( `Expected Dockerfile RUN signature: ${ signature } ` ) ;
20- }
18+ expect ( signatureIndex , `Expected Dockerfile RUN signature: ${ signature } ` ) . not . toBe ( - 1 ) ;
2119 const runIndex = dockerfile . lastIndexOf ( "RUN set -eu;" , signatureIndex ) ;
22- if ( runIndex === - 1 ) {
23- throw new Error ( `Expected RUN instruction before ${ signature } ` ) ;
24- }
25- const runLines : string [ ] = [ ] ;
26- for ( const line of dockerfile . slice ( runIndex ) . split ( "\n" ) ) {
27- runLines . push ( line ) ;
28- if ( ! line . trimEnd ( ) . endsWith ( "\\" ) ) break ;
29- }
30- const lastLine = runLines [ runLines . length - 1 ] ?. trimEnd ( ) ?? "" ;
31- if ( lastLine . endsWith ( "\\" ) ) {
32- throw new Error ( `Expected complete RUN instruction containing ${ signature } ` ) ;
33- }
34- return runLines
20+ expect ( runIndex , `Expected RUN instruction before ${ signature } ` ) . not . toBe ( - 1 ) ;
21+ const linesAfterRun = dockerfile . slice ( runIndex ) . split ( "\n" ) ;
22+ const endIndex = linesAfterRun . findIndex ( ( line ) => ! line . trimEnd ( ) . endsWith ( "\\" ) ) ;
23+ expect ( endIndex , `Expected complete RUN instruction containing ${ signature } ` ) . toBeGreaterThan ( - 1 ) ;
24+ return linesAfterRun
25+ . slice ( 0 , endIndex + 1 )
3526 . join ( "\n" )
3627 . trim ( )
3728 . replace ( / ^ R U N \s + / , "" )
You can’t perform that action at this time.
0 commit comments