-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from multiversx/integrate-sys-tests-ci
add python script to update go.mod with a specific hash in pipeline
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
requests==2.32.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import os | ||
import re | ||
import sys | ||
|
||
def update_go_mod_file(go_mod_path, new_hash): | ||
""" | ||
Update the go.mod file with the new commit hash. | ||
""" | ||
try: | ||
with open(go_mod_path, 'r') as file: | ||
content = file.read() | ||
# Print the original content for debugging | ||
print("Original go.mod content:") | ||
print(content) | ||
updated_content = re.sub(r'(github\.com/multiversx/mx-chain-go\s+)[^\s]+', f'github.com/multiversx/mx-chain-go {new_hash}', content) | ||
|
||
# Print updated content for verification | ||
print("Updated go.mod content:") | ||
print(updated_content) | ||
|
||
# Write the updated content back to the file | ||
with open(go_mod_path, 'w') as file: | ||
file.write(updated_content) | ||
|
||
print(f"Successfully updated go.mod with the latest commit hash: {new_hash}") | ||
except Exception as e: | ||
print(f"Failed to update go.mod file: {str(e)}") | ||
sys.exit(1) | ||
|
||
def run_go_mod_tidy(): | ||
""" | ||
Run `go mod tidy` to ensure the go.mod file is tidy. | ||
""" | ||
try: | ||
print("Running go mod tidy...") | ||
subprocess.run(['go', 'mod', 'tidy'], check=True) | ||
print("Successfully ran go mod tidy.") | ||
|
||
except subprocess.CalledProcessError as e: | ||
print(f"Failed to run go mod tidy: {e.stderr}") | ||
sys.exit(1) | ||
|
||
def main(): | ||
# Assuming the script is run from the root of mx-chain-simulator-go | ||
go_mod_path = './go.mod' | ||
|
||
if len(sys.argv) != 2: | ||
print("Usage: update-go-mod.py <commit_hash>") | ||
sys.exit(1) | ||
|
||
latest_commit_hash = sys.argv[1] | ||
|
||
print(f"go.mod path: {go_mod_path}") | ||
print(f"Latest commit hash received: {latest_commit_hash}") | ||
|
||
update_go_mod_file(go_mod_path, latest_commit_hash) | ||
|
||
# Run go mod tidy after updating go.mod | ||
run_go_mod_tidy() | ||
|
||
print("Python Script executed successfully.") | ||
|
||
if __name__ == "__main__": | ||
try: | ||
main() | ||
except Exception as e: | ||
print(f"Main() Script execution failed: {str(e)}") | ||
sys.exit(1) |