Skip to content
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

fix license ci by using merge base #3732

Closed
wants to merge 1 commit into from
Closed
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
60 changes: 40 additions & 20 deletions tools/check_stamped.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
# in the license stamp, with the assumption being that any modifications/creations will need to be stamped to the year that the
# modification/creation was made.
#####################################################################################
import subprocess, sys, datetime, argparse
import subprocess, sys, datetime, argparse, os

debug = False
debug = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to keep this as false for the actual PR


current_year = datetime.date.today().year

Expand Down Expand Up @@ -110,26 +110,47 @@ def check_filename(filename: str, fileTuple: tuple or list) -> bool:
return True
return False

def eval(cmd, **kwargs):
return subprocess.run(cmd,
capture_output=True,
shell=isinstance(cmd, str),
check=True,
**kwargs).stdout.decode('utf-8').strip()

def main(branch) -> None:
unsupported_file_types.extend(specificIgnores)

## Get a list of all files (not including deleted) that have changed/added in comparison to the latest Dev branch from MI Graphx
def is_excluded(f):
base = os.path.basename(f)
return base in unsupported_file_types


def get_top():
return eval("git rev-parse --show-toplevel")


def get_head():
return eval("git rev-parse --abbrev-ref HEAD")


# Subprocess 1 is fetching the latest dev branch from the MIgraphX Url and naming it as 'FETCH_HEAD'
subprocess.run(
"git fetch https://github.com/ROCmSoftwarePlatform/AMDMIGraphX {0} --quiet"
.format(branch),
shell=True,
stdout=subprocess.PIPE)
def get_merge_base(branch):
head = get_head()
return eval(f"git merge-base {branch} {head}")

# proc 2 is getting the list of file differences between FETCH_HEAD and the branch to be merged. (filters out deleted files from FETCH_HEAD)
proc = subprocess.run("git diff --name-only --diff-filter=d FETCH_HEAD",
shell=True,
stdout=subprocess.PIPE)
fileList = proc.stdout.decode().split('\n')

if debug: print(f"Target file list {len(fileList)}:\n" + str(fileList))
def get_files_changed(against, ext=('.py')):
files = eval(
f"git diff-index --cached --name-only --diff-filter=d {against}",
cwd=get_top()).splitlines()
return (f for f in files if f.endswith(ext) and not is_excluded(f))

def main(against) -> None:
unsupported_file_types.extend(specificIgnores)

base = get_merge_base(against)
fileList = list(
get_files_changed(base,
ext=supported_file_types))

if debug: print(fileList)

for file in fileList:
if check_filename(file, supported_file_types):
Expand Down Expand Up @@ -169,9 +190,8 @@ def main(branch) -> None:


if __name__ == "__main__":

parser = argparse.ArgumentParser()
parser.add_argument("branch")
parser.add_argument('against', default='develop', nargs='?')
args = parser.parse_args()

main(args.branch)
main(args.against)
Loading