3
3
import re
4
4
5
5
from aiohttp import ClientSession
6
+ from typing import List , Tuple
6
7
from yaml import safe_load
7
8
8
9
from .common import (
24
25
# Given a PR and commit sha, post a comment with any artifacts
25
26
async def make_artifact_comment (session : ClientSession , pr : int , sha : str ) -> None :
26
27
artifacts = await fetch_pr_sha_artifacts (session , pr , sha )
28
+
29
+ comment = compose_azure_comment (artifacts ["azure" ] if "azure" in artifacts else [])
30
+ if len (comment ) > 0 :
31
+ comment += "\n \n "
32
+ comment += compose_circlci_comment (artifacts ["circleci" ] if "circleci" in artifacts else [])
33
+
34
+ await send_comment (session , pr , comment )
35
+
36
+ def compose_azure_comment (artifacts : List [Tuple [str , str ]]) -> str :
27
37
nPackages = len (artifacts )
38
+ comment = "## Azure\n \n "
28
39
29
40
if nPackages > 0 :
30
- comment = "Package(s) built on Azure are ready for inspection:\n \n "
41
+ comment + = "Package(s) built on Azure are ready for inspection:\n \n "
31
42
comment += "Arch | Package | Zip File\n -----|---------|---------\n "
32
- install_noarch = ""
33
- install_linux = ""
34
- install_osx = ""
35
43
36
- # Table of packages and repodata.json
44
+ # Table of packages and zips
37
45
for URL , artifact in artifacts :
38
46
if not (package_match := re .match (r"^((.+)\/(.+)\/(.+)\/(.+\.tar\.bz2))$" , artifact )):
39
47
continue
@@ -61,9 +69,9 @@ async def make_artifact_comment(session: ClientSession, pr: int, sha: str) -> No
61
69
comment += "```\n conda install -c ./packages <package name>\n ```\n "
62
70
63
71
# Table of containers
64
- comment + = "***\n \n Docker image(s) built (images are in the LinuxArtifacts zip file above):\n \n "
65
- comment += "Package | Tag | Install with `docker`\n "
66
- comment += "--------|-----|----------------------\n "
72
+ imageHeader = "***\n \n Docker image(s) built (images for Azure are in the LinuxArtifacts zip file above):\n \n "
73
+ imageHeader += "Package | Tag | Install with `docker`\n "
74
+ imageHeader += "--------|-----|----------------------\n "
67
75
68
76
for URL , artifact in artifacts :
69
77
if artifact .endswith (".tar.gz" ):
@@ -72,18 +80,68 @@ async def make_artifact_comment(session: ClientSession, pr: int, sha: str) -> No
72
80
package_name , tag = image_name .split (':' , 1 )
73
81
#image_url = URL[:-3] # trim off zip from format=
74
82
#image_url += "file&subPath=%2F{}.tar.gz".format("%2F".join(["images", '%3A'.join([package_name, tag])]))
83
+ comment += imageHeader
84
+ imageHeader = "" # only add the header for the first image
75
85
comment += f"{ package_name } | { tag } | "
76
86
comment += f'<details><summary>show</summary>`gzip -dc LinuxArtifacts/images/{ image_name } .tar.gz \\ | docker load`\n '
77
87
comment += "\n \n "
78
88
else :
79
- comment = (
89
+ comment + = (
80
90
"No artifacts found on the most recent Azure build. "
81
- "Either the build failed, the artifacts have were removed due to age, or the recipe was blacklisted/skipped."
91
+ "Either the build failed, the artifacts have been removed due to age, or the recipe was blacklisted/skipped."
82
92
)
83
- await send_comment ( session , pr , comment )
93
+ return comment
84
94
95
+ def compose_circlci_comment (artifacts : List [Tuple [str , str ]]) -> str :
96
+ nPackages = len (artifacts )
85
97
86
- # Post a comment on a given PR with its CircleCI artifacts
98
+ if nPackages < 1 :
99
+ return ""
100
+
101
+ comment = "## CircleCI\n \n "
102
+ comment += "Package(s) built on CircleCI are ready for inspection:\n \n "
103
+ comment += "Arch | Package | Repodata\n -----|---------|---------\n "
104
+
105
+ # Table of packages and repodata.json
106
+ for URL , artifact in artifacts :
107
+ if not (package_match := re .match (r"^((.+)\/(.+)\/(.+\.tar\.bz2))$" , URL )):
108
+ continue
109
+ url , basedir , subdir , packageName = package_match .groups ()
110
+ repo_url = "/" .join ([basedir , subdir , "repodata.json" ])
111
+ conda_install_url = basedir
112
+
113
+ if subdir == "noarch" :
114
+ comment += "noarch |"
115
+ elif subdir == "linux-64" :
116
+ comment += "linux-64 |"
117
+ elif subdir == "linux-aarch64" :
118
+ comment += "linux-aarch64 |"
119
+ else :
120
+ comment += "osx-64 |"
121
+ comment += f" [{ packageName } ]({ URL } ) | [repodata.json]({ repo_url } )\n "
122
+
123
+ # Conda install examples
124
+ comment += "***\n \n You may also use `conda` to install these:\n \n "
125
+ comment += f"```\n conda install -c { conda_install_url } <package name>\n ```\n "
126
+
127
+ # Table of containers
128
+ imageHeader = "***\n \n Docker image(s) built:\n \n "
129
+ imageHeader += "Package | Tag | Install with `docker`\n "
130
+ imageHeader += "--------|-----|----------------------\n "
131
+
132
+ for URL , artifact in artifacts :
133
+ if artifact .endswith (".tar.gz" ):
134
+ image_name = artifact .split ("/" ).pop ()[: - len (".tar.gz" )]
135
+ if ":" in image_name :
136
+ package_name , tag = image_name .split (":" , 1 )
137
+ comment += imageHeader
138
+ imageHeader = "" # only add the header for the first image
139
+ comment += f"[{ package_name } ]({ URL } ) | { tag } | "
140
+ comment += f'<details><summary>show</summary>`curl -L "{ URL } " \\ | gzip -dc \\ | docker load`</details>\n '
141
+ comment += "</details>\n "
142
+ return comment
143
+
144
+ # Post a comment on a given PR with its artifacts
87
145
async def artifact_checker (session : ClientSession , issue_number : int ) -> None :
88
146
url = f"https://api.github.com/repos/bioconda/bioconda-recipes/pulls/{ issue_number } "
89
147
headers = {
0 commit comments