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, '.ch_gitcompare')
10+ runs-on : ubuntu-latest
11+ permissions :
12+ contents : read
13+ issues : write
14+ pull-requests : write
15+ outputs :
16+ good_build : ${{ steps.parse.outputs.good_build }}
17+ bad_build : ${{ steps.parse.outputs.bad_build }}
18+ steps :
19+ - name : Parse comment
20+ id : parse
21+ env :
22+ COMMENT_BODY : ${{ github.event.comment.body }}
23+ run : |
24+ echo "Comment body: $COMMENT_BODY"
25+
26+ # Extract good_build and bad_build from the command
27+ # Remove the .ch_gitcompare command
28+ COMMENT=${COMMENT_BODY#.ch_gitcompare}
29+
30+ # Parse --good_build argument (capture everything until --bad_build)
31+ if [[ $COMMENT =~ --good_build[[:space:]]+(.*)[[:space:]]+--bad_build[[:space:]]+(.*) ]]; then
32+ GOOD_BUILD="${BASH_REMATCH[1]}"
33+ BAD_BUILD="${BASH_REMATCH[2]}"
34+ else
35+ echo "Error: Invalid format. Please use: .ch_gitcompare --good_build <good_build> --bad_build <bad_build>"
36+ exit 1
37+ fi
38+
39+ # Clean up whitespace and remove outer quotes
40+ GOOD_BUILD=$(echo "$GOOD_BUILD" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | sed 's/^"//;s/"$//')
41+ BAD_BUILD=$(echo "$BAD_BUILD" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | sed 's/^"//;s/"$//')
42+
43+ echo "Good build: '$GOOD_BUILD'"
44+ echo "Bad build: '$BAD_BUILD'"
45+
46+ # Validate builds
47+ if [ -z "$GOOD_BUILD" ] || [ -z "$BAD_BUILD" ]; then
48+ echo "Error: Invalid format. Please use: .ch_gitcompare --good_build <good_build> --bad_build <bad_build>"
49+ exit 1
50+ fi
51+
52+ # Set outputs
53+ {
54+ echo "good_build<<EOF"
55+ echo "$GOOD_BUILD"
56+ echo "EOF"
57+ } >> $GITHUB_OUTPUT
58+
59+ {
60+ echo "bad_build<<EOF"
61+ echo "$BAD_BUILD"
62+ echo "EOF"
63+ } >> $GITHUB_OUTPUT
64+
65+ compare :
66+ needs : parse-comment
67+ runs-on : ubuntu-latest
68+ permissions :
69+ contents : read
70+ issues : write
71+ pull-requests : write
72+ steps :
73+ - name : Checkout repository
74+ uses : actions/checkout@v4
75+
76+ - name : Run CommitHunter
77+ id : run_commit_hunter
78+ env :
79+ GOOD_BUILD : ${{ needs.parse-comment.outputs.good_build }}
80+ BAD_BUILD : ${{ needs.parse-comment.outputs.bad_build }}
81+ run : |
82+ cd CommitHunter
83+ echo "Running commit_hunter.sh with:"
84+ echo "Good build: $GOOD_BUILD"
85+ echo "Bad build: $BAD_BUILD"
86+ bash commit_hunter.sh "$GOOD_BUILD" "$BAD_BUILD" > output.txt
87+ echo "CommitHunter output:"
88+ cat output.txt
89+
90+ - name : Parse URLs from output
91+ id : parse_urls
92+ run : |
93+ if [ -f "./CommitHunter/output.txt" ]; then
94+ echo "Found output file, parsing URLs..."
95+ cat ./CommitHunter/output.txt
96+
97+ url_openj9=$(grep "OpenJ9:" ./CommitHunter/output.txt | awk '{print $2}')
98+ url_omr=$(grep "OMR:" ./CommitHunter/output.txt | awk '{print $2}')
99+ url_jcl=$(grep "JCL:" ./CommitHunter/output.txt | awk '{print $2}')
100+
101+ echo "Parsed URLs:"
102+ echo "OpenJ9: $url_openj9"
103+ echo "OMR: $url_omr"
104+ echo "JCL: $url_jcl"
105+
106+ echo "url_openj9=$url_openj9" >> $GITHUB_OUTPUT
107+ echo "url_omr=$url_omr" >> $GITHUB_OUTPUT
108+ echo "url_jcl=$url_jcl" >> $GITHUB_OUTPUT
109+ else
110+ echo "Error: output.txt not found in CommitHunter directory"
111+ ls -la ./CommitHunter/
112+ exit 1
113+ fi
114+
115+ - name : Prepare comment
116+ run : |
117+ echo "## 🔍 GitCompare Results" > comment.md
118+ echo "" >> comment.md
119+ echo "### OpenJ9 Changes" >> comment.md
120+ echo "${{ steps.parse_urls.outputs.url_openj9 }}" >> comment.md
121+ echo "" >> comment.md
122+ echo "### OMR Changes" >> comment.md
123+ echo "${{ steps.parse_urls.outputs.url_omr }}" >> comment.md
124+ echo "" >> comment.md
125+ echo "### JCL Changes" >> comment.md
126+ echo "${{ steps.parse_urls.outputs.url_jcl }}" >> comment.md
127+ echo "" >> comment.md
128+ echo "> 💡 **Note:** These links show the differences between the specified builds."
129+
130+ echo "Prepared comment:"
131+ cat comment.md
132+
133+ - name : Comment on PR
134+ env :
135+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
136+ GITHUB_REPOSITORY : ${{ github.repository }}
137+ ISSUE_NUMBER : ${{ github.event.issue.number }}
138+ run : |
139+ pip install PyGithub
140+ python3 <<EOF
141+ import os
142+ import sys
143+ from github import Github
144+
145+ try:
146+ with open("comment.md", "r", encoding="utf-8") as f:
147+ comment_body = f.read()
148+
149+ token = os.environ["GITHUB_TOKEN"]
150+ repo_name = os.environ["GITHUB_REPOSITORY"]
151+ issue_number = int(os.environ["ISSUE_NUMBER"])
152+
153+ g = Github(token)
154+ repo = g.get_repo(repo_name)
155+ issue = repo.get_issue(number=issue_number)
156+
157+ comment = issue.create_comment(comment_body)
158+ print(f"✅ Comment created successfully: {comment.html_url}")
159+
160+ except Exception as e:
161+ print(f"❌ Error creating comment: {e}")
162+ print(f"Error type: {type(e).__name__}")
163+ sys.exit(1)
164+ EOF
0 commit comments