Skip to content

Commit 1d87491

Browse files
authored
fix: use a patch for rerender (#22)
* fix: use a patch for rerender * fix: sync perms and stage properly * fix: wrong git diff syntax * fix: strip newlines and spaces * test: debug what is going on here * fix: do not cache docker build for now
1 parent 530e020 commit 1d87491

File tree

3 files changed

+67
-21
lines changed

3 files changed

+67
-21
lines changed

.github/workflows/tests.yml

+4-6
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@ jobs:
6060
push: false
6161
load: true
6262
tags: conda-forge-feedstock-ops:test
63-
cache-from: type=gha
64-
cache-to: type=gha,mode=max
65-
66-
- name: run tests
67-
run: |
68-
pytest -vvs tests
6963

7064
- name: ensure cli runs
7165
run: |
7266
conda-forge-feedstock-ops-container --help
67+
68+
- name: run tests
69+
run: |
70+
pytest -vvs tests

conda_forge_feedstock_ops/__main__.py

+48-9
Original file line numberDiff line numberDiff line change
@@ -113,30 +113,40 @@ def _run_bot_task(func, *, log_level, existing_feedstock_node_attrs, **kwargs):
113113
print(dumps(ret))
114114

115115

116-
def _execute_git_cmds_and_report(*, cmds, cwd, msg):
116+
def _execute_git_cmds_and_report(*, cmds, cwd, msg, ignore_stderr=False):
117117
logger = logging.getLogger("conda_forge_feedstock_ops.container")
118118

119119
try:
120120
_output = ""
121+
_output_stderr = ""
121122
for cmd in cmds:
122123
gitret = subprocess.run(
123124
cmd,
124125
cwd=cwd,
125126
stdout=subprocess.PIPE,
126-
stderr=subprocess.STDOUT,
127+
stderr=subprocess.PIPE if ignore_stderr else subprocess.STDOUT,
127128
text=True,
128129
)
129130
logger.debug("git command %r output: %s", cmd, gitret.stdout)
130131
_output += gitret.stdout
132+
if ignore_stderr:
133+
_output_stderr += gitret.stderr
131134
gitret.check_returncode()
132135
except Exception as e:
133-
logger.error("%s\noutput: %s", msg, _output, exc_info=e)
136+
logger.error(
137+
"%s\noutput: %s\nstderr: %s",
138+
msg,
139+
_output,
140+
_output_stderr if ignore_stderr else "<in output>",
141+
exc_info=e,
142+
)
134143
raise e
135144

145+
return _output
146+
136147

137148
def _rerender_feedstock(*, timeout):
138149
from conda_forge_feedstock_ops.os_utils import (
139-
chmod_plus_rwX,
140150
get_user_execute_permissions,
141151
reset_permissions_with_user_execute,
142152
sync_dirs,
@@ -192,6 +202,13 @@ def _rerender_feedstock(*, timeout):
192202
msg="git init failed for rerender",
193203
)
194204

205+
prev_commit = _execute_git_cmds_and_report(
206+
cmds=[["git", "rev-parse", "HEAD"]],
207+
cwd=fs_dir,
208+
msg="git rev-parse HEAD failed for rerender prev commit",
209+
ignore_stderr=True,
210+
).strip()
211+
195212
if timeout is not None:
196213
kwargs = {"timeout": timeout}
197214
else:
@@ -212,16 +229,38 @@ def _rerender_feedstock(*, timeout):
212229
msg="git status failed for rerender",
213230
)
214231

215-
# if something changed, copy back the new feedstock
216232
if msg is not None:
217233
output_permissions = get_user_execute_permissions(fs_dir)
218-
sync_dirs(fs_dir, input_fs_dir, ignore_dot_git=True, update_git=False)
234+
235+
_execute_git_cmds_and_report(
236+
cmds=[
237+
["git", "add", "."],
238+
["git", "commit", "-am", msg],
239+
],
240+
cwd=fs_dir,
241+
msg="git commit failed for rerender",
242+
)
243+
curr_commit = _execute_git_cmds_and_report(
244+
cmds=[["git", "rev-parse", "HEAD"]],
245+
cwd=fs_dir,
246+
msg="git rev-parse HEAD failed for rerender curr commit",
247+
ignore_stderr=True,
248+
).strip()
249+
patch = _execute_git_cmds_and_report(
250+
cmds=[["git", "diff", prev_commit + ".." + curr_commit]],
251+
cwd=fs_dir,
252+
msg="git diff failed for rerender",
253+
ignore_stderr=True,
254+
)
219255
else:
256+
patch = None
220257
output_permissions = input_permissions
221258

222-
chmod_plus_rwX(input_fs_dir, recursive=True, skip_on_error=True)
223-
224-
return {"commit_message": msg, "permissions": output_permissions}
259+
return {
260+
"commit_message": msg,
261+
"patch": patch,
262+
"permissions": output_permissions,
263+
}
225264

226265

227266
def _parse_package_and_feedstock_names():

conda_forge_feedstock_ops/rerender.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,23 @@ def rerender_containerized(feedstock_dir, timeout=None):
113113
mount_dir=tmpdir,
114114
)
115115

116-
if data["commit_message"] is not None:
117-
sync_dirs(
118-
tmp_feedstock_dir,
119-
feedstock_dir,
120-
ignore_dot_git=True,
121-
update_git=True,
116+
if data["commit_message"] is not None and data["patch"] is not None:
117+
patch_file = os.path.join(
118+
tmpdir, f"rerender-diff-{os.path.basename(feedstock_dir)}.patch"
119+
)
120+
with open(patch_file, "w") as fp:
121+
fp.write(data["patch"])
122+
subprocess.run(
123+
["git", "apply", "--allow-empty", patch_file],
124+
check=True,
125+
cwd=feedstock_dir,
122126
)
123127
reset_permissions_with_user_execute(feedstock_dir, data["permissions"])
128+
subprocess.run(
129+
["git", "add", "."],
130+
check=True,
131+
cwd=feedstock_dir,
132+
)
124133

125134
# When tempfile removes tempdir, it tries to reset permissions on subdirs.
126135
# This causes a permission error since the subdirs were made by the user

0 commit comments

Comments
 (0)