Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
pipeline:
name: android-client-diffuse
identifier: androidclientdiffuse
projectIdentifier: Harness_Split
orgIdentifier: PROD
tags: {}
stages:
- stage:
name: Build and Analyze
identifier: build_and_analyze
description: Clone repo, run diffuse script with PR branch parameters, and comment on PR
type: CI
spec:
cloneCodebase: true
caching:
enabled: true
override: true
platform:
os: Linux
arch: Amd64
runtime:
type: Cloud
spec: {}
variables:
- name: ANDROID_HOME
type: String
value: /opt/android-sdk
execution:
steps:
- step:
type: Run
name: Setup Environment and Extract PR Info
identifier: setup_environment
spec:
shell: Sh
envVariables:
GH_TOKEN: <+secrets.getValue("github-devops-token")>
command: |
# Install required tools
apt-get update
apt-get install -y curl jq git

# Extract PR information from trigger payload
PR_NUMBER="<+trigger.payload.pull_request.number>"
PR_TITLE="<+trigger.payload.pull_request.title>"
PR_AUTHOR="<+trigger.payload.pull_request.user.login>"
PR_HEAD_REF="<+trigger.payload.pull_request.head.ref>"
PR_BASE_REF="<+trigger.payload.pull_request.base.ref>"
PR_HEAD_SHA="<+trigger.payload.pull_request.head.sha>"
REPO_FULL_NAME="<+trigger.payload.repository.full_name>"

echo "=== PR Information ==="
echo "PR Number: $PR_NUMBER"
echo "PR Title: $PR_TITLE"
echo "PR Author: $PR_AUTHOR"
echo "Source Branch (HEAD): $PR_HEAD_REF"
echo "Target Branch (BASE): $PR_BASE_REF"
echo "Head SHA: $PR_HEAD_SHA"
echo "Repository: $REPO_FULL_NAME"
echo "=== End PR Info ==="

# Check if this is a PR build
if [ -n "$PR_NUMBER" ] && [ "$PR_NUMBER" != "null" ] && [ "$PR_NUMBER" != "" ]; then
echo "✅ Detected PR build"
SOURCE_BRANCH="$PR_HEAD_REF"
TARGET_BRANCH="$PR_BASE_REF"
IS_PR_BUILD="true"
else
echo "ℹ️ Not a PR build - using fallback values"
SOURCE_BRANCH="<+codebase.branch>"
TARGET_BRANCH="main"
IS_PR_BUILD="false"
PR_NUMBER=""
fi

echo "Final branch configuration:"
echo " Source Branch: $SOURCE_BRANCH"
echo " Target Branch: $TARGET_BRANCH"
echo " Is PR Build: $IS_PR_BUILD"

# Export variables for subsequent steps
cat > /harness/pr_info.sh << EOF
export PR_NUMBER="$PR_NUMBER"
export PR_TITLE="$PR_TITLE"
export PR_AUTHOR="$PR_AUTHOR"
export SOURCE_BRANCH="$SOURCE_BRANCH"
export TARGET_BRANCH="$TARGET_BRANCH"
export PR_HEAD_SHA="$PR_HEAD_SHA"
export REPO_FULL_NAME="$REPO_FULL_NAME"
export IS_PR_BUILD="$IS_PR_BUILD"
EOF

chmod +x /harness/pr_info.sh
echo "=== Exported Variables ==="
cat /harness/pr_info.sh
- step:
type: Run
name: Install Dependencies
identifier: install_dependencies
spec:
shell: Sh
command: |
# Install basic tools needed by install-deps.sh
apt-get update -qq
apt-get install -y curl unzip

# Use the existing install-deps.sh script for consistent setup
chmod +x .harness/scripts/install-deps.sh
.harness/scripts/install-deps.sh
- step:
type: Run
name: Run Diffuse Script with Branch Parameters
identifier: run_diffuse
spec:
shell: Sh
envVariables:
GH_TOKEN: <+secrets.getValue("github-devops-token")>
command: |
set -e

# Set Android SDK environment variables (matching instrumented pipeline)
export ANDROID_SDK_ROOT=$ANDROID_HOME
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
export PATH="$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/cmdline-tools/latest/bin"

# Verify environment
echo "=== Environment Verification ==="
echo "JAVA_HOME: $JAVA_HOME"
echo "ANDROID_HOME: $ANDROID_HOME"
java -version

# Source the PR information (use . for sh compatibility)
. /harness/pr_info.sh

echo "=== Running Diffuse Analysis ==="
echo "Source Branch: $SOURCE_BRANCH"
echo "Target Branch: $TARGET_BRANCH"

# Fetch all branches from remote so diffuse.sh can access them
echo "Fetching branches from remote..."
git fetch origin --prune > /dev/null 2>&1
git fetch origin "$SOURCE_BRANCH:$SOURCE_BRANCH" > /dev/null 2>&1 || true
git fetch origin "$TARGET_BRANCH:$TARGET_BRANCH" > /dev/null 2>&1 || true
echo "✓ Branches fetched"

# Verify the script exists
if [ ! -f "scripts/diffuse.sh" ]; then
echo "❌ Error: scripts/diffuse.sh not found"
echo "Available files in scripts/:"
ls -la scripts/ || echo "scripts/ directory not found"
exit 1
fi

# Make the script executable
chmod +x scripts/diffuse.sh

# Run the diffuse script with branch parameters
echo "Executing: ./scripts/diffuse.sh --source '$SOURCE_BRANCH' --target '$TARGET_BRANCH'"

# Run and capture output
set +e # Don't exit on error
./scripts/diffuse.sh --source "$SOURCE_BRANCH" --target "$TARGET_BRANCH" > diffuse_output_full.txt 2>&1
DIFFUSE_EXIT_CODE=$?
set -e

echo ""
echo "=== Diffuse Script Exit Code: $DIFFUSE_EXIT_CODE ==="

# Extract only the comparison tables from the output
sed 's/\x1b\[[0-9;]*m//g' diffuse_output_full.txt | \
awk '/^ (AAR|JAR).*old.*new.*diff/,/^$/ {
if (/^ (AAR|JAR)/ || /─/ || /┼/ || /│/ || /^ *total/ || /^ *(jar|manifest|other|classes|methods|fields)/) {
print
}
}' > /harness/diffuse_output.txt

# Display the filtered output
echo "=== Diffuse Analysis Results ==="
cat /harness/diffuse_output.txt
echo ""

# Save exit code for the comment step
echo "$DIFFUSE_EXIT_CODE" > /harness/diffuse_exit_code.txt

# Fail the step if diffuse failed
if [ "$DIFFUSE_EXIT_CODE" != "0" ]; then
echo "❌ Diffuse script failed with exit code: $DIFFUSE_EXIT_CODE"
exit "$DIFFUSE_EXIT_CODE"
fi
- step:
type: Run
name: Comment on PR
identifier: comment_on_pr
spec:
shell: Sh
envVariables:
GH_TOKEN: <+secrets.getValue("github-devops-token")>
command: |
# Source PR information (use . for sh compatibility)
. /harness/pr_info.sh

# Check if this is a PR build
if [ "$IS_PR_BUILD" != "true" ] || [ -z "$PR_NUMBER" ]; then
echo "ℹ️ Not a PR build, skipping comment"
exit 0
fi

# Get the diffuse script exit code
DIFFUSE_EXIT_CODE=$(cat /harness/diffuse_exit_code.txt 2>/dev/null || echo "unknown")

# Only post comment if analysis was successful
if [ "$DIFFUSE_EXIT_CODE" != "0" ]; then
echo "⚠️ Diffuse analysis failed (exit code: $DIFFUSE_EXIT_CODE), skipping PR comment"
exit 1
fi

# Read the diffuse output
if [ -f /harness/diffuse_output.txt ]; then
DIFFUSE_OUTPUT=$(cat /harness/diffuse_output.txt)
else
DIFFUSE_OUTPUT="Diffuse script output not found"
fi

# Create the comment body
COMMENT_BODY="## 📱 Android Diffuse Analysis Results ✅

**Source Branch:** \`$SOURCE_BRANCH\`
**Target Branch:** \`$TARGET_BRANCH\`
**Commit:** \`$PR_HEAD_SHA\`

### Script Output:
\`\`\`
$DIFFUSE_OUTPUT
\`\`\`"

# Escape the comment body for JSON
ESCAPED_COMMENT=$(echo "$COMMENT_BODY" | jq -Rs .)

# Post comment to GitHub
echo "Posting comment to PR #$PR_NUMBER in $REPO_FULL_NAME..."

RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
-H "Authorization: token $GH_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.github.v3+json" \
-d "{\"body\": $ESCAPED_COMMENT}" \
"https://api.github.com/repos/$REPO_FULL_NAME/issues/$PR_NUMBER/comments")

# Extract HTTP code from response
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
RESPONSE_BODY=$(echo "$RESPONSE" | head -n -1)

if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then
echo "✅ Comment posted successfully to PR #$PR_NUMBER"
echo "Comment URL: $(echo "$RESPONSE_BODY" | jq -r '.html_url // "N/A"')"
else
echo "❌ Failed to post comment. HTTP code: $HTTP_CODE"
echo "Response: $RESPONSE_BODY"
exit 1
fi

echo "✅ Comment posted successfully and pipeline completed"
when:
stageStatus: All
properties:
ci:
codebase:
connectorRef: <+input>
repoName: <+input>
build: <+input>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
inputSet:
name: androidclient_PR
identifier: androidclient_PR
orgIdentifier: PROD
projectIdentifier: Harness_Split
pipeline:
identifier: androidclientdiffuse
stages:
- stage:
identifier: build_and_analyze
type: CI
spec:
infrastructure:
type: KubernetesDirect
spec:
connectorRef: ""
namespace: ""
execution:
steps:
- step:
identifier: setup_environment
type: Run
spec:
connectorRef: ""
- step:
identifier: run_diffuse
type: Run
spec:
connectorRef: ""
- step:
identifier: comment_on_pr
type: Run
spec:
connectorRef: ""
properties:
ci:
codebase:
connectorRef: fmegithubrunnersci
repoName: android-client
build:
type: PR
spec:
number: <+trigger.prNumber>
15 changes: 11 additions & 4 deletions .harness/scripts/install-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@ echo ""
# ============================================
echo "=== Installing Java 17 ==="

# Detect if we need sudo (not running as root)
if [ "$EUID" -eq 0 ] || [ "$(id -u)" -eq 0 ]; then
SUDO=""
else
SUDO="sudo"
fi

# Install Java 17
echo "Installing OpenJDK 17..."
sudo apt-get update -qq
sudo apt-get install -y openjdk-17-jdk
$SUDO apt-get update -qq
$SUDO apt-get install -y openjdk-17-jdk

# Set JAVA_HOME to Java 17 explicitly
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64

# Update alternatives to use Java 17 as default
sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/java-17-openjdk-amd64/bin/javac
$SUDO update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java
$SUDO update-alternatives --set javac /usr/lib/jvm/java-17-openjdk-amd64/bin/javac

echo ""
echo "Java 17 installation complete:"
Expand Down
Loading
Loading