-
Notifications
You must be signed in to change notification settings - Fork 183
chore: add shared renovate config with version bumping #531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
lawrence-u10d
wants to merge
9
commits into
main
Choose a base branch
from
chore/add-renovate-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e670963
chore: add shared renovate config with version bumping
lawrence-u10d 84d7602
chore: update renovate-security-bump.sh with shfmt formatting
lawrence-u10d 135e787
chore: update script with improved pip-compile requirements detection
lawrence-u10d e4167bf
fix: handle extras in .in files and ~= in pyproject.toml
lawrence-u10d 10587be
fix: strip inline comments and exclude URL deps in .in files
lawrence-u10d 4ef5627
fix: address cursor bot review comments on bump script
lawrence-u10d 07e12cc
fix: portable sed, trailing content, package detection, exact match
lawrence-u10d 38c50a2
feat: auto-detect and adapt to CHANGELOG format
lawrence-u10d 64ce590
fix: shellcheck SC2016 - pass PACKAGE_COUNT as awk variable
lawrence-u10d File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,22 @@ | ||
| { | ||
| "$schema": "https://docs.renovatebot.com/renovate-schema.json", | ||
| "extends": [ | ||
| "github>unstructured-io/renovate-config" | ||
| ], | ||
| "packageRules": [ | ||
| { | ||
| "matchDatasources": ["pypi"], | ||
| "matchIsVulnerabilityAlert": true, | ||
| "postUpgradeTasks": { | ||
| "commands": [ | ||
| "VERSION_FILE=prepline_general/api/__version__.py bash scripts/renovate-security-bump.sh" | ||
| ], | ||
| "fileFilters": [ | ||
| "prepline_general/api/__version__.py", | ||
| "CHANGELOG.md" | ||
| ], | ||
| "executionMode": "branch" | ||
| } | ||
| } | ||
| ] | ||
| } |
This file contains hidden or 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,309 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| # Shared script for Renovate to bump version and update CHANGELOG | ||
| # Supports both __version__.py and pyproject.toml versioning styles | ||
| # Auto-detects changed dependencies from git diff | ||
|
|
||
| # Use current working directory as repo root (where Renovate executes the script) | ||
| REPO_ROOT="${REPO_ROOT:-$(pwd)}" | ||
| CHANGELOG_FILE="${CHANGELOG_FILE:-$REPO_ROOT/CHANGELOG.md}" | ||
|
|
||
| # VERSION_FILE can be: | ||
| # - Path to __version__.py (traditional Python) | ||
| # - Path to pyproject.toml (modern Python with uv/poetry) | ||
| # - "auto" or unset to auto-detect | ||
| VERSION_FILE="${VERSION_FILE:-auto}" | ||
|
|
||
| echo "=== Renovate Security Version Bump ===" | ||
|
|
||
| # Auto-detect versioning style | ||
| detect_version_style() { | ||
| if [[ "$VERSION_FILE" == "auto" ]]; then | ||
| # Check for pyproject.toml with version field first (modern style) | ||
| if [[ -f "$REPO_ROOT/pyproject.toml" ]] && grep -q "^version\s*=" "$REPO_ROOT/pyproject.toml"; then | ||
| VERSION_FILE="$REPO_ROOT/pyproject.toml" | ||
| VERSION_STYLE="pyproject" | ||
| echo "Auto-detected: pyproject.toml versioning" | ||
| # Check for common __version__.py locations | ||
| elif [[ -f "$REPO_ROOT/unstructured/__version__.py" ]]; then | ||
| VERSION_FILE="$REPO_ROOT/unstructured/__version__.py" | ||
| VERSION_STYLE="python" | ||
| echo "Auto-detected: __version__.py versioning" | ||
| else | ||
| echo "Error: Could not auto-detect version file. Set VERSION_FILE explicitly." | ||
| exit 1 | ||
| fi | ||
| elif [[ "$VERSION_FILE" == *.py ]]; then | ||
| VERSION_STYLE="python" | ||
| echo "Using Python __version__.py style: $VERSION_FILE" | ||
| elif [[ "$VERSION_FILE" == *pyproject.toml ]]; then | ||
| VERSION_STYLE="pyproject" | ||
| echo "Using pyproject.toml style: $VERSION_FILE" | ||
| else | ||
| echo "Error: Unknown version file type: $VERSION_FILE" | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| # Read current version based on style | ||
| read_current_version() { | ||
| if [[ "$VERSION_STYLE" == "python" ]]; then | ||
| CURRENT_VERSION=$(grep -o -E "(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-dev[0-9]+)?" "$VERSION_FILE") | ||
cursor[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
cursor[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| elif [[ "$VERSION_STYLE" == "pyproject" ]]; then | ||
| # Extract version from pyproject.toml (handles both quoted styles) | ||
| CURRENT_VERSION=$(grep -E "^version\s*=" "$VERSION_FILE" | head -1 | sed -E 's/version\s*=\s*["\x27]?([^"\x27]+)["\x27]?/\1/' | tr -d ' ') | ||
cursor[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fi | ||
| echo "Current version: $CURRENT_VERSION" | ||
| } | ||
|
|
||
| # Calculate new release version | ||
| calculate_release_version() { | ||
| if [[ "$CURRENT_VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(-dev.*)?$ ]]; then | ||
| MAJOR="${BASH_REMATCH[1]}" | ||
| MINOR="${BASH_REMATCH[2]}" | ||
| PATCH="${BASH_REMATCH[3]}" | ||
| DEV_SUFFIX="${BASH_REMATCH[4]}" | ||
|
|
||
| if [[ -n "$DEV_SUFFIX" ]]; then | ||
| # Strip -dev suffix to release current version | ||
| RELEASE_VERSION="$MAJOR.$MINOR.$PATCH" | ||
| echo "Stripping dev suffix: $CURRENT_VERSION → $RELEASE_VERSION" | ||
| else | ||
| # Already a release version, bump to next patch | ||
| NEW_PATCH=$((PATCH + 1)) | ||
| RELEASE_VERSION="$MAJOR.$MINOR.$NEW_PATCH" | ||
| echo "Bumping patch version: $CURRENT_VERSION → $RELEASE_VERSION" | ||
| fi | ||
| else | ||
| echo "Error: Could not parse version: $CURRENT_VERSION" | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| # Update version in __version__.py | ||
| update_python_version() { | ||
| echo "Updating $VERSION_FILE to version $RELEASE_VERSION" | ||
|
|
||
| # Detect quote style used in the file | ||
| if grep -q "__version__ = ['\"]" "$VERSION_FILE"; then | ||
| if grep -q "__version__ = \"" "$VERSION_FILE"; then | ||
| # Double quotes | ||
| sed -i.bak -E "s/__version__ = \"[^\"]+\"/__version__ = \"$RELEASE_VERSION\"/" "$VERSION_FILE" | ||
| else | ||
| # Single quotes | ||
| sed -i.bak -E "s/__version__ = '[^']+'/__version__ = '$RELEASE_VERSION'/" "$VERSION_FILE" | ||
| fi | ||
| else | ||
| echo "Error: Could not detect quote style in $VERSION_FILE" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Verify the update succeeded | ||
| if ! grep -q "__version__ = ['\"]${RELEASE_VERSION}['\"]" "$VERSION_FILE"; then | ||
| echo "Error: Failed to update version in $VERSION_FILE" | ||
| exit 1 | ||
| fi | ||
|
|
||
| rm -f "$VERSION_FILE.bak" | ||
| } | ||
|
|
||
| # Update version in pyproject.toml | ||
| update_pyproject_version() { | ||
| echo "Updating $VERSION_FILE to version $RELEASE_VERSION" | ||
|
|
||
| # Detect quote style (single or double quotes) | ||
| if grep -qE "^version\s*=\s*\"" "$VERSION_FILE"; then | ||
| # Double quotes | ||
| sed -i.bak -E "s/^(version\s*=\s*)\"[^\"]+\"/\1\"$RELEASE_VERSION\"/" "$VERSION_FILE" | ||
| else | ||
| # Single quotes | ||
| sed -i.bak -E "s/^(version\s*=\s*)'[^']+'$/\1'$RELEASE_VERSION'/" "$VERSION_FILE" | ||
cursor[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fi | ||
|
|
||
| # Verify the update succeeded | ||
| if ! grep -qE "^version\s*=\s*['\"]${RELEASE_VERSION}['\"]" "$VERSION_FILE"; then | ||
| echo "Error: Failed to update version in $VERSION_FILE" | ||
| exit 1 | ||
| fi | ||
|
|
||
| rm -f "$VERSION_FILE.bak" | ||
| } | ||
|
|
||
| # Detect changed packages from git diff | ||
| detect_changed_packages() { | ||
| echo "Detecting changed dependencies..." | ||
|
|
||
| # Package name regex per PEP 508: starts with letter/digit, can contain letters, digits, dots, underscores, hyphens | ||
| local pkg_pattern='^[-+][a-zA-Z0-9][a-zA-Z0-9._-]*==' | ||
|
|
||
| # Try requirements/*.txt files first (pip-compile output format) | ||
| CHANGED_PACKAGES=$(git diff --cached requirements/*.txt 2>/dev/null | grep -E "$pkg_pattern" | sed 's/^[+-]//' | sort -u | head -20 || true) | ||
|
|
||
| if [ -z "$CHANGED_PACKAGES" ]; then | ||
| CHANGED_PACKAGES=$(git diff requirements/*.txt 2>/dev/null | grep -E "$pkg_pattern" | sed 's/^[+-]//' | sort -u | head -20 || true) | ||
| fi | ||
|
|
||
| # Try requirements/*.in files (unpinned requirements) | ||
| if [ -z "$CHANGED_PACKAGES" ]; then | ||
| CHANGED_PACKAGES=$(git diff --cached requirements/*.in 2>/dev/null | grep -E '^[-+][a-zA-Z0-9][a-zA-Z0-9._-]*' | grep -v '^[-+]#' | grep -v '^[-+]-' | sed 's/^[+-]//' | sed 's/[<>=].*//' | sort -u | head -20 || true) | ||
| fi | ||
|
|
||
| if [ -z "$CHANGED_PACKAGES" ]; then | ||
| CHANGED_PACKAGES=$(git diff requirements/*.in 2>/dev/null | grep -E '^[-+][a-zA-Z0-9][a-zA-Z0-9._-]*' | grep -v '^[-+]#' | grep -v '^[-+]-' | sed 's/^[+-]//' | sed 's/[<>=].*//' | sort -u | head -20 || true) | ||
| fi | ||
|
|
||
| # Try uv.lock if no requirements changes found | ||
| if [ -z "$CHANGED_PACKAGES" ]; then | ||
| CHANGED_PACKAGES=$(git diff --cached uv.lock 2>/dev/null | grep -E '^[-+]name\s*=' | sed -E 's/^[-+]name\s*=\s*"([^"]+)"/\1/' | sort -u | head -20 || true) | ||
| fi | ||
|
|
||
| if [ -z "$CHANGED_PACKAGES" ]; then | ||
| CHANGED_PACKAGES=$(git diff uv.lock 2>/dev/null | grep -E '^[-+]name\s*=' | sed -E 's/^[-+]name\s*=\s*"([^"]+)"/\1/' | sort -u | head -20 || true) | ||
| fi | ||
|
|
||
| # Try pyproject.toml dependencies section | ||
| if [ -z "$CHANGED_PACKAGES" ]; then | ||
| CHANGED_PACKAGES=$(git diff --cached pyproject.toml 2>/dev/null | grep -E '^[-+]\s*"?[a-zA-Z0-9][a-zA-Z0-9._-]*[<>=]' | sed -E 's/^[-+]\s*"?([a-zA-Z0-9][a-zA-Z0-9._-]*).*/\1/' | sort -u | head -20 || true) | ||
| fi | ||
|
|
||
| if [ -z "$CHANGED_PACKAGES" ]; then | ||
| CHANGED_PACKAGES=$(git diff pyproject.toml 2>/dev/null | grep -E '^[-+]\s*"?[a-zA-Z0-9][a-zA-Z0-9._-]*[<>=]' | sed -E 's/^[-+]\s*"?([a-zA-Z0-9][a-zA-Z0-9._-]*).*/\1/' | sort -u | head -20 || true) | ||
| fi | ||
|
|
||
| # Build changelog entry | ||
| if [ -n "$CHANGED_PACKAGES" ]; then | ||
| PACKAGE_COUNT=$(echo "$CHANGED_PACKAGES" | wc -l | tr -d ' ') | ||
| echo "Found $PACKAGE_COUNT changed package(s):" | ||
| echo "$CHANGED_PACKAGES" | head -5 | sed 's/^/ - /' | ||
| if [ "$PACKAGE_COUNT" -gt 5 ]; then | ||
| echo " ... and $((PACKAGE_COUNT - 5)) more" | ||
| fi | ||
| else | ||
| echo "Could not auto-detect packages, using generic entry" | ||
| fi | ||
|
|
||
| CHANGELOG_ENTRY="- **Security update**: Bumped dependencies to address security vulnerabilities" | ||
| echo "Changelog entry: $CHANGELOG_ENTRY" | ||
| } | ||
|
|
||
| # Update CHANGELOG.md | ||
| update_changelog() { | ||
| echo "Updating CHANGELOG..." | ||
|
|
||
| # Check if CHANGELOG exists | ||
| if [[ ! -f "$CHANGELOG_FILE" ]]; then | ||
| echo "Warning: CHANGELOG.md not found at $CHANGELOG_FILE, skipping changelog update" | ||
| return 0 | ||
| fi | ||
|
|
||
| # Only look for -dev version to rename if CURRENT_VERSION had -dev suffix | ||
| if [[ -n "${DEV_SUFFIX:-}" ]]; then | ||
| # Look for -dev version header in CHANGELOG that matches our version | ||
| DEV_VERSION_HEADER=$(grep -m 1 -F "## $CURRENT_VERSION" "$CHANGELOG_FILE" || true) | ||
|
|
||
| if [[ -n "$DEV_VERSION_HEADER" ]]; then | ||
| echo "Found dev version in CHANGELOG: $DEV_VERSION_HEADER" | ||
|
|
||
| # Extract the -dev version number from header | ||
| DEV_VERSION=$(echo "$DEV_VERSION_HEADER" | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+-dev[0-9]*") | ||
|
|
||
| echo "Renaming CHANGELOG header: $DEV_VERSION → $RELEASE_VERSION" | ||
|
|
||
| awk -v dev_version="$DEV_VERSION" \ | ||
| -v release_version="$RELEASE_VERSION" \ | ||
| -v security_entry="$CHANGELOG_ENTRY" ' | ||
| BEGIN { | ||
| in_target_version = 0 | ||
| found_fixes = 0 | ||
| added_entry = 0 | ||
| } | ||
|
|
||
| /^## / { | ||
| if ($0 ~ "^## " dev_version) { | ||
cursor[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| print "## " release_version | ||
| in_target_version = 1 | ||
| next | ||
| } else { | ||
| if (in_target_version && !found_fixes && !added_entry) { | ||
| print "" | ||
| print "### Fixes" | ||
| print security_entry | ||
| print "" | ||
| added_entry = 1 | ||
| } | ||
| in_target_version = 0 | ||
| found_fixes = 0 | ||
| } | ||
| } | ||
|
|
||
| /^### Fixes/ && in_target_version { | ||
| print security_entry | ||
| found_fixes = 1 | ||
| added_entry = 1 | ||
| next | ||
| } | ||
|
|
||
| { print } | ||
|
|
||
| END { | ||
| if (in_target_version && !found_fixes && !added_entry) { | ||
| print "" | ||
| print "### Fixes" | ||
| print security_entry | ||
| } | ||
| } | ||
| ' "$CHANGELOG_FILE" >"$CHANGELOG_FILE.tmp" | ||
|
|
||
| mv "$CHANGELOG_FILE.tmp" "$CHANGELOG_FILE" | ||
| else | ||
| echo "Warning: Current version has -dev suffix but no matching dev header in CHANGELOG" | ||
| create_new_changelog_entry | ||
| fi | ||
| else | ||
| # Current version was already a release, so we bumped to next patch | ||
| create_new_changelog_entry | ||
| fi | ||
| } | ||
|
|
||
| create_new_changelog_entry() { | ||
| echo "Creating new CHANGELOG entry for $RELEASE_VERSION" | ||
|
|
||
| cat >/tmp/new_changelog_section.tmp <<EOF | ||
| ## $RELEASE_VERSION | ||
|
|
||
| ### Fixes | ||
| $CHANGELOG_ENTRY | ||
|
|
||
| EOF | ||
|
|
||
| cat /tmp/new_changelog_section.tmp "$CHANGELOG_FILE" >"$CHANGELOG_FILE.tmp" | ||
| mv "$CHANGELOG_FILE.tmp" "$CHANGELOG_FILE" | ||
| rm -f /tmp/new_changelog_section.tmp | ||
| } | ||
|
|
||
| # Main execution | ||
| detect_version_style | ||
| read_current_version | ||
| calculate_release_version | ||
|
|
||
| if [[ "$VERSION_STYLE" == "python" ]]; then | ||
| update_python_version | ||
| elif [[ "$VERSION_STYLE" == "pyproject" ]]; then | ||
| update_pyproject_version | ||
| fi | ||
|
|
||
| detect_changed_packages | ||
| update_changelog | ||
|
|
||
| echo "" | ||
| echo "✓ Successfully updated version to $RELEASE_VERSION" | ||
| echo "✓ Updated CHANGELOG with security fix entry" | ||
| echo "" | ||
| echo "Modified files:" | ||
| echo " - $VERSION_FILE" | ||
| if [[ -f "$CHANGELOG_FILE" ]]; then | ||
| echo " - $CHANGELOG_FILE" | ||
| fi | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.