Skip to content

Commit da645b1

Browse files
committed
github actions: Use python PR check script
Obsoletes the old ruby PR check script
1 parent c053ab5 commit da645b1

File tree

2 files changed

+82
-14
lines changed

2 files changed

+82
-14
lines changed
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import sys
2+
import subprocess
3+
import os
4+
5+
requestors = {"gvrose8192": ""}
6+
7+
def file_prepend(file, str):
8+
with open(file, 'r') as fd:
9+
contents = fd.read()
10+
new_contents = str + contents
11+
12+
# Overwrite file but now with prepended string on it
13+
with open(file, 'w') as fd:
14+
fd.write(new_contents)
15+
16+
def process_git_request(fname, target_branch, source_branch, prj_dir):
17+
retcode = 200 # presume success
18+
# print(f"Opening file {fname}")
19+
file = open(fname, "w")
20+
working_dir = prj_dir
21+
# print(f"Working Dir : {working_dir}")
22+
os.chdir(working_dir)
23+
# print(f"pwd : {os.getcwd()}")
24+
git_cmd = f"git log --oneline --no-abbrev-commit origin/{target_branch}..origin/{source_branch}"
25+
# print(git_cmd)
26+
try:
27+
out, err = subprocess.Popen(git_cmd, shell=True, stdout=subprocess.PIPE,
28+
stderr=subprocess.PIPE, text=True).communicate()
29+
if err:
30+
print(f"Command error output is {err}")
31+
file.write(f"Command error output is {err}")
32+
file.close()
33+
retcode = 201
34+
return retcode
35+
36+
output_lines = out.split()
37+
# we just want the commit sha IDs
38+
for x in output_lines:
39+
print(f"This is output_lines {x}")
40+
41+
file.close()
42+
return retcode
43+
except Exception as e:
44+
print(f"Error executing git command: {str(e)}")
45+
file.close()
46+
return 201
47+
48+
first_arg, *argv_in = sys.argv[1:] # Skip script name in sys.argv
49+
50+
if len(argv_in) < 5:
51+
print("Not enough arguments: fname, target_branch, source_branch, prj_dir, pull_request, requestor")
52+
sys.exit()
53+
54+
fname = str(first_arg)
55+
fname = "tmp-" + fname
56+
# print("filename is " + fname)
57+
target_branch = str(argv_in[0])
58+
# print("target branch is " + target_branch)
59+
source_branch = str(argv_in[1])
60+
# print("source branch is " + source_branch)
61+
prj_dir = str(argv_in[2])
62+
# print("project dir is " + prj_dir)
63+
pullreq = str(argv_in[3])
64+
# print("pull request is " + pullreq)
65+
requestor = str(argv_in[4])
66+
67+
retcode = process_git_request(fname, target_branch, source_branch, prj_dir)
68+
69+
if retcode != 200:
70+
with open(fname, 'r') as fd:
71+
contents = fd.read()
72+
print(contents)
73+
sys.exit(1)
74+
else:
75+
print("Done")
76+
77+
sys.exit(0)
78+

.github/workflows/process-pull-request.yml

+4-14
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,9 @@ jobs:
1919

2020
runs-on: ubuntu-latest
2121
strategy:
22-
matrix:
23-
ruby-version: ['3.0']
2422

2523
steps:
2624
- uses: actions/checkout@v4
27-
- name: Set up Ruby
28-
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
29-
# change this to (see https://github.com/ruby/setup-ruby#versioning):
30-
uses: ruby/setup-ruby@v1
31-
# uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
32-
with:
33-
ruby-version: ${{ matrix.ruby-version }}
34-
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
3525
- name: Set up Python
3626
uses: actions/setup-python@v5
3727
- name: Run tests
@@ -42,15 +32,15 @@ jobs:
4232
if ! git fetch origin ${{ github.head_ref }}; then
4333
echo "Unable to checkout ${{ github.head_ref }}"
4434
fi
45-
git remote add linux https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
46-
git fetch --shallow-since="3 years ago" linux
47-
echo "Will run process-git-request.rb with:"
35+
# git remote add linux https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
36+
# git fetch --shallow-since="3 years ago" linux
37+
echo "Will run process-git-request.py with:"
4838
echo "fname = ${{ github.run_id }}"
4939
echo "target_branch = ${{ github.base_ref }}"
5040
echo "source_branch = ${{ github.head_ref }}"
5141
echo "prj_dir = ${{ github.workspace }}"
5242
echo "pull_request = ${{ github.ref }}"
5343
echo "requestor = ${{ github.actor }}"
5444
cd ${{ github.workspace }}
55-
/usr/bin/ruby .github/workflows/process-git-request.rb ${{ github.run_id }} ${{ github.base_ref }} \
45+
/usr/bin/python3 .github/workflows/process-git-request.py ${{ github.run_id }} ${{ github.base_ref }} \
5646
${{ github.head_ref }} ${{ github.workspace }} ${{ github.ref }} ${{ github.actor }}

0 commit comments

Comments
 (0)