ci: add automated PR for dep upgrades

This commit is contained in:
fa-sharp
2026-02-20 00:10:02 -05:00
parent 4159d0d7ff
commit c0828867bd
6 changed files with 99 additions and 4 deletions

82
.ci/merge_versions.py Normal file
View File

@@ -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!")

9
.env.liquid Normal file
View File

@@ -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}}

View File

@@ -1,3 +1,5 @@
.ci/
.github/
target/
Cargo.lock
.env

View File

@@ -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

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
/target
.env*
!.env.example
!.env.liquid

View File

@@ -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