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

use 'git am' to apply patch for PRs in fetch_easyconfigs_from_pr #2680

Merged
Merged
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
8 changes: 6 additions & 2 deletions easybuild/tools/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ def guess_patch_level(patched_files, parent_dir):
return patch_level


def apply_patch(patch_file, dest, fn=None, copy=False, level=None):
def apply_patch(patch_file, dest, fn=None, copy=False, level=None, use_git_am=False):
"""
Apply a patch to source code in directory dest
- assume unified diff created with "diff -ru old new"
Expand Down Expand Up @@ -1002,7 +1002,11 @@ def apply_patch(patch_file, dest, fn=None, copy=False, level=None):
else:
_log.debug("Using specified patch level %d for patch %s" % (level, patch_file))

patch_cmd = "patch -b -p%s -i %s" % (level, apatch)
if use_git_am:
patch_cmd = "git am patch %s" % apatch
else:
patch_cmd = "patch -b -p%s -i %s" % (level, apatch)

out, ec = run.run_cmd(patch_cmd, simple=False, path=adest, log_ok=False, trace=False)

if ec:
Expand Down
5 changes: 3 additions & 2 deletions easybuild/tools/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,10 @@ def pr_url(gh):
diff_filepath = os.path.join(path, diff_fn)
download_file(diff_fn, pr_data['diff_url'], diff_filepath, forced=True)
diff_txt = read_file(diff_filepath)
_log.debug("Diff for PR #%s:\n%s", pr, diff_txt)

patched_files = det_patched_files(txt=diff_txt, omit_ab_prefix=True, github=True, filter_deleted=True)
_log.debug("List of patched files: %s" % patched_files)
_log.debug("List of patched files for PR #%s: %s", pr, patched_files)

for key, val in sorted(pr_data.items()):
_log.debug("\n%s:\n\n%s\n", key, val)
Expand Down Expand Up @@ -431,7 +432,7 @@ def pr_url(gh):
elif not pr_closed:
try:
_log.debug("Trying to apply PR patch %s to %s...", diff_filepath, repo_target_branch)
apply_patch(diff_filepath, repo_target_branch, level=1)
apply_patch(diff_filepath, repo_target_branch, use_git_am=True)
_log.info("Using %s which included PR patch to test PR #%s", repo_target_branch, pr)
final_path = repo_target_branch

Expand Down
17 changes: 16 additions & 1 deletion test/framework/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,23 @@ def test_fetch_easyconfigs_from_pr(self):
'libxc-4.2.3-gimkl-2017a.eb',
'libxc-4.2.3-intel-2018a.eb',
]
# PR where files are renamed
# see https://github.com/easybuilders/easybuild-easyconfigs/pull/7159/files
all_ecs_pr7159 = [
'DOLFIN-2018.1.0.post1-foss-2018a-Python-3.6.4.eb',
'OpenFOAM-5.0-20180108-foss-2018a.eb',
'OpenFOAM-5.0-20180108-intel-2018a.eb',
'OpenFOAM-6-foss-2018b.eb',
'OpenFOAM-6-intel-2018a.eb',
'OpenFOAM-v1806-foss-2018b.eb',
'PETSc-3.9.3-foss-2018a.eb',
'SCOTCH-6.0.6-foss-2018a.eb',
'SCOTCH-6.0.6-foss-2018b.eb',
'SCOTCH-6.0.6-intel-2018a.eb',
'Trilinos-12.12.1-foss-2018a-Python-3.6.4.eb'
]

for pr, all_ecs in [(2481, all_ecs_pr2481), (6587, all_ecs_pr6587)]:
for pr, all_ecs in [(2481, all_ecs_pr2481), (6587, all_ecs_pr6587), (7159, all_ecs_pr7159)]:
try:
tmpdir = os.path.join(self.test_prefix, 'pr%s' % pr)
ec_files = gh.fetch_easyconfigs_from_pr(pr, path=tmpdir, github_user=GITHUB_TEST_ACCOUNT)
Expand Down