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