-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eat: Add script to update Cargo version and modify Tauri config
- New script `update_cargo_version.py` added to update the version in Cargo.toml. - Refactored `update_tauri_version.py` to modify the version in `tauri.conf.json` instead of Cargo.toml. - Updated `update_version.sh` to call the new `update_cargo_version.py` and the modified `update_tauri_version.py`. - Set initial version in `tauri.conf.json` to "0.2.0".
- Loading branch information
1 parent
3a28e50
commit 4f84626
Showing
4 changed files
with
124 additions
and
64 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,86 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import re | ||
from typing import List | ||
from pathlib import Path | ||
|
||
def read_file(file_path: Path) -> List[str]: | ||
"""Reads the file and returns its lines.""" | ||
try: | ||
with open(file_path, 'r', encoding='utf-8') as file: | ||
return file.readlines() | ||
except FileNotFoundError: | ||
print(f"Error: The file {file_path} was not found.") | ||
sys.exit(1) | ||
except IOError: | ||
print(f"Error: Could not read the file {file_path}.") | ||
sys.exit(1) | ||
|
||
def write_file(file_path: Path, lines: List[str]) -> None: | ||
"""Writes the given lines to the file.""" | ||
try: | ||
with open(file_path, 'w', encoding='utf-8') as file: | ||
file.writelines(lines) | ||
except IOError: | ||
print(f"Error: Could not write to the file {file_path}.") | ||
sys.exit(1) | ||
|
||
def update_version(lines: List[str], new_version: str) -> List[str]: | ||
"""Updates the version in the specified lines and returns updated lines.""" | ||
in_package_section = False | ||
version_updated = False | ||
pattern = re.compile(r'^version\s*=\s*".*"$') | ||
current_version = None | ||
|
||
def process_line(line: str) -> str: | ||
nonlocal in_package_section, version_updated, current_version | ||
|
||
if line.strip() == "[package]": | ||
in_package_section = True | ||
elif line.strip().startswith("[") and in_package_section: | ||
in_package_section = False | ||
|
||
if in_package_section and pattern.search(line): | ||
current_version_match = re.search(r'"([^"]+)"', line) | ||
if current_version_match: | ||
current_version = current_version_match.group(1) | ||
|
||
if current_version == new_version: | ||
print(f"No change in version. The current version is already {new_version}.") | ||
sys.exit(1) | ||
|
||
version_updated = True | ||
return f'version = "{new_version}"\n' | ||
|
||
return line | ||
|
||
updated_lines = list(map(process_line, lines)) | ||
|
||
if not version_updated: | ||
print("Error: No version entry was updated. Please ensure the [package] section exists and contains a version entry.") | ||
sys.exit(1) | ||
|
||
print(f"Updated version from {current_version} to {new_version}") | ||
return updated_lines | ||
|
||
def main(new_version: str, file_path: Path) -> None: | ||
"""Main function to update the version in the given file.""" | ||
lines = read_file(file_path) | ||
updated_lines = update_version(lines, new_version) | ||
write_file(file_path, updated_lines) | ||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) != 3: | ||
print("Usage: python update_version.py <new_version> <file_path>") | ||
sys.exit(1) | ||
|
||
new_version = sys.argv[1] | ||
file_path = Path(sys.argv[2]).absolute() | ||
|
||
# Ensure the file exists | ||
if not file_path.exists(): | ||
print(f"Error: The file {file_path} does not exist.") | ||
sys.exit(1) | ||
|
||
main(new_version, file_path) |
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 |
---|---|---|
@@ -1,67 +1,40 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import json | ||
import argparse | ||
import sys | ||
import re | ||
from typing import List | ||
from pathlib import Path | ||
|
||
def read_file(file_path: Path) -> List[str]: | ||
try: | ||
with open(file_path, 'r', encoding='utf-8') as file: | ||
return file.readlines() | ||
except FileNotFoundError: | ||
print(f"Error: The file {file_path} was not found.") | ||
sys.exit(1) | ||
except IOError: | ||
print(f"Error: Could not read the file {file_path}.") | ||
sys.exit(1) | ||
|
||
def write_file(file_path: Path, lines: List[str]) -> None: | ||
try: | ||
with open(file_path, 'w', encoding='utf-8') as file: | ||
file.writelines(lines) | ||
except IOError: | ||
print(f"Error: Could not write to the file {file_path}.") | ||
sys.exit(1) | ||
|
||
def update_version(lines: List[str], new_version: str) -> List[str]: | ||
in_package_section = False | ||
version_updated = False | ||
pattern = re.compile(r'^version\s*=\s*".*"$') | ||
|
||
def process_line(line: str) -> str: | ||
nonlocal in_package_section, version_updated | ||
|
||
if line.strip() == "[package]": | ||
in_package_section = True | ||
elif line.strip().startswith("[") and in_package_section: | ||
in_package_section = False | ||
|
||
if in_package_section and pattern.search(line): | ||
version_updated = True | ||
return f'version = "{new_version}"\n' | ||
|
||
return line | ||
|
||
updated_lines = list(map(process_line, lines)) | ||
|
||
if not version_updated: | ||
print("Error: No version entry was updated. Please ensure the [package] section exists and contains a version entry.") | ||
sys.exit(1) | ||
|
||
return updated_lines | ||
|
||
def main(new_version: str, file_path: Path) -> None: | ||
lines = read_file(file_path) | ||
updated_lines = update_version(lines, new_version) | ||
write_file(file_path, updated_lines) | ||
print(f"Version updated successfully to {new_version}") | ||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) != 3: | ||
print("Usage: python update_version.py <new_version> <file_path>") | ||
def update_version_in_config(file_path: Path, new_version: str) -> None: | ||
# Load the existing JSON configuration | ||
with open(file_path, 'r', encoding='utf-8') as file: | ||
config = json.load(file) | ||
|
||
# Update the version number | ||
current_version = config.get("version", "0.0.0") | ||
|
||
if new_version == current_version: | ||
print(f"No change in version. The current version is already {new_version}.") | ||
sys.exit(1) | ||
|
||
new_version = sys.argv[1] | ||
file_path = Path(sys.argv[2]).absolute().resolve(strict=True) | ||
main(new_version, file_path) | ||
config["version"] = new_version | ||
|
||
# Write the updated configuration back to the file | ||
with open(file_path, 'w', encoding='utf-8') as file: | ||
json.dump(config, file, indent=2) | ||
|
||
print(f"Updated version from {current_version} to {new_version}") | ||
|
||
def main() -> None: | ||
# Set up argument parser | ||
parser = argparse.ArgumentParser(description="Update version in Tauri configuration file.") | ||
parser.add_argument("new_version", help="New version to set.") | ||
parser.add_argument("file_path", help="Path to the Tauri configuration JSON file.") | ||
|
||
# Parse arguments | ||
args = parser.parse_args() | ||
|
||
file_path = Path(args.file_path).absolute().resolve(strict=True) | ||
# Update version in the configuration file | ||
update_version_in_config(file_path, args.new_version) | ||
|
||
if __name__ == "__main__": | ||
main() |
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
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