|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +copy_to_file_path="." |
| 4 | +version_tag="$1" |
| 5 | + |
| 6 | +echo "version tag: $version_tag" |
| 7 | +nargo_file_path="$copy_to_file_path/Nargo.toml" |
| 8 | + |
| 9 | +repo_url="https://github.com/AztecProtocol/aztec-packages.git" |
| 10 | +contracts_path="noir-projects/noir-contracts/contracts" |
| 11 | + |
| 12 | +# Check if the file exists |
| 13 | +if [ ! -f "$nargo_file_path" ]; then |
| 14 | + echo "File not found: $nargo_file_path" |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +# Update the tag in the Nargo.toml file |
| 19 | +while IFS= read -r line; do |
| 20 | + if [[ $line == *tag=* ]]; then |
| 21 | + # Extract the dependency name for logging purposes |
| 22 | + dependency_name=$(echo $line | grep -oP '(?<=\").+?(?=\")' | head -1) |
| 23 | + # Update the tag |
| 24 | + sed -i "s|\($dependency_name.*tag=\"\)[^\"]*|\1$version_tag|" $nargo_file_path |
| 25 | + echo "Updated tag for $dependency_name to $version_tag" |
| 26 | + fi |
| 27 | +done < <( |
| 28 | + sed -n '/^\[dependencies\]/,/^$/p' $nargo_file_path | grep -v '^\[dependencies\]' | awk NF |
| 29 | +) |
| 30 | + |
| 31 | +# Extract the value of the 'name' field |
| 32 | +name_value=$(grep "^name\s*=" "$nargo_file_path" | sed 's/name\s*=\s*"\(.*\)"/\1/') |
| 33 | + |
| 34 | +# Check if name_value is not empty |
| 35 | +if [ -z "$name_value" ]; then |
| 36 | + echo "Name field not found or empty in the TOML file." |
| 37 | +else |
| 38 | + echo "The value of the 'name' field is: $name_value" |
| 39 | +fi |
| 40 | + |
| 41 | +# Check if this is running as a GitHub action |
| 42 | +if [ "$GITHUB_ACTIONS" == "true" ]; then |
| 43 | + tmp_dir="$GITHUB_WORKSPACE/tmp" |
| 44 | +else |
| 45 | + tmp_dir="$copy_to_file_path/tmp" |
| 46 | +fi |
| 47 | + |
| 48 | +# Clone the repository into a tmp folder |
| 49 | +git clone $repo_url $tmp_dir |
| 50 | +cd $tmp_dir && git checkout $version_tag && cd .. |
| 51 | + |
| 52 | +# Check if clone was successful |
| 53 | +if [ $? -eq 0 ]; then |
| 54 | + |
| 55 | + # Check if the directory exists |
| 56 | + if [ -d "$tmp_dir/$contracts_path/$name_value" ]; then |
| 57 | + echo "Directory found: $name_value" |
| 58 | + cp -r $tmp_dir/$contracts_path/$name_value/src/ $copy_to_file_path/ |
| 59 | + rm -rf $tmp_dir |
| 60 | + echo "Copied the contracts to $copy_to_file_path" |
| 61 | + # You can add additional commands here to handle the directory |
| 62 | + |
| 63 | + # Remove docs comments from the files |
| 64 | + find "$copy_to_file_path/src" -type f -name "*.nr" | while read file; do |
| 65 | + # Remove lines starting with '// docs:' |
| 66 | + sed -i '/[ \t]*\/\/ docs:.*/d' "$file" |
| 67 | + |
| 68 | + echo "Comments removed from $file" |
| 69 | + done |
| 70 | + else |
| 71 | + echo "Directory not found: $name_value" |
| 72 | + fi |
| 73 | +else |
| 74 | + echo "Failed to clone the repository" |
| 75 | +fi |
| 76 | + |
| 77 | +rm -rf $tmp_dir |
0 commit comments