forked from adoptium/aqa-test-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (134 loc) · 5.14 KB
/
gitcompare.yml
File metadata and controls
155 lines (134 loc) · 5.14 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
name: GitCompare
on:
issue_comment:
types: [created]
jobs:
parse-comment:
if: 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"
COMMENT=${COMMENT_BODY#.ch_gitcompare}
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
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'"
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
{
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 (Python)
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 "$GOOD_BUILD" > good.txt
echo "$BAD_BUILD" > bad.txt
echo "Running commit_hunter.py..."
python3 commit_hunter.py "$(cat good.txt)" "$(cat bad.txt)" > 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."
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