Skip to content
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

Automation Script: find_moved_or_renamed_commit #1559

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions auto-find-moved-or-renamed/find_moved_or_renamed_commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# This script identifies the commit where a specified function was modified,
# starting from a given commit, and handles cases where the function or file
# might have been renamed or moved.

# Usage:
# ./find_moved_or_renamed_commit.sh <FUNCTION_NAME> <FILENAME> <START_COMMIT>

# Parameters:
FUNCTION_NAME="$1"
FILENAME="$2" # Relative Path
START_COMMIT="$3"

if [ -z "$FUNCTION_NAME" ] || [ -z "$FILENAME" ] || [ -z "$START_COMMIT" ]; then
echo "Usage: $0 <FUNCTION_NAME> <FILENAME> <START_COMMIT>"
exit 1
fi

# Ensure we're in the root directory of the repository
cd "$(git rev-parse --show-toplevel)"

METHOD_REGEX="(public|protected|private|static|\s)+\s+.*\s+$FUNCTION_NAME\s*\(.*\)"

echo "Checking for function renames or file renames/moves..."

# Track file renames: See commits where the file was renamed.
# Track function changes: See commits where the function was modified, or removed.
git log "$START_COMMIT"..HEAD \
--follow \
--find-renames \
-G"$METHOD_REGEX" \
-p \
--name-status \
--reverse \
--color \
--decorate \
-- "$FILENAME" > outputfile.log
72 changes: 72 additions & 0 deletions auto-find-moved-or-renamed/find_moved_or_renamed_commit_batch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash

# This script takes a batch of (FUNCTION_NAME, FILENAME, START_COMMIT) sets from a file
# and identifies the commit where each function was modified.

# Usage:
# ./find_moved_or_renamed_commit_batch.sh <BATCH_FILE>
#
# The batch file should have one set of parameters per line, in the following format:
# FUNCTION_NAME FILENAME START_COMMIT

BATCH_FILE="$1"

if [ -z "$BATCH_FILE" ]; then
echo "Usage: $0 <BATCH_FILE>"
exit 1
fi

if [ ! -f "$BATCH_FILE" ]; then
echo "Error: File '$BATCH_FILE' not found!"
exit 1
fi

# Ensure we're in the root directory of the repository
cd "$(git rev-parse --show-toplevel)" || exit 1

OUTPUT_FILE="batch_output.log"
> "$OUTPUT_FILE" # Clear the file at the start of each run

echo "Processing batch input from $BATCH_FILE ..." | tee -a "$OUTPUT_FILE"
echo | tee -a "$OUTPUT_FILE"

while IFS= read -r line; do
# Skip empty lines or lines starting with '#'
if [[ -z "$line" || "$line" =~ ^# ]]; then
continue
fi

# Extract parameters from the line
FUNCTION_NAME=$(echo "$line" | awk '{print $1}')
FILENAME=$(echo "$line" | awk '{print $2}')
START_COMMIT=$(echo "$line" | awk '{print $3}')

if [ -z "$FUNCTION_NAME" ] || [ -z "$FILENAME" ] || [ -z "$START_COMMIT" ]; then
echo "Skipping malformed line: $line" | tee -a "$OUTPUT_FILE"
continue
fi

echo "----------------------------------------" | tee -a "$OUTPUT_FILE"
echo "Checking for function renames or file renames/moves for:" | tee -a "$OUTPUT_FILE"
echo "FUNCTION_NAME: $FUNCTION_NAME" | tee -a "$OUTPUT_FILE"
echo "FILENAME: $FILENAME" | tee -a "$OUTPUT_FILE"
echo "START_COMMIT: $START_COMMIT" | tee -a "$OUTPUT_FILE"
echo "----------------------------------------" | tee -a "$OUTPUT_FILE"

METHOD_REGEX="(public|protected|private|static|\\s)+\\s+.*\\s+$FUNCTION_NAME\\s*\\(.*\\)"

git log "$START_COMMIT"..HEAD \
--follow \
--find-renames \
-G"$METHOD_REGEX" \
-p \
--name-status \
--reverse \
--color \
--decorate \
-- "$FILENAME" >> "$OUTPUT_FILE"

echo | tee -a "$OUTPUT_FILE"
done < "$BATCH_FILE"

echo "All results have been logged to $OUTPUT_FILE."
41 changes: 41 additions & 0 deletions auto-find-moved-or-renamed/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Overview
This automation script is designed to identify the specific commit that moved or renamed a test function or test file from the ones recorded in the IDOFT repository.

# Instructions
1. Copy and paste `find_moved_or_renamed_commit.sh` to the Repo you are working on.
2. `git checkout xxx` (replace xxx with the commit hash that the flake test was detected in IDOFT)
3. Find and copy the **Relative Path** of the given testing file, it should contain the given FUNCTION_NAME. (Paste it somewhere, this is the FILENAME that will be used later)
4. `git checkout master` (or whichever branch you want that has the latest commit)
5. Execute the script by running:

``` bash
chmod +x find_moved_or_renamed_commit.sh`
./find_moved_or_renamed_commit.sh <FUNCTION_NAME> <FILENAME> <START_COMMIT>
```

## Examples

### A Row in IDOFT
```
https://github.com/apache/ignite-3,a1aa7fd4e2398c72827777ec5417d67915ff4da3,modules/configuration,org.apache.ignite.internal.configuration.asm.ConfigurationAsmGeneratorTest.testConstructInternalConfig,ID,MovedOrRenamed,,https://github.com/apache/ignite-3/commit/b48ddcba7cd2bd3b9a053ae131c25b44a0400e27
```

### Execute
```
./find_moved_or_renamed_commit.sh testConstructInternalConfig modules/configuration/src/test/java/org/apache/ignite/internal/configuration/asm/ConfigurationAsmGeneratorTest.java a1aa7fd4e2398c72827777ec5417d67915ff4da3
```

### Output
```
commit b48ddcba7cd2bd3b9a053ae131c25b44a0400e27
Author: Aleksandr Pakhomov <[email protected]>
Date: Wed Apr 26 20:02:34 2023 +0400

IGNITE-19152 Use schema information in LocalFileConfigurationStorage (#1988)

---------

Co-authored-by: Ivan Bessonov <[email protected]>

D modules/configuration/src/test/java/org/apache/ignite/internal/configuration/asm/ConfigurationAsmGeneratorTest.java
```
Loading