This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
forked from nf-core/modules
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsync_with_upstream.py
executable file
·74 lines (64 loc) · 2.83 KB
/
sync_with_upstream.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
import argparse
import os
import subprocess
import sys
import tempfile
import tolit.slack
script_description = """
Script to merge the upstream nf-core 'master' branch onto our own nf-core-modules ('main' branch)
"""
# Define a cron job such as:
#30 2 * * * /bin/bash -cl 'env PYTHONPATH=$HOME/workspace/tol-it/lib /software/python-3.9.2/bin/python3 $HOME/workspace/tol-it/nextflow/modules/sync_with_upstream.py > workspace/tol-it/nextflow/modules/sync_with_upstream.cron.txt 2>&1'
GITHUB_SANGER_MODULES = '[email protected]:sanger-tol/nf-core-modules.git'
GITHUB_NFCORE_MODULES = '[email protected]:nf-core/modules.git'
SANGER_REMOTE_NAME = 'sanger'
NFCORE_REMOTE_NAME = 'upstream'
SANGER_BRANCH_NAME = 'main'
NFCORE_BRANCH_NAME = 'master'
# Run the command, and report failures to Slack
def run_and_check_command(args):
print("Running", args)
proc = subprocess.run(args, capture_output=True, text=True)
if proc.returncode:
msg_items = [f'The command `{" ".join(args)}` failed with return code {proc.returncode}']
if proc.stdout:
msg_items.extend([
'_stdout_:',
'```',
proc.stdout,
'```',
])
if proc.stderr:
msg_items.extend([
'_stderr_:',
'```',
proc.stderr,
'```',
])
tolit.slack.report_to_slack(os.environ["SLACK_WEBHOOK_PERSO"], "\n".join(msg_items))
sys.exit(1)
else:
print("OK")
print(proc.stdout)
def main():
# No parameters are exposed. Only a dry-run option for testing
parser = argparse.ArgumentParser(description=script_description)
parser.add_argument('-n', '--dry-run', action='store_true')
args = parser.parse_args()
# Work in an isolated directory
with tempfile.TemporaryDirectory() as tmpdirname:
# A bunch of commands we run one after the other
run_and_check_command(["git", "clone", "-o", SANGER_REMOTE_NAME, "-b", SANGER_BRANCH_NAME, GITHUB_SANGER_MODULES, tmpdirname])
os.chdir(tmpdirname)
run_and_check_command(["git", "remote", "add", NFCORE_REMOTE_NAME, GITHUB_NFCORE_MODULES])
run_and_check_command(["git", "fetch", NFCORE_REMOTE_NAME])
run_and_check_command(["git", "merge", "--no-edit", f"{NFCORE_REMOTE_NAME}/{NFCORE_BRANCH_NAME}"])
if args.dry_run:
run_and_check_command(["git", "push", "-n", SANGER_REMOTE_NAME])
run_and_check_command(["git", "push", "-n", SANGER_REMOTE_NAME, f"{NFCORE_REMOTE_NAME}/{NFCORE_BRANCH_NAME}:nf-core_master"])
else:
run_and_check_command(["git", "push", SANGER_REMOTE_NAME])
run_and_check_command(["git", "push", SANGER_REMOTE_NAME, f"{NFCORE_REMOTE_NAME}/{NFCORE_BRANCH_NAME}:nf-core_master"])
if __name__ == "__main__":
main()