ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
deploy_tag.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file deploy_tag.py
1 #!/usr/bin/env python3
2 import argparse
3 import os
4 import fs
5 from fs.osfs import OSFS
6 from markdown import markdown as mdlib
7 import textwrap
8 import json
9 
10 from util import smtp, def_arguments, get_lxplus_fs, Spinner, gitlab
11 from release_notes import collect_milestone, make_release_notes, parse_version
12 
13 sender_email = "Acts Bot <atsjenkins@cern.ch>"
14 receiver_email = os.getenv("TAG_DEPLOY_EMAIL_RECEIVERS")
15 
16 from email.mime.text import MIMEText
17 from email.mime.multipart import MIMEMultipart
18 
19 
20 def markdown(md):
21  return mdlib(md, extensions=["pymdownx.extra"])
22 
23 
24 def main():
25  p = argparse.ArgumentParser()
26  p = def_arguments(p, acc=True, gl=True)
27 
28  p.add_argument("--doc-source", required=True)
29  p.add_argument("--dry-run", action="store_true")
30  p.add_argument(
31  "--ref", default=os.getenv("CI_COMMIT_REF_NAME", None), required=True
32  )
33  p.add_argument(
34  "--doc-root",
35  default=os.getenv("DOC_WEBSITE_ROOT", "/eos/user/a/atsjenkins/www/ACTS/"),
36  )
37  p.add_argument(
38  "--doc-public-url",
39  default=os.getenv("DOC_WEBSITE_URL", "https://acts.web.cern.ch/ACTS/"),
40  )
41 
42  args = p.parse_args()
43 
44  src_fs = OSFS(os.path.abspath(args.doc_source))
45 
46  www_fs = get_lxplus_fs(args).opendir(os.path.join(args.doc_root))
47 
48  if not www_fs.exists(args.ref):
49  www_fs.makedirs(os.path.join(args.ref, "doc"))
50  refdir = www_fs.opendir(os.path.join(args.ref, "doc"))
51 
52  # refdir = OSFS("/tmp/doctest")
53 
54  print(
55  os.path.abspath(args.doc_source),
56  "->",
57  os.path.join(args.doc_root, args.ref, "doc"),
58  )
59  with Spinner(f"Publishing doc for {args.ref}"):
60  if not args.dry_run:
61  fs.copy.copy_dir(src_fs, ".", refdir, ".")
62 
63  doc_url = os.path.join(args.doc_public_url, args.ref, "doc")
64  print("Doc is available at", doc_url)
65 
66  # write tag info json file
67  if not args.dry_run:
68  with www_fs.open("latest_release.json", "w") as f:
69  json.dump({"subject": "release", "status": args.ref, "color": "yellow"}, f)
70 
71  gl = gitlab(args)
72  project = gl.projects.get("acts/acts-core")
73 
74  version = parse_version(args.ref)
75  with Spinner(text="Loading milestone"):
76  milestones = project.milestones.list(all=True)
77  milestone = None
78  for ms in milestones:
79  if ms.title == version:
80  milestone = ms
81  break
82 
83  relnotes = make_release_notes(milestone, *collect_milestone(milestone))
84 
85  message = MIMEMultipart("alternative")
86  message["Subject"] = f"New Acts release: {args.ref}"
87  message["From"] = sender_email
88  message["To"] = receiver_email
89 
90  text = """
91  Dear Acts enthusiasts,
92 
93  a new tag '{ref}' of the Acts project has been created.
94 
95  You can get the source code from git using:
96 
97  git clone https://gitlab.cern.ch/acts/acts-core.git
98  cd acts-core/
99  git checkout {ref}
100 
101  or download a tarball with the source from
102 
103  https://gitlab.cern.ch/acts/acts-core/-/archive/{ref}/acts-core-{ref}.tar.gz
104 
105  The documentation is deployed at
106  https://acts.web.cern.ch/ACTS/{ref}/doc/index.html
107 
108  Cheers,
109  your friendly Acts robot
110  """
111  text = textwrap.dedent(text).format(ref=args.ref, relnotes=relnotes)
112 
113  md = """
114  Dear Acts enthusiasts,
115 
116  a new tag of the Acts project has been created.
117 
118  ---
119 
120  # {ref}
121  [![](https://badgen.net/badge/release/{ref}/yellow)](https://gitlab.cern.ch/acts/acts-core/tags/{ref})
122  {relnotes}
123 
124  ---
125 
126  You can get the source code from git using:
127 
128  ```bash
129  git clone https://gitlab.cern.ch/acts/acts-core.git
130  cd acts-core/
131  git checkout {ref}
132  ```
133 
134  or download a tarball with the source from
135 
136  https://gitlab.cern.ch/acts/acts-core/-/archive/{ref}/acts-core-{ref}.tar.gz
137 
138  The documentation is deployed at
139 
140  https://acts.web.cern.ch/ACTS/{ref}/doc/index.html
141 
142  Cheers,<br/>
143  your friendly Acts robot
144  """
145 
146  md = textwrap.dedent(md).format(ref=args.ref, relnotes=relnotes)
147 
148  html = """\
149  <html>
150  <body>
151  {text}
152  </body>
153  </html>
154  """.format(
155  text=markdown(textwrap.dedent(md))
156  )
157 
158  # print(html)
159 
160  part1 = MIMEText(text, "plain")
161  part2 = MIMEText(html, "html")
162 
163  message.attach(part1)
164  message.attach(part2)
165 
166  with Spinner("Sending email"):
167  if not args.dry_run:
168  with smtp(args) as server:
169  server.sendmail(sender_email, receiver_email, message.as_string())
170 
171 
172 if "__main__" == __name__:
173  main()