Skip to content

github actions: Use python PR check script #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .github/workflows/process-git-request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import sys
import subprocess
import os

requestors = {"gvrose8192": ""}

def file_prepend(file, str):
with open(file, 'r') as fd:
contents = fd.read()
new_contents = str + contents

# Overwrite file but now with prepended string on it
with open(file, 'w') as fd:
fd.write(new_contents)

def process_git_request(fname, target_branch, source_branch, prj_dir):
retcode = 200 # presume success
# print(f"Opening file {fname}")
file = open(fname, "w")
working_dir = prj_dir
# print(f"Working Dir : {working_dir}")
os.chdir(working_dir)
# print(f"pwd : {os.getcwd()}")
git_cmd = f"git log --oneline --no-abbrev-commit origin/{target_branch}..origin/{source_branch}"
# print(git_cmd)
try:
out, err = subprocess.Popen(git_cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, text=True).communicate()
if err:
print(f"Command error output is {err}")
file.write(f"Command error output is {err}")
file.close()
retcode = 201
return retcode

output_lines = out.split()
# we just want the commit sha IDs
for x in output_lines:
print(f"This is output_lines {x}")

file.close()
return retcode
except Exception as e:
print(f"Error executing git command: {str(e)}")
file.close()
return 201

first_arg, *argv_in = sys.argv[1:] # Skip script name in sys.argv

if len(argv_in) < 5:
print("Not enough arguments: fname, target_branch, source_branch, prj_dir, pull_request, requestor")
sys.exit()

fname = str(first_arg)
fname = "tmp-" + fname
# print("filename is " + fname)
target_branch = str(argv_in[0])
# print("target branch is " + target_branch)
source_branch = str(argv_in[1])
# print("source branch is " + source_branch)
prj_dir = str(argv_in[2])
# print("project dir is " + prj_dir)
pullreq = str(argv_in[3])
# print("pull request is " + pullreq)
requestor = str(argv_in[4])

retcode = process_git_request(fname, target_branch, source_branch, prj_dir)

if retcode != 200:
with open(fname, 'r') as fd:
contents = fd.read()
print(contents)
sys.exit(1)
else:
print("Done")

sys.exit(0)

18 changes: 4 additions & 14 deletions .github/workflows/process-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,9 @@ jobs:

runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.0']

steps:
- uses: actions/checkout@v4
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
uses: ruby/setup-ruby@v1
# uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Set up Python
uses: actions/setup-python@v5
- name: Run tests
Expand All @@ -42,15 +32,15 @@ jobs:
if ! git fetch origin ${{ github.head_ref }}; then
echo "Unable to checkout ${{ github.head_ref }}"
fi
git remote add linux https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --shallow-since="3 years ago" linux
echo "Will run process-git-request.rb with:"
# git remote add linux https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
# git fetch --shallow-since="3 years ago" linux
echo "Will run process-git-request.py with:"
echo "fname = ${{ github.run_id }}"
echo "target_branch = ${{ github.base_ref }}"
echo "source_branch = ${{ github.head_ref }}"
echo "prj_dir = ${{ github.workspace }}"
echo "pull_request = ${{ github.ref }}"
echo "requestor = ${{ github.actor }}"
cd ${{ github.workspace }}
/usr/bin/ruby .github/workflows/process-git-request.rb ${{ github.run_id }} ${{ github.base_ref }} \
/usr/bin/python3 .github/workflows/process-git-request.py ${{ github.run_id }} ${{ github.base_ref }} \
${{ github.head_ref }} ${{ github.workspace }} ${{ github.ref }} ${{ github.actor }}
Loading