mirror of
https://github.com/rangermix/TwitchDropsMiner.git
synced 2026-05-26 15:13:32 +00:00
extracted the previous version extraction logic
This commit is contained in:
9
.github/scripts/generate_release_notes.sh
vendored
9
.github/scripts/generate_release_notes.sh
vendored
@@ -77,12 +77,13 @@ fi
|
||||
echo "🤖 Generating release notes using Gemini AI..."
|
||||
|
||||
# Get previous version from history of src/version.py
|
||||
LAST_VERSION=$(git show HEAD^:src/version.py | sed -n 's/^__version__ = "\([^"]*\)"/\1/p')
|
||||
echo "Last version from git history of src/version.py: $LAST_VERSION"
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PREV_VERSION=$("$SCRIPT_DIR/get_previous_version.sh" "$VERSION" 2>&1)
|
||||
echo "Previous version from git history of src/version.py: $PREV_VERSION"
|
||||
|
||||
# Get commit history since last version tag
|
||||
echo "Looking for last version tag: v$LAST_VERSION"
|
||||
PREV_TAG="v$LAST_VERSION"
|
||||
echo "Looking for previous version tag: v$PREV_VERSION"
|
||||
PREV_TAG="v$PREV_VERSION"
|
||||
|
||||
if ! git rev-parse "$PREV_TAG" >/dev/null 2>&1; then
|
||||
echo "❌ Error: Could not find previous tag for $PREV_TAG"
|
||||
|
||||
74
.github/scripts/get_previous_version.sh
vendored
Executable file
74
.github/scripts/get_previous_version.sh
vendored
Executable file
@@ -0,0 +1,74 @@
|
||||
#!/bin/bash
|
||||
|
||||
# get_previous_version.sh - Extract the previous version from git history
|
||||
# Usage: get_previous_version.sh <version>
|
||||
#
|
||||
# Arguments:
|
||||
# version: The current semver version (e.g., 1.2.3 or 2.0.0-rc.1)
|
||||
#
|
||||
# Output:
|
||||
# Prints the previous version to stdout
|
||||
# Returns exit code 0 on success, non-zero on failure
|
||||
#
|
||||
# This script:
|
||||
# 1. Finds the commit that introduced the specified version
|
||||
# 2. Gets the parent commit of that version change
|
||||
# 3. Extracts the version from the parent commit
|
||||
# 4. Outputs the previous version
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Display usage information
|
||||
usage() {
|
||||
echo "Usage: $0 <version>" >&2
|
||||
echo "" >&2
|
||||
echo "Extracts the previous version from git history before the specified version." >&2
|
||||
echo "" >&2
|
||||
echo "Arguments:" >&2
|
||||
echo " version: The current semver version (e.g., 1.2.3 or 2.0.0-rc.1)" >&2
|
||||
echo "" >&2
|
||||
echo "Examples:" >&2
|
||||
echo " $0 1.2.3 # Get version before 1.2.3" >&2
|
||||
echo " $0 2.0.0-rc.1 # Get version before 2.0.0-rc.1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check if version argument is provided
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Error: Version argument required" >&2
|
||||
usage
|
||||
fi
|
||||
|
||||
VERSION="$1"
|
||||
|
||||
# Get the git history of version.py, find the commit that introduced $VERSION
|
||||
CURRENT_VERSION_COMMIT=$(git log --all --format="%H" --follow -S "__version__ = \"$VERSION\"" -- src/version.py | head -1)
|
||||
|
||||
if [ -z "$CURRENT_VERSION_COMMIT" ]; then
|
||||
echo "Error: Could not find commit that set version to $VERSION" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the previous commit for version.py
|
||||
PREVIOUS_VERSION_COMMIT=$(git log --all --format="%H" --follow "$CURRENT_VERSION_COMMIT^..HEAD" -- src/version.py | grep -A1 "$CURRENT_VERSION_COMMIT" | tail -1 || true)
|
||||
|
||||
# If we can't find a previous commit in that way, try getting the parent commit and extracting version from there
|
||||
if [ -z "$PREVIOUS_VERSION_COMMIT" ] || [ "$PREVIOUS_VERSION_COMMIT" = "$CURRENT_VERSION_COMMIT" ]; then
|
||||
PREVIOUS_VERSION_COMMIT=$(git rev-parse "$CURRENT_VERSION_COMMIT^" 2>/dev/null || true)
|
||||
fi
|
||||
|
||||
if [ -z "$PREVIOUS_VERSION_COMMIT" ]; then
|
||||
echo "Error: Could not find previous commit for version.py" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract version from that commit
|
||||
PREVIOUS_VERSION=$(git show "$PREVIOUS_VERSION_COMMIT:src/version.py" | grep -oP '__version__ = "\K[^"]+' || true)
|
||||
|
||||
if [ -z "$PREVIOUS_VERSION" ]; then
|
||||
echo "Error: Could not extract previous version from commit ${PREVIOUS_VERSION_COMMIT:0:7}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Output the previous version to stdout
|
||||
echo "$PREVIOUS_VERSION"
|
||||
35
.github/scripts/revert_release.sh
vendored
35
.github/scripts/revert_release.sh
vendored
@@ -155,37 +155,10 @@ fi
|
||||
# Step 4: Extract previous version from git history
|
||||
echo -e "${YELLOW}[4/7] Extracting previous version from git history...${NC}"
|
||||
|
||||
# Get the git history of version.py, find the commit before the version we're reverting
|
||||
# We need to find the commit that changed version to $VERSION, then get the version from the commit before that
|
||||
CURRENT_VERSION_COMMIT=$(git log --all --format="%H" --follow -S "__version__ = \"$VERSION\"" -- src/version.py | head -1)
|
||||
|
||||
if [ -z "$CURRENT_VERSION_COMMIT" ]; then
|
||||
echo -e "${RED}Error: Could not find commit that set version to $VERSION${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo " Found version $VERSION in commit: ${CURRENT_VERSION_COMMIT:0:7}"
|
||||
|
||||
# Get the previous commit for version.py
|
||||
PREVIOUS_VERSION_COMMIT=$(git log --all --format="%H" --follow "$CURRENT_VERSION_COMMIT^..HEAD" -- src/version.py | grep -A1 "$CURRENT_VERSION_COMMIT" | tail -1 || true)
|
||||
|
||||
# If we can't find a previous commit in that way, try getting the parent commit and extracting version from there
|
||||
if [ -z "$PREVIOUS_VERSION_COMMIT" ] || [ "$PREVIOUS_VERSION_COMMIT" = "$CURRENT_VERSION_COMMIT" ]; then
|
||||
PREVIOUS_VERSION_COMMIT=$(git rev-parse "$CURRENT_VERSION_COMMIT^" 2>/dev/null || true)
|
||||
fi
|
||||
|
||||
if [ -z "$PREVIOUS_VERSION_COMMIT" ]; then
|
||||
echo -e "${RED}Error: Could not find previous commit for version.py${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo " Found previous commit: ${PREVIOUS_VERSION_COMMIT:0:7}"
|
||||
|
||||
# Extract version from that commit
|
||||
PREVIOUS_VERSION=$(git show "$PREVIOUS_VERSION_COMMIT:src/version.py" | grep -oP '__version__ = "\K[^"]+' || true)
|
||||
|
||||
if [ -z "$PREVIOUS_VERSION" ]; then
|
||||
echo -e "${RED}Error: Could not extract previous version from commit ${PREVIOUS_VERSION_COMMIT:0:7}${NC}"
|
||||
# Use the get_previous_version.sh script to extract the previous version
|
||||
if ! PREVIOUS_VERSION=$("$SCRIPT_DIR/get_previous_version.sh" "$VERSION" 2>&1); then
|
||||
echo -e "${RED}Error: Failed to extract previous version${NC}"
|
||||
echo -e "${RED}$PREVIOUS_VERSION${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user