Skip to content

Commit 3e5770b

Browse files
committed
github actions: Incorporate feedback on workflows
Add workflows for pushes and pull requests. Signed-off-by: Greg Rose <[email protected]>
1 parent f90dffe commit 3e5770b

6 files changed

+416
-0
lines changed

.github/workflows/diffdiff.py

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#!/usr/bin/env python3
2+
# coding: utf-8
3+
#
4+
5+
import argparse
6+
import copy
7+
import difflib
8+
import io
9+
import git
10+
import os
11+
import re
12+
import subprocess
13+
import sys
14+
import tempfile
15+
16+
verbose = False
17+
18+
19+
def get_upstream_commit(upstream, c):
20+
for l in c.message.splitlines():
21+
try:
22+
sha = re.match('\s*commit\s+(?P<sha>\S+)', l).groups()[0].upper()
23+
return upstream.commit(sha)
24+
except:
25+
True
26+
27+
def get_diff(d):
28+
dif = ''
29+
df = False
30+
for l in d.splitlines():
31+
if l[:10] == 'diff --git':
32+
df = True
33+
if not df:
34+
continue
35+
dif = dif + l + '\n'
36+
return dif
37+
38+
39+
def trim_unchanged_files(lines):
40+
dl = []
41+
ld = 0 # Last line with a 'diff --git' we saw
42+
hd = False # Have we seen a changed line since ld?
43+
i = 0
44+
for i, l in enumerate(lines):
45+
if l[:4] == '+++ ' or l[:4] == '--- ' :
46+
continue
47+
if l[0] == '+' or l[0] == '-':
48+
hd = True
49+
if l[:11] == ' diff --git':
50+
if ld: # We are at a new diff now, last one started at 'ld'
51+
if not hd:
52+
dl.insert(0, (ld, i+1),)
53+
ld = i
54+
hd = False # Reset hasdiff to False as we start a new section
55+
# and check the tail
56+
if not hd:
57+
dl.insert(0, (ld, i+1),)
58+
# delete the unchanged file sections
59+
for d in dl:
60+
del lines[d[0]:d[1]]
61+
return lines
62+
63+
64+
if __name__ == "__main__":
65+
parser = argparse.ArgumentParser()
66+
parser.add_argument('-v', action='store_true', help='Verbose')
67+
parser.add_argument('--colour', action='store_true', help='Colorize the diff. Green for additions, red for deletions')
68+
parser.add_argument('--commit', help='Commit in current tree to diffdiff. Default is the most recent commit.')
69+
parser.add_argument('--upstream', help='A directory that contains the current upstream of linus kernel tree where we can find the commits we reference. Default is the current repo')
70+
args = parser.parse_args()
71+
72+
73+
if args.v:
74+
verbose = True
75+
76+
srcgit = git.Repo.init('.')
77+
upstream = git.Repo.init(args.upstream)
78+
c = srcgit.head.commit if not args.commit else srcgit.commit(args.commit)
79+
uc = get_upstream_commit(upstream, c)
80+
81+
dc = get_diff(srcgit.git.show(c))
82+
duc = get_diff(upstream.git.show(uc))
83+
84+
with open('c.diff', 'w') as f:
85+
f.write(dc)
86+
with open('u.diff', 'w') as f:
87+
f.write(duc)
88+
89+
res = subprocess.run(['diff', '-u', 'u.diff', 'c.diff'],
90+
check=False, stdout=subprocess.PIPE)
91+
lines = res.stdout.splitlines()
92+
dd = []
93+
for l in lines:
94+
l = str(l)[2:-1]
95+
if l[:6] == '-index':
96+
continue
97+
if l[:6] == '+index':
98+
continue
99+
if l[:3] == '-@@':
100+
continue
101+
if l[:3] == '+@@':
102+
dd.append(' ' + l[1:])
103+
continue
104+
dd.append(l)
105+
106+
# trim diffs for files that did not change
107+
lines = trim_unchanged_files(dd)
108+
109+
# colorize the diff
110+
diffs = 0
111+
if args.colour:
112+
dd = []
113+
for l in lines:
114+
if l[0:4] != '+++ ' and l[0:4] != '--- ':
115+
if l[0] == '+':
116+
l = '\033[42m' + l + '\033[0m'
117+
diffs = diffs + 1
118+
if l[0] == '-':
119+
l = '\033[41m' + l + '\033[0m'
120+
diffs = diffs + 1
121+
dd.append(l)
122+
lines = dd
123+
124+
125+
if diffs:
126+
for l in lines:
127+
print(l)
128+
129+
sys.exit(diffs)
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: GitHub Actions Sanity Check
2+
run-name: ${{ github.actor }} is running actions - this runs as a sanity check 🚀
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
- '!mainline'
8+
9+
jobs:
10+
Explore-GitHub-Actions:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
14+
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
15+
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
16+
- name: Check out repository code
17+
uses: actions/checkout@v4
18+
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
19+
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
20+
- name: List files in the repository
21+
run: |
22+
ls ${{ github.workspace }}
23+
df .
24+
df /
25+
pwd
26+
- run: echo "🍏 This job's status is ${{ job.status }}."
+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
require 'open3'
2+
3+
requestors = { "gvrose8192" => "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" }
4+
5+
def file_prepend(file, str)
6+
new_contents = ""
7+
File.open(file, 'r') do |fd|
8+
contents = fd.read
9+
new_contents = str << contents
10+
end
11+
# Overwrite file but now with prepended string on it
12+
File.open(file, 'w') do |fd|
13+
fd.write(new_contents)
14+
end
15+
end
16+
17+
def process_git_request(fname, target_branch, source_branch, prj_dir)
18+
retcode = 200 #presume success
19+
# puts "Opening file " + fname
20+
file = File.new(fname, "w")
21+
working_dir = prj_dir
22+
# puts "Working Dir : " + working_dir
23+
Dir.chdir working_dir
24+
# puts "pwd : " + Dir.pwd
25+
git_cmd = "git log --oneline --no-abbrev-commit origin/" + target_branch + ".." + "origin/" + source_branch
26+
# puts git_cmd
27+
out, err, status = Open3.capture3(git_cmd)
28+
if status.exitstatus != 0
29+
puts "Command error output is " + err
30+
file.write("Command error output is " + err)
31+
file.close
32+
retcode = 201
33+
return retcode
34+
end
35+
output_lines = out.split(' ')
36+
# we just want the commit sha IDs
37+
output_lines.each { |x|
38+
# puts "This is output_lines " + x
39+
upstream_diff = false
40+
if !x[/\H/]
41+
if x.length < 40
42+
next
43+
end
44+
git_cmd = "git show " + x
45+
gitlog_out, gitlog_err, gitlog_status = Open3.capture3(git_cmd)
46+
if gitlog_status.exitstatus != 0
47+
file.write("git show command error output is " + gitlog_err)
48+
retcode = 201
49+
end
50+
loglines = gitlog_out.lines.map(&:chomp)
51+
lines_counted = 0
52+
local_diffdiff_sha = ""
53+
upstream_diffdiff_sha = ""
54+
loglines.each { |logline|
55+
lines_counted = lines_counted + 1
56+
if lines_counted == 1
57+
local_commit_sha = logline.match("[0-9a-f]\{40\}")
58+
local_diffdiff_sha = local_commit_sha.to_s
59+
# puts "Local : " + local_diffdiff_sha
60+
file.write("Merge Request sha: " + local_diffdiff_sha)
61+
file.write("\n")
62+
end
63+
if lines_counted == 2 #email address
64+
if !logline.downcase.include? "ciq.com"
65+
# Bad Author
66+
s = "error:\nBad " + logline + "\n"
67+
puts s
68+
file.write(s)
69+
retcode = 201
70+
else
71+
file.write("\t" + logline + "\n")
72+
end
73+
end
74+
if lines_counted > 1
75+
if logline.downcase.include? "jira"
76+
file.write("\t" + logline + "\n")
77+
end
78+
if logline.downcase.include? "upstream-diff"
79+
upstream_diff = true
80+
end
81+
if logline.downcase.include? "commit"
82+
commit_sha = logline.match("[0-9a-f]\{40\}")
83+
upstream_diffdiff_sha = commit_sha.to_s
84+
# puts "Upstream : " + upstream_diffdiff_sha
85+
if (!upstream_diffdiff_sha.empty?)
86+
file.write("\tUpstream sha: " + upstream_diffdiff_sha)
87+
file.write("\n")
88+
end
89+
end
90+
end
91+
if lines_counted > 8 #Everything we need should be in the first 8 lines
92+
break
93+
end
94+
}
95+
if !local_diffdiff_sha.empty? && !upstream_diffdiff_sha.empty?
96+
diff_cmd = Dir.pwd + "/.github/workflows/diffdiff.py --colour --commit " + local_diffdiff_sha
97+
puts "diffdiff: " + diff_cmd
98+
diff_out, diff_err, diff_status = Open3.capture3(diff_cmd)
99+
if diff_status.exitstatus != 0 && !upstream_diff
100+
puts "diffdiff out: " + diff_out
101+
puts "diffdiff err: " + diff_err
102+
retcode = 201
103+
file.write("error:\nCommit: " + local_diffdiff_sha + " differs with no upstream tag in commit message\n")
104+
end
105+
end
106+
end
107+
}
108+
file.close
109+
return retcode
110+
end
111+
112+
first_arg, *argv_in = ARGV
113+
if argv_in.length < 5
114+
puts "Not enough arguments: fname, target_branch, source_branch, prj_dir, pull_request, requestor"
115+
exit
116+
end
117+
fname = first_arg.to_s
118+
fname = "tmp-" + fname
119+
# puts "filename is " + fname
120+
target_branch = argv_in[0].to_s
121+
# puts "target branch is " + target_branch
122+
source_branch = argv_in[1].to_s
123+
# puts "source branch is " + source_branch
124+
prj_dir = argv_in[2].to_s
125+
# puts "project dir is " + prj_dir
126+
pullreq = argv_in[3].to_s
127+
# puts "pull request is " + pullreq
128+
requestor = argv_in[4].to_s
129+
retcode = process_git_request(fname, target_branch, source_branch, prj_dir)
130+
if retcode != 200
131+
File.open(fname, 'r') do |fd|
132+
contents = fd.read
133+
puts contents
134+
end
135+
exit(1)
136+
else
137+
puts "Done"
138+
end
139+
exit(0)
140+
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
name: Pull Request Checker
7+
8+
on:
9+
pull_request:
10+
branches:
11+
- '**'
12+
- '!mainline'
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
test:
19+
20+
runs-on:
21+
labels: kernel-build
22+
strategy:
23+
matrix:
24+
ruby-version: ['3.0']
25+
26+
steps:
27+
- uses: actions/checkout@v4
28+
- name: Set up Ruby
29+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
30+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
31+
uses: ruby/setup-ruby@v1
32+
# uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
33+
with:
34+
ruby-version: ${{ matrix.ruby-version }}
35+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
36+
- name: Set up Python
37+
uses: actions/setup-python@v5
38+
- name: Run tests
39+
run: |
40+
/usr/bin/pip3 install gitPython
41+
python -c "import sys; import git; print(sys.version)"
42+
git fetch origin ${{ github.base_ref }}
43+
git fetch origin ${{ github.head_ref }}
44+
git remote add linux https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
45+
git fetch --shallow-since="3 years ago" linux
46+
echo "Will run process-git-request.rb with:"
47+
echo "fname = ${{ github.run_id }}"
48+
echo "target_branch = ${{ github.base_ref }}"
49+
echo "source_branch = ${{ github.head_ref }}"
50+
echo "prj_dir = ${{ github.workspace }}"
51+
echo "pull_request = ${{ github.ref }}"
52+
echo "requestor = ${{ github.actor }}"
53+
cd ${{ github.workspace }}
54+
/usr/bin/ruby .github/workflows/process-git-request.rb ${{ github.run_id }} ${{ github.base_ref }} \
55+
${{ github.head_ref }} ${{ github.workspace }} ${{ github.ref }} ${{ github.actor }}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- '**'
6+
- '!mainline'
7+
8+
jobs:
9+
kernel-build-job:
10+
runs-on:
11+
labels: kernel-build-arm64
12+
container:
13+
image: rockylinux:8
14+
env:
15+
ROCKY_ENV: rocky8
16+
ports:
17+
- 80
18+
options: --cpus 8
19+
steps:
20+
- name: Install tools and Libraries
21+
run: |
22+
dnf groupinstall 'Development Tools' -y
23+
dnf install --enablerepo=devel bc dwarves kernel-devel openssl-devel elfutils-libelf-devel -y
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
- name: Build the Kernel
29+
run: |
30+
git config --global --add safe.directory /__w/kernel-src-git/kernel-src-git
31+
cp configs/kernel-4.18.0-aarch64.config .config
32+
make olddefconfig
33+
make -j8

0 commit comments

Comments
 (0)