-
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.
Merge pull request #93 from takanotume24/feature/79__automate_app_ver…
…sion_changes feat: Automate version management and update Tauri application config…
- Loading branch information
Showing
4 changed files
with
168 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 |
---|---|---|
|
@@ -50,6 +50,40 @@ jobs: | |
|
||
- name: install frontend dependencies | ||
run: npm install # change this to npm, pnpm or bun depending on which one you use. | ||
|
||
- uses: tauri-apps/tauri-action@v0 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
args: ${{ matrix.args }} | ||
|
||
- name: Extract version from branch name | ||
id: extract_version | ||
run: | | ||
VERSION=${GITHUB_REF#refs/heads/release/} | ||
if [[ -z "$VERSION" ]]; then | ||
echo "Error: Version could not be extracted from the branch name." | ||
exit 1 | ||
fi | ||
echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
- name: Update version number | ||
run: ./script/update_version $VERSION | ||
|
||
- name: Set up Git | ||
run: | | ||
git config --global user.name "github-actions[bot]" | ||
git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
- name: Commit changes | ||
run: | | ||
git add . | ||
git commit -m "Automated commit from GitHub Actions" | ||
- name: Push changes | ||
uses: ad-m/[email protected] | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- uses: tauri-apps/tauri-action@v0 | ||
env: | ||
|
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import json | ||
import argparse | ||
import sys | ||
from pathlib import 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) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
set -euxo pipefail | ||
cd "$(dirname "$0")/../" | ||
|
||
version="$1" | ||
npm version "${version}" --git-tag-version false | ||
python3 ./script/update_tauri_version.py "${version}" "./src-tauri/tauri.conf.json" | ||
python3 ./script/update_cargo_version.py "${version}" "./src-tauri/Cargo.toml" |