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 : Set issue number env
102+ run : echo "ISSUE_NUMBER=${{ github.event.issue.number }}" >> $GITHUB_ENV
103+
104+ - name : Comment on PR (Python)
105+ env :
106+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
107+ GITHUB_REPOSITORY : ${{ github.repository }}
108+ run : |
109+ pip install PyGithub
110+ python <<EOF
111+ import os
112+ from github import Github
113+
114+ with open("comment.md", "r", encoding="utf-8") as f:
115+ comment_body = f.read()
116+
117+ token = os.environ["GITHUB_TOKEN"]
118+ repo_name = os.environ["GITHUB_REPOSITORY"]
119+ issue_number = int(os.environ["ISSUE_NUMBER"])
120+
121+ g = Github(token)
122+ repo = g.get_repo(repo_name)
123+ issue = repo.get_issue(number=issue_number)
124+ issue.create_comment(comment_body)
125+ EOF
0 commit comments