From f124de87bfbd8575a06c6a9eeb332f3375ad2441 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 22 Jun 2024 16:59:12 -0400 Subject: [PATCH] build: no longer download kits to upload them --- Makefile | 9 +-- ci/download_gha_artifacts.py | 110 ----------------------------------- howto.txt | 6 +- 3 files changed, 3 insertions(+), 122 deletions(-) delete mode 100644 ci/download_gha_artifacts.py diff --git a/Makefile b/Makefile index c1a7bde7a..ac2433fdc 100644 --- a/Makefile +++ b/Makefile @@ -177,7 +177,7 @@ sample_html_beta: _sample_cog_html ## Generate sample HTML report for a beta rel ##@ Kitting: making releases .PHONY: edit_for_release cheats relbranch relcommit1 relcommit2 -.PHONY: kit kit_upload test_upload kit_local build_kits download_kits check_kits +.PHONY: kit kit_upload test_upload kit_local build_kits .PHONY: tag bump_version REPO_OWNER = nedbat/coveragepy @@ -219,13 +219,6 @@ kit_local: build_kits: ## Trigger GitHub to build kits python ci/trigger_action.py $(REPO_OWNER) build-kits -download_kits: ## Download the built kits from GitHub. - python ci/download_gha_artifacts.py $(REPO_OWNER) 'dist-*' dist - -check_kits: ## Check that dist/* are well-formed. - python -m twine check dist/* - @echo $$(ls -1 dist | wc -l) distribution kits - tag: #: Make a git tag with the version number (see howto.txt). git tag -s -m "Version $$(python setup.py --version)" $$(python setup.py --version) git push --follow-tags diff --git a/ci/download_gha_artifacts.py b/ci/download_gha_artifacts.py deleted file mode 100644 index e656b6d2e..000000000 --- a/ci/download_gha_artifacts.py +++ /dev/null @@ -1,110 +0,0 @@ -# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 -# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt - -"""Use the GitHub API to download built artifacts.""" - -import collections -import datetime -import fnmatch -import operator -import os -import os.path -import sys -import time -import zipfile - -from session import get_session - -def download_url(url, filename): - """Download a file from `url` to `filename`.""" - response = get_session().get(url, stream=True) - if response.status_code == 200: - with open(filename, "wb") as f: - for chunk in response.iter_content(16*1024): - f.write(chunk) - else: - raise RuntimeError(f"Fetching {url} produced: status={response.status_code}") - - -def unpack_zipfile(filename): - """Unpack a zipfile, using the names in the zip.""" - with open(filename, "rb") as fzip: - z = zipfile.ZipFile(fzip) - for name in z.namelist(): - print(f" extracting {name}") - z.extract(name) - - -def utc2local(timestring): - """ - Convert a UTC time into local time in a more readable form. - - For example: '20201208T122900Z' to '2020-12-08 07:29:00'. - - """ - dt = datetime.datetime - utc = dt.fromisoformat(timestring.rstrip("Z")) - epoch = time.mktime(utc.timetuple()) - offset = dt.fromtimestamp(epoch) - dt.utcfromtimestamp(epoch) - local = utc + offset - return local.strftime("%Y-%m-%d %H:%M:%S") - - -def all_items(url, key): - """ - Get all items from a paginated GitHub URL. - - `key` is the key in the top-level returned object that has a list of items. - - """ - url += ("&" if "?" in url else "?") + "per_page=100" - while url: - response = get_session().get(url) - response.raise_for_status() - data = response.json() - if isinstance(data, dict) and (msg := data.get("message")): - raise RuntimeError(f"URL {url!r} failed: {msg}") - yield from data.get(key, ()) - try: - url = response.links.get("next").get("url") - except AttributeError: - url = None - - -def main(owner_repo, artifact_pattern, dest_dir): - """ - Download and unzip the latest artifacts matching a pattern. - - `owner_repo` is a GitHub pair for the repo, like "nedbat/coveragepy". - `artifact_pattern` is a filename glob for the artifact name. - `dest_dir` is the directory to unpack them into. - - """ - # Get all artifacts matching the pattern, grouped by name. - url = f"https://api.github.com/repos/{owner_repo}/actions/artifacts" - artifacts_by_name = collections.defaultdict(list) - for artifact in all_items(url, "artifacts"): - name = artifact["name"] - if not fnmatch.fnmatch(name, artifact_pattern): - continue - artifacts_by_name[name].append(artifact) - - os.makedirs(dest_dir, exist_ok=True) - os.chdir(dest_dir) - temp_zip = "artifacts.zip" - - # Download the latest of each name. - for name, artifacts in artifacts_by_name.items(): - artifact = max(artifacts, key=operator.itemgetter("created_at")) - print( - f"Downloading {artifact['name']}, " - + f"size: {artifact['size_in_bytes']}, " - + f"created: {utc2local(artifact['created_at'])}", - ) - download_url(artifact["archive_download_url"], temp_zip) - unpack_zipfile(temp_zip) - os.remove(temp_zip) - - -if __name__ == "__main__": - sys.exit(main(*sys.argv[1:])) diff --git a/howto.txt b/howto.txt index dfaf15456..e540f6355 100644 --- a/howto.txt +++ b/howto.txt @@ -52,15 +52,13 @@ - Kits: - Wait for kits to finish: - https://github.com/nedbat/coveragepy/actions/workflows/kit.yml - - Download and check built kits from GitHub Actions: - $ make clean download_kits check_kits - there should be 52 - - examine the dist directory, and remove anything that looks malformed. - - opvars - test the pypi upload: $ make test_upload + - you'll need to approve the action - upload kits: $ make kit_upload + - you'll need to approve the action - Tag the tree $ make tag - Update GitHub releases: