Skip to content

Commit 1e481b9

Browse files
Fix rsync and add cwd to all commands
1 parent b11a882 commit 1e481b9

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

main.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,20 @@ def sync_website_content(
8888
email : str
8989
Email of the bot account.
9090
"""
91-
base_folder = Path(os.getcwd())
92-
source_folder_path = base_folder / source_folder
93-
translations_folder_path = base_folder / translations_folder
91+
base_path = Path(os.getcwd())
92+
base_source_path = base_path / source_repo.split("/")[-1]
93+
source_path = base_path / source_folder
94+
base_translations_path = base_path / translations_repo.split("/")[-1]
95+
translations_path = base_path / translations_folder
96+
9497
print(
9598
"\n\n### Syncing content from source repository to translations repository.\n\n"
9699
)
97-
print("Base folder: ", base_folder)
98-
print("Source folder: ", source_folder_path)
99-
print("Translation folder: ", translations_folder_path)
100+
print("\nBase path: ", base_path)
101+
print("\nBase source path: ", base_source_path)
102+
print("\nSource path: ", source_path)
103+
print("\nBase translations path: ", base_translations_path)
104+
print("\nTranslations path: ", translations_path)
100105

101106
run(["git", "config", "--global", "user.name", f'"{name}"'])
102107
run(["git", "config", "--global", "user.email", f'"{email}"'])
@@ -139,26 +144,27 @@ def sync_website_content(
139144
date_time = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
140145
branch_name = f"content-sync-{date_time}"
141146

142-
# FIXME: If on the same level do this, otherwise no parent?
143-
if source_folder_path.name == translations_folder_path.name:
144-
dest = str(translations_folder_path.parent)
147+
if source_path.name == translations_path.name:
148+
dest = str(translations_path.parent)
145149
else:
146-
dest = str(translations_folder_path)
150+
dest = str(translations_path)
147151

148-
run(["rsync", "-avr", "--delete", str(source_folder_path), dest])
149-
run(["git", "status"], cwd=translations_folder_path)
150-
run(["git", "add", "."], cwd=translations_folder_path)
151-
_out, _err, rc = run(["git", "diff", "--staged", "--quiet"])
152+
run(["rsync", "-avr", "--delete", str(source_path), dest])
153+
run(["git", "status"], cwd=base_translations_path)
154+
run(["git", "add", "."], cwd=base_translations_path)
155+
_out, _err, rc = run(
156+
["git", "diff", "--staged", "--quiet"], cwd=base_translations_path
157+
)
152158

153159
pr_title = "Update content"
154160
github_token = os.environ.get("GITHUB_TOKEN", "")
155161
if rc:
156162
run(
157163
["git", "commit", "-S", "-m", "Update content."],
158-
cwd=translations_folder_path,
164+
cwd=base_translations_path,
159165
)
160-
run(["git", "remote", "-v"], cwd=translations_folder_path)
161-
run(["git", "push", "-u", "origin", branch_name], cwd=translations_folder_path)
166+
run(["git", "remote", "-v"], cwd=base_translations_path)
167+
run(["git", "push", "-u", "origin", branch_name], cwd=base_translations_path)
162168

163169
os.environ["GITHUB_TOKEN"] = token
164170
run(
@@ -175,7 +181,7 @@ def sync_website_content(
175181
"--body",
176182
"Automated content update.",
177183
],
178-
cwd=translations_folder_path,
184+
cwd=base_translations_path,
179185
)
180186
os.environ["GITHUB_TOKEN"] = github_token
181187

@@ -220,7 +226,7 @@ def sync_website_content(
220226
"--squash",
221227
"--delete-branch",
222228
],
223-
cwd=translations_folder_path,
229+
cwd=base_translations_path,
224230
)
225231
else:
226232
print("\n\nNot all commits are signed, abort merge!")

0 commit comments

Comments
 (0)