From 4937c4e266b2d1a2583b793128f87c66c96a7d5e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 04 2018 11:28:30 +0000 Subject: [PATCH 1/3] Bypass old hooks rather than using non-existing symlinks When we moved to the runner architecture, we changed the way hooks are called. During this move, we changed all of our existing hooks into non-existing symlinks pointing to '/does/not/exists' and we were checking if the files on disk were matching this target or not. This created a few issue when releasing pagure: - python setup.py sdist resolve symlinks as part of the archive creation process Reported in https://pagure.io/pagure/issue/3782 - Building pagure failed on some system because these symlinks does not exist Reported in https://pagure.io/pagure/issue/3706 So in this commit we are dropping the use of symlink and just making pagure ignore all the hook it could have created. Fixes https://pagure.io/pagure/issue/3782 Fixes https://pagure.io/pagure/issue/3706 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/hooks/__init__.py b/pagure/hooks/__init__.py index 660e6a0..d7b949f 100644 --- a/pagure/hooks/__init__.py +++ b/pagure/hooks/__init__.py @@ -435,10 +435,9 @@ def run_project_hooks( if hook.startswith(hooktype + "."): hookfile = os.path.join(hookdir, hook) - # Determine if this is an actual hook, or if it's a remnant - # from a hook that was installed before it was moved to the - # runner system. - if os.path.realpath(hookfile) == pagure.lib.query.HOOK_DNE_TARGET: + # By-pass all the old hooks that pagure may have created before + # moving to the runner architecture + if hook in pagure.lib.query.ORIGINAL_PAGURE_HOOK: continue # Execute diff --git a/pagure/lib/query.py b/pagure/lib/query.py index 87b90b5..ecf7434 100644 --- a/pagure/lib/query.py +++ b/pagure/lib/query.py @@ -69,9 +69,23 @@ from pagure.lib import tasks_services REDIS = None PAGURE_CI = None _log = logging.getLogger(__name__) -# The target for hooks migrated to the Runner system, to be able to detect -# whether a hook was migrated without having to open and read the file -HOOK_DNE_TARGET = "/does/not/exist" +# List of all the possible hooks pagure could generate before it was moved +# to the runner architecture we now use. +# This list is kept so we can ignore all of these hooks. +ORIGINAL_PAGURE_HOOK = [ + "post-receive.default", + "post-receive.fedmsg", + "post-receive.irc", + "post-receive.mail", + "post-receive.mirror", + "post-receive.pagure", + "post-receive.pagure-requests", + "post-receive.pagure-ticket", + "post-receive.rtd", + "pre-receive.pagure_no_new_branches", + "pre-receive.pagureforcecommit", + "pre-receive.pagureunsignedcommit", +] def get_repotypes(): diff --git a/pagure/lib/tasks.py b/pagure/lib/tasks.py index a3deb4e..051d785 100644 --- a/pagure/lib/tasks.py +++ b/pagure/lib/tasks.py @@ -605,7 +605,6 @@ def move_to_repospanner(self, session, name, namespace, user, region): raise Exception("Project is already on repoSpanner") # Make sure that no non-runner hooks are enabled for this project - compatible_targets = [pagure.lib.query.HOOK_DNE_TARGET] incompatible_hooks = [] for repotype in pagure.lib.query.get_repotypes(): path = project.repopath(repotype) @@ -620,8 +619,7 @@ def move_to_repospanner(self, session, name, namespace, user, region): if hook.endswith(".sample"): # Ignore the samples that Git inserts continue - hookfile = os.path.join(hookpath, hook) - if os.path.realpath(hookfile) not in compatible_targets: + if hook not in pagure.lib.query.ORIGINAL_PAGURE_HOOK: incompatible_hooks.append((repotype, hook)) if incompatible_hooks: From e0fd667a223506e3e373149a7cbc5f74467cfe77 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 04 2018 11:28:30 +0000 Subject: [PATCH 2/3] When calling the hooks, ignore the samples that git inserts Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/hooks/__init__.py b/pagure/hooks/__init__.py index d7b949f..6faf8c7 100644 --- a/pagure/hooks/__init__.py +++ b/pagure/hooks/__init__.py @@ -440,6 +440,10 @@ def run_project_hooks( if hook in pagure.lib.query.ORIGINAL_PAGURE_HOOK: continue + if hook.endswith(".sample"): + # Ignore the samples that Git inserts + continue + # Execute print( "Running legacy hook %s. " From 0055c093e07e8ca0672ba49c9801d170ee72c570 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 04 2018 11:28:30 +0000 Subject: [PATCH 3/3] Adjust a little bit the information message Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/hooks/__init__.py b/pagure/hooks/__init__.py index 6faf8c7..37fed8c 100644 --- a/pagure/hooks/__init__.py +++ b/pagure/hooks/__init__.py @@ -427,7 +427,10 @@ def run_project_hooks( stdin = stdin.encode("utf-8") if debug: - print("Running legacy hooks with args: %s, stdin: %s" % (args, stdin)) + print( + "Running legacy hooks (if any) with args: %s, stdin: %s" + % (args, stdin) + ) for hook in os.listdir(hookdir): # This is for legacy hooks, which create symlinks in the form of