Skip to content

Commit 514b79a

Browse files
committed
Add GitCompare workflow and CommitHunter script for build comparison
1 parent aeae2c6 commit 514b79a

File tree

2 files changed

+193
-0
lines changed

2 files changed

+193
-0
lines changed

.github/workflows/gitcompare.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: GitCompare
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
7+
jobs:
8+
parse-comment:
9+
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/gitcompare')
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
issues: write
14+
outputs:
15+
good_build: ${{ steps.parse.outputs.good_build }}
16+
bad_build: ${{ steps.parse.outputs.bad_build }}
17+
steps:
18+
- name: Parse comment
19+
id: parse
20+
env:
21+
COMMENT_BODY: ${{ github.event.comment.body }}
22+
run: |
23+
echo "Comment body: $COMMENT_BODY"
24+
25+
# Remove the /gitcompare command
26+
COMMENT=${COMMENT_BODY#/gitcompare}
27+
28+
# Split into good and bad builds
29+
GOOD_BUILD=$(echo "$COMMENT" | awk '/^---/{exit} {print}')
30+
BAD_BUILD=$(echo "$COMMENT" | awk '/^---/,EOF' | sed '1d')
31+
32+
# Clean up whitespace
33+
GOOD_BUILD=$(echo "$GOOD_BUILD" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
34+
BAD_BUILD=$(echo "$BAD_BUILD" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
35+
36+
# Validate builds
37+
if [ -z "$GOOD_BUILD" ] || [ -z "$BAD_BUILD" ]; then
38+
echo "Error: Invalid format. Please provide both good and bad builds separated by ---"
39+
exit 1
40+
fi
41+
42+
# Set outputs
43+
{
44+
echo "good_build<<EOF"
45+
echo "$GOOD_BUILD"
46+
echo "EOF"
47+
} >> $GITHUB_OUTPUT
48+
49+
{
50+
echo "bad_build<<EOF"
51+
echo "$BAD_BUILD"
52+
echo "EOF"
53+
} >> $GITHUB_OUTPUT
54+
55+
compare:
56+
needs: parse-comment
57+
runs-on: ubuntu-latest
58+
permissions:
59+
contents: read
60+
issues: write
61+
steps:
62+
- name: Checkout repository
63+
uses: actions/checkout@v4
64+
65+
- name: Run CommitHunter
66+
id: run_commit_hunter
67+
env:
68+
GOOD_BUILD: ${{ needs.parse-comment.outputs.good_build }}
69+
BAD_BUILD: ${{ needs.parse-comment.outputs.bad_build }}
70+
run: |
71+
cd CommitHunter
72+
bash commit_hunter.sh "$GOOD_BUILD" "$BAD_BUILD" > output.txt
73+
cat output.txt
74+
75+
- name: Parse URLs from output
76+
id: parse_urls
77+
run: |
78+
url_openj9=$(grep "OpenJ9:" output.txt | awk '{print $2}')
79+
url_omr=$(grep "OMR:" output.txt | awk '{print $2}')
80+
url_jcl=$(grep "JCL:" output.txt | awk '{print $2}')
81+
82+
echo "url_openj9=$url_openj9" >> $GITHUB_OUTPUT
83+
echo "url_omr=$url_omr" >> $GITHUB_OUTPUT
84+
echo "url_jcl=$url_jcl" >> $GITHUB_OUTPUT
85+
86+
- name: Prepare comment
87+
run: |
88+
echo "## 🔍 GitCompare Results" > comment.md
89+
echo "" >> comment.md
90+
echo "### OpenJ9 Changes" >> comment.md
91+
echo "${{ steps.parse_urls.outputs.url_openj9 }}" >> comment.md
92+
echo "" >> comment.md
93+
echo "### OMR Changes" >> comment.md
94+
echo "${{ steps.parse_urls.outputs.url_omr }}" >> comment.md
95+
echo "" >> comment.md
96+
echo "### JCL Changes" >> comment.md
97+
echo "${{ steps.parse_urls.outputs.url_jcl }}" >> comment.md
98+
echo "" >> comment.md
99+
echo "> 💡 **Note:** These links show the differences between the specified builds."
100+
101+
- name: Comment on PR
102+
uses: actions/github-script@v7
103+
with:
104+
script: |
105+
const fs = require('fs');
106+
const comment = fs.readFileSync('comment.md', 'utf8');
107+
108+
github.rest.issues.createComment({
109+
issue_number: context.issue.number,
110+
owner: context.repo.owner,
111+
repo: context.repo.repo,
112+
body: comment
113+
});

CommitHunter/commit_hunter.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
3+
parse_java_version() {
4+
local version_output="$1"
5+
local result=""
6+
7+
# Debug output
8+
echo "Parsing version output: $version_output" >&2
9+
10+
if [[ $version_output =~ openjdk\ version\ \"([0-9]+)\.[0-9]+\.[0-9]+-beta ]]; then
11+
result+="openjdk_version=${BASH_REMATCH[1]}\n"
12+
fi
13+
14+
if [[ $version_output =~ OpenJ9[[:space:]]*-[[:space:]]*([0-9a-f]+) ]]; then
15+
result+="openj9_commit=${BASH_REMATCH[1]}\n"
16+
fi
17+
18+
if [[ $version_output =~ OMR[[:space:]]*-[[:space:]]*([0-9a-f]+) ]]; then
19+
result+="omr_commit=${BASH_REMATCH[1]}\n"
20+
fi
21+
22+
if [[ $version_output =~ JCL[[:space:]]*-[[:space:]]*([0-9a-f]+) ]]; then
23+
result+="jcl_commit=${BASH_REMATCH[1]}\n"
24+
fi
25+
26+
echo -e "$result"
27+
}
28+
29+
generate_compare_urls() {
30+
local good_info="$1"
31+
local bad_info="$2"
32+
33+
declare -A good
34+
declare -A bad
35+
36+
while IFS='=' read -r key value; do
37+
if [[ -n $key ]]; then
38+
good[$key]="$value"
39+
fi
40+
done <<< "$good_info"
41+
42+
while IFS='=' read -r key value; do
43+
if [[ -n $key ]]; then
44+
bad[$key]="$value"
45+
fi
46+
done <<< "$bad_info"
47+
48+
echo "OpenJ9: https://github.com/eclipse-openj9/openj9/compare/${good[openj9_commit]}...${bad[openj9_commit]}"
49+
echo "OMR: https://github.com/eclipse-omr/omr/compare/${good[omr_commit]}...${bad[omr_commit]}"
50+
echo "JCL: https://github.com/ibmruntimes/openj9-openjdk-jdk${good[openjdk_version]}/compare/${good[jcl_commit]}...${bad[jcl_commit]}"
51+
}
52+
53+
if [ $# -ne 2 ]; then
54+
echo "Usage: $0 <good_build> <bad_build>"
55+
exit 1
56+
fi
57+
58+
GOOD_BUILD="$1"
59+
BAD_BUILD="$2"
60+
61+
# Debug output
62+
echo "Good build: $GOOD_BUILD" >&2
63+
echo "Bad build: $BAD_BUILD" >&2
64+
65+
GOOD_INFO=$(parse_java_version "$GOOD_BUILD")
66+
BAD_INFO=$(parse_java_version "$BAD_BUILD")
67+
68+
# Debug output
69+
echo "Good info: $GOOD_INFO" >&2
70+
echo "Bad info: $BAD_INFO" >&2
71+
72+
required_fields=("openjdk_version" "openj9_commit" "omr_commit" "jcl_commit")
73+
for field in "${required_fields[@]}"; do
74+
if ! echo "$GOOD_INFO" | grep -q "^$field=" || ! echo "$BAD_INFO" | grep -q "^$field="; then
75+
echo "Error: Missing required field: $field" >&2
76+
exit 1
77+
fi
78+
done
79+
80+
generate_compare_urls "$GOOD_INFO" "$BAD_INFO"

0 commit comments

Comments
 (0)