Last active
November 11, 2024 22:08
-
-
Save FrostyX/13fdf75cdab40087087f0f22bb45fef7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
""" | |
Deployment script for Fedora Packager Sponsors page | |
Upstream: https://github.com/FrostyX/fedora-sponsors | |
Instance: https://docs.pagure.org/fedora-sponsors/ | |
First authenticate to kerberos | |
fkinit -u frostyx | |
And then run this script. | |
""" | |
import os | |
import shutil | |
import subprocess | |
from tempfile import mkdtemp | |
from bs4 import BeautifulSoup | |
def run(cmd, cwd=None): | |
""" | |
In this script, we often run shell commands. This wrapper is to make the | |
calls as simple as possible. | |
""" | |
return subprocess.run(cmd, check=True, cwd=cwd) | |
def git_clone(workdir): | |
""" | |
Clone the up-to-date upstream sources to this machine | |
""" | |
url = "https://github.com/FrostyX/fedora-sponsors.git" | |
run(["git", "clone", url, workdir]) | |
return workdir | |
def build(workdir): | |
""" | |
Obtain all third-party information and compile the site to its functional | |
and deployable state | |
""" | |
run(["make", "activity"], cwd=workdir) | |
run(["make", "groups"], cwd=workdir) | |
run(["make", "build"], cwd=workdir) | |
def check(workdir): | |
""" | |
Make sure we built the page correctly and that it displays all the expected | |
information and sections. | |
This function should be called on a fully-built site but **before** | |
deploying it into production. | |
""" | |
# Test that we successfully generated the page with all sponsors | |
classes = ["sponsor", "card"] | |
path = os.path.join(workdir, "_build/production/all/index.html") | |
soup = _parse_html_for_check(path) | |
sponsors = soup.body.find_all("div", attrs={"class": classes}) | |
assert len(sponsors) > 100 | |
# Test that some of those sponsors are not active | |
inactive = [x for x in sponsors if "muted" in x.attrs["class"]] | |
assert len(inactive) > 30 | |
assert len(inactive) < 150 | |
# Test that we successfully generated the page with active sponsors | |
path = os.path.join(workdir, "_build/production/active/index.html") | |
soup = _parse_html_for_check(path) | |
active = soup.body.find_all("div", attrs={"class": classes}) | |
assert len(active) > 20 | |
assert len(active) + len(inactive) == len(sponsors) | |
# Test that we successfully generated the page with sponsors divided by | |
# their groups of interests | |
path = os.path.join(workdir, "_build/production/interests/index.html") | |
soup = _parse_html_for_check(path) | |
toc = soup.body.find("ul", attrs={"id": "toc"}).find_all("li") | |
assert len(toc) > 30 | |
headings = soup.body.find_all("h2") | |
assert len(headings) == len(toc) | |
sponsors = soup.body.find_all("div", attrs={"class": classes}) | |
assert len(sponsors) > 50 | |
# Test that we successfully generated the page with sponsors divided by | |
# their native languages | |
path = os.path.join(workdir, "_build/production/languages/index.html") | |
soup = _parse_html_for_check(path) | |
toc = soup.body.find("ul", attrs={"id": "toc"}).find_all("li") | |
assert len(toc) > 10 | |
headings = soup.body.find_all("h2") | |
assert len(headings) == len(toc) | |
sponsors = soup.body.find_all("div", attrs={"class": classes}) | |
assert len(sponsors) > 30 | |
def _parse_html_for_check(path): | |
with open(path, "r") as html: | |
return BeautifulSoup(html, "html.parser") | |
def deploy(workdir): | |
""" | |
Deploy a locally built site to production | |
""" | |
run(["make", "deploy"], cwd=workdir) | |
def clean(workdir): | |
""" | |
Remove all the temporary files and directories that this script generated | |
as a byproduct of deploying the site. | |
""" | |
shutil.rmtree(workdir) | |
def main(): | |
""" | |
Clone, build, verify, and deploy the Fedora Sponsors site | |
""" | |
workdir = mkdtemp(prefix="fedora-sponsors-") | |
print("Building in: {0}".format(workdir)) | |
git_clone(workdir) | |
build(workdir) | |
check(workdir) | |
deploy(workdir) | |
clean(workdir) | |
instance = "https://docs.pagure.org/fedora-sponsors/" | |
print("Successfully built: {0}".format(instance)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment