in asfyaml/feature/website_publish.py [0:0]
def run(self):
"""Publishing for websites. Sample entry .asf.yaml entry:
publish:
whoami: asf-site
# would publish current branch (if asf-site) at https://$project.apache.org/
subdir: optional subdirectory to publish from
type: website|blog (default website)
hostname: optional override; must be events.apache.org or a non-ASF host
"""
# Get optional target hostname:
hostname = self.yaml.hostname if "hostname" in self.yaml else None
if hostname and "apache.org" in hostname:
if mappings.WS_HOSTNAME_OVERRIDES.get(self.repository.name, "") != hostname:
raise Exception(
f".asf.yaml: Invalid hostname '{hostname}' - you cannot specify *.apache.org hostnames, they must be inferred!"
)
elif not hostname: # Infer hostname if not supplied.
hostname = f"{self.repository.hostname}.apache.org"
# If whoami specified, ignore this payload if branch does not match
whoami = self.yaml.get("whoami")
if whoami and whoami != self.instance.branch:
return
subdir = self.yaml.get("subdir")
if subdir:
validate_subdir(subdir)
# Determine deployment type (website or blog?)
deploy_type = self.yaml.get("type", "website")
if deploy_type not in ("website", "blog"):
raise Exception(f".asf.yaml: Invalid deployment type '{deploy_type}' - must be either 'website' or 'blog'!")
print(f"Publishing contents at https://{self.repository.hostname}.apache.org/ ...")
# If in NO-OP mode, we shouldn't actually try to stage anything.
if not self.noop("publish"):
# Try sending publish payload to pubsub
try:
payload = {
"publish": {
"project": self.repository.project,
"subdir": subdir,
"source": "https://gitbox.apache.org/repos/asf/%s.git" % self.repository.name,
"branch": self.instance.branch,
"pusher": self.committer.username,
"target": hostname,
"type": deploy_type,
}
}
# Send to pubsub.a.o
requests.post(f"https://pubsub.apache.org:2070/publish/{self.repository.project}", json=payload)
except Exception as e:
print(e)