diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index e6dd59f2c1..19f1323cf0 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -354,12 +354,20 @@ jobs: SN_LOG: "v" timeout-minutes: 2 - - name: create local user data - run: | - # 1 MB - python3 -c "with open('random.txt', 'wb') as f: f.write(bytearray([0xff] * 1 * 1024 * 1024))" - ./target/release/autonomi --log-output-dest=data-dir file upload random.txt - ./target/release/autonomi --log-output-dest=data-dir register create sample_new_register 1234 + - name: create local user file + run: echo random > random.txt + env: + SN_LOG: "v" + timeout-minutes: 2 + + - name: file upload + run: ./target/release/autonomi --log-output-dest=data-dir file upload random.txt + env: + SN_LOG: "v" + timeout-minutes: 2 + + - name: create a local register + run: ./target/release/autonomi --log-output-dest=data-dir register create sample_new_register 1234 env: SN_LOG: "v" timeout-minutes: 2 @@ -461,62 +469,59 @@ jobs: if: matrix.os == 'windows-latest' shell: pwsh run: | - # Initialize variables to empty - $NUM_OF_PUBLIC_FILES = "" - $NUM_OF_PRIVATE_FILES = "" - $NUM_OF_REGISTERS = "" - $NUM_OF_PUBLIC_FILES_IN_VAULT = "" - $NUM_OF_PRIVATE_FILES_IN_VAULT = "" - $NUM_OF_REGISTERS_IN_VAULT = "" - - # Execute commands and save outputs to files + $ErrorActionPreference = "Stop" ./target/release/autonomi --log-output-dest=data-dir file list > file_list.txt 2>&1 - ./target/release/autonomi register list | Select-String "register" > register_list.txt + ./target/release/autonomi register list > register_list.txt 2>&1 ./target/release/autonomi --log-output-dest=data-dir vault load > vault_data.txt 2>&1 + env: + SN_LOG: "v" + timeout-minutes: 15 - # Parse the files and extract numbers - $NUM_OF_PUBLIC_FILES = (Select-String "public" file_list.txt | ForEach-Object { $_ -match "\d+"; $matches[0] })[0] - $NUM_OF_PRIVATE_FILES = (Select-String "private" file_list.txt | ForEach-Object { $_ -match "\d+"; $matches[0] })[0] - $NUM_OF_REGISTERS = (Select-String "register" register_list.txt | ForEach-Object { $_ -match "\d+"; $matches[0] })[0] - - # Get the first word only (PowerShell handles this without additional parsing) - $NUM_OF_REGISTERS_first = $NUM_OF_REGISTERS -split '\s+' | Select-Object -First 1 - - Write-Output "NUM_OF_REGISTERS is $NUM_OF_REGISTERS_first" - - # Continue with vault data parsing - $NUM_OF_PUBLIC_FILES_IN_VAULT = (Select-String "public" vault_data.txt | ForEach-Object { $_ -match "\d+"; $matches[0] })[0] - $NUM_OF_PRIVATE_FILES_IN_VAULT = (Select-String "private" vault_data.txt | ForEach-Object { $_ -match "\d+"; $matches[0] })[0] - $NUM_OF_REGISTERS_IN_VAULT = (Select-String "register" vault_data.txt | ForEach-Object { $_ -match "\d+"; $matches[0] })[0] - - # Output summary - Write-Output "Total Num of local public files is $NUM_OF_PUBLIC_FILES and in vault is $NUM_OF_PUBLIC_FILES_IN_VAULT" - Write-Output "Total Num of local private files is $NUM_OF_PRIVATE_FILES and in vault is $NUM_OF_PRIVATE_FILES_IN_VAULT" - Write-Output "Total Num of local registers is $NUM_OF_REGISTERS_first and in vault is $NUM_OF_REGISTERS_IN_VAULT" - - # Clean up temporary files - Remove-Item -Force file_list.txt, register_list.txt, vault_data.txt - - # - name: Vault sync validation - # if: matrix.os == 'windows-latest' - # shell: python - # run: | - # import sys - - # # Define the values as environment variables - # NUM_OF_PUBLIC_FILES = int("$env:NUM_OF_PUBLIC_FILES") - # NUM_OF_PUBLIC_FILES_IN_VAULT = int("$env:NUM_OF_PUBLIC_FILES_IN_VAULT") - # NUM_OF_PRIVATE_FILES = int("$env:NUM_OF_PRIVATE_FILES") - # NUM_OF_PRIVATE_FILES_IN_VAULT = int("$env:NUM_OF_PRIVATE_FILES_IN_VAULT") - # NUM_OF_REGISTERS_FIRST = int("$env:NUM_OF_REGISTERS_first") - # NUM_OF_REGISTERS_IN_VAULT = int("$env:NUM_OF_REGISTERS_IN_VAULT") - - # # Assertions - # assert NUM_OF_PUBLIC_FILES == NUM_OF_PUBLIC_FILES_IN_VAULT, f"Error: Local public Files: {NUM_OF_PUBLIC_FILES} and vault public files: {NUM_OF_PUBLIC_FILES_IN_VAULT} are Not Equal" - # assert NUM_OF_PRIVATE_FILES == NUM_OF_PRIVATE_FILES_IN_VAULT, f"Error: Local private Files: {NUM_OF_PRIVATE_FILES} and vault private files: {NUM_OF_PRIVATE_FILES_IN_VAULT} are Not Equal" - # assert NUM_OF_REGISTERS_FIRST == NUM_OF_REGISTERS_IN_VAULT, f"Error: Local registers: {NUM_OF_REGISTERS_FIRST} and vault registers: {NUM_OF_REGISTERS_IN_VAULT} are Not Equal" - - # print("Vault synced successfully!") + - name: Vault sync validation + if: matrix.os == 'windows-latest' + shell: python + run: | + import re + def find_number_before_word(file_name, search_word): + """ + Reads a file and finds the number immediately preceding a specified word in a line. + + :param file_name: Name of the file to read. + :param search_word: Word to search for in the file. + :return: The number before the word as an integer, or None if not found. + """ + try: + with open(file_name, 'r') as file: + for line in file: + if search_word in line: + match = re.search(r'(\d+)\s+' + re.escape(search_word), line) + if match: + return int(match.group(1)) # Convert to integer + return None # Return None if no match is found + except FileNotFoundError: + print(f"Error: File '{file_name}' not found.") + return None + NUM_OF_PUBLIC_FILES = find_number_before_word("file_list.txt", "public") + print("NUM_OF_PUBLIC_FILES:", NUM_OF_PUBLIC_FILES) + NUM_OF_PRIVATE_FILES = find_number_before_word("file_list.txt", "private") + print("NUM_OF_PRIVATE_FILES:", NUM_OF_PRIVATE_FILES) + NUM_OF_REGISTERS_FILES = find_number_before_word("register_list.txt", "register") + print("NUM_OF_REGISTERS_FILES:", NUM_OF_REGISTERS_FILES) + NUM_OF_PUBLIC_FILES_IN_VAULT = find_number_before_word("vault_data.txt", "public") + print("NUM_OF_PUBLIC_FILES_IN_VAULT:", NUM_OF_PUBLIC_FILES_IN_VAULT) + NUM_OF_PRIVATE_FILES_IN_VAULT = find_number_before_word("vault_data.txt", "private") + print("NUM_OF_PRIVATE_FILES_IN_VAULT:", NUM_OF_PRIVATE_FILES_IN_VAULT) + NUM_OF_REGISTERS_IN_VAULT = find_number_before_word("vault_data.txt", "register") + print("NUM_OF_PRIVATE_FILES_IN_VAULT:", NUM_OF_PRIVATE_FILES_IN_VAULT) + + # Assertions + assert NUM_OF_PUBLIC_FILES == NUM_OF_PUBLIC_FILES_IN_VAULT, f"Error: Local public Files: {NUM_OF_PUBLIC_FILES} and vault public files: {NUM_OF_PUBLIC_FILES_IN_VAULT} are Not Equal" + assert NUM_OF_PRIVATE_FILES == NUM_OF_PRIVATE_FILES_IN_VAULT, f"Error: Local private Files: {NUM_OF_PRIVATE_FILES} and vault private files: {NUM_OF_PRIVATE_FILES_IN_VAULT} are Not Equal" + assert NUM_OF_REGISTERS_FILES == NUM_OF_REGISTERS_IN_VAULT, f"Error: Local registers: {NUM_OF_REGISTERS_FILES} and vault registers: {NUM_OF_REGISTERS_IN_VAULT} are Not Equal" + print("Vault synced successfully!") + env: + SN_LOG: "v" + timeout-minutes: 2 - name: load an existing vault from the network run: ./target/release/autonomi --log-output-dest=data-dir vault load