github.com/facebookincubator/ttpforge@v1.0.13-0.20240405153150-5ae801628835/example-ttps/actions/edit-file/replace.yaml (about) 1 --- 2 api_version: 2.0 3 uuid: aac712b5-b5d4-4074-85ea-68a763172560 4 name: edit_file_replace 5 description: | 6 This TTP shows you how to use the edit_file action type 7 to modify files and replace string literals 8 or regexp matches with new strings 9 args: 10 - name: test_file_path 11 type: path 12 description: The path at which the temporary test file should be created 13 default: /tmp/ttpforge_edit_file_replace 14 steps: 15 - name: create-tmp-file 16 create_file: {{.Args.test_file_path}} 17 contents: | 18 this_will_be_replaced 19 and another this_will_be_replaced 20 multi-line strings can 21 also be replaced 22 you can comment out entire sections using capture groups 23 entire_function_call( 24 'this function call will be commented out' 25 ); 26 overwrite: true 27 - name: edit_test_file 28 edit_file: {{.Args.test_file_path}} 29 edits: 30 - description: | 31 Replace all occurrences of a string literal 32 with another string literal. 33 old: this_will_be_replaced 34 new: single_line_literal_replacement 35 - description: Same as above, but with multiple lines. 36 old: | 37 multi-line strings can 38 also be replaced 39 new: | 40 isn't that 41 cool 42 - description: | 43 You can do fancy edits with regular expressions, 44 like commenting out entire function calls in code. 45 old: (?P<fn_call>(?ms:^entire_function_call\(.*?\);$)) 46 new: "/*${fn_call}*/" 47 regexp: true 48 - name: display_result 49 inline: cat {{.Args.test_file_path}}