diff --git a/.ci/merge_versions.py b/.ci/merge_versions.py new file mode 100644 index 0000000..6393e72 --- /dev/null +++ b/.ci/merge_versions.py @@ -0,0 +1,82 @@ +import re +import sys + + +def parse_toml_deps(content): + """Extract dependency versions from TOML content.""" + deps = {} + in_deps = False + for line in content.split("\n"): + if line.strip() == "[dependencies]": + in_deps = True + continue + if in_deps and line.strip().startswith("["): + break + if in_deps and "=" in line and not line.strip().startswith("#"): + # Parse: package = "version" or package = { version = "version", ... } + match = re.match(r'^\s*(\S+)\s*=\s*["{].*version\s*=\s*"([^"]+)"', line) + if match: + deps[match.group(1)] = match.group(2) + else: + match = re.match(r'^\s*(\S+)\s*=\s*"([^"]+)"', line) + if match: + deps[match.group(1)] = match.group(2) + return deps + + +def update_template_versions(template_content, new_versions): + """Update versions in template while preserving Liquid syntax.""" + lines = template_content.split("\n") + result = [] + + for line in lines: + updated_line = line + # Skip Liquid control flow lines + if re.match(r"^\s*{%", line): + result.append(line) + continue + + # Check if this line has a dependency with version + for dep_name, new_version in new_versions.items(): + # Match: package = "version" + pattern1 = rf'^(\s*{re.escape(dep_name)}\s*=\s*")([^"]+)(".*)' + match = re.match(pattern1, updated_line) + if match: + updated_line = f"{match.group(1)}{new_version}{match.group(3)}" + break + + # Match: package = { version = "version", ... } + pattern2 = rf'^(\s*{re.escape(dep_name)}\s*=\s*{{[^}}]*version\s*=\s*")([^"]+)(".*)' + match = re.match(pattern2, updated_line) + if match: + updated_line = f"{match.group(1)}{new_version}{match.group(3)}" + break + + result.append(updated_line) + + return "\n".join(result) + + +if __name__ == "__main__": + # Read files + with open(sys.argv[1], "r") as f: + upgraded_content = f.read() + + with open(sys.argv[2], "r") as f: + template_content = f.read() + + # Extract new versions from upgraded Cargo.toml + new_versions = parse_toml_deps(upgraded_content) + + print(f"Found {len(new_versions)} dependencies:") + for dep, version in sorted(new_versions.items()): + print(f" {dep} -> {version}") + + # Update template while preserving Liquid syntax + updated_template = update_template_versions(template_content, new_versions) + + # Write updated template + with open(sys.argv[2], "w") as f: + f.write(updated_template) + + print("\nāœ… Template updated successfully!") diff --git a/.env.liquid b/.env.liquid new file mode 100644 index 0000000..4406b5a --- /dev/null +++ b/.env.liquid @@ -0,0 +1,9 @@ +# API Configuration +{{env_prefix}}_API_KEY=your-secret-api-key-here + +# Server Configuration +{{env_prefix}}_HOST=127.0.0.1 +{{env_prefix}}_PORT={{default_port}} + +# Logging +{{env_prefix}}_LOG_LEVEL={{default_log_level}} diff --git a/.genignore b/.genignore index edd13b3..c8d5dfa 100644 --- a/.genignore +++ b/.genignore @@ -1,3 +1,5 @@ +.ci/ +.github/ target/ Cargo.lock .env diff --git a/.github/workflows/dependency-check.yml b/.github/workflows/dependency-check.yml index eda5682..4406de1 100644 --- a/.github/workflows/dependency-check.yml +++ b/.github/workflows/dependency-check.yml @@ -93,10 +93,11 @@ jobs: run: | echo "šŸ“ Updating template with new dependency versions..." - # Copy the upgraded Cargo.toml back to template - cp ../dep-check-test/Cargo.toml Cargo.toml.liquid + # Run the merge script from .ci directory + python3 .ci/merge_versions.py dep-check-test/Cargo.toml Cargo.toml.liquid # Show what changed + echo "" echo "Changes to template:" git diff Cargo.toml.liquid working-directory: ${{ github.workspace }}/axum-template @@ -161,7 +162,7 @@ jobs: UPGRADE_SUMMARY=$(cat upgrade-output.txt | grep -A 100 "name.*old req.*compatible.*latest.*new req" | head -n 20) cat > pr-body.txt << 'EOF' - This PR contains automated dependency upgrades that have been tested and verified. + This PR contains automated dependency upgrades that have been tested with `cargo check` and `cargo build` ## Changes diff --git a/.gitignore b/.gitignore index 57d8fbc..02ad72c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target .env* !.env.example +!.env.liquid diff --git a/README.md b/README.md index b87d5d9..672d9f9 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ APP_PORT=8080 APP_LOG_LEVEL=info ``` -In development, you can use a `.env` file (copy from `.env.example`). +In development, you can use the `.env` file. ## Project Structure