Skip to content

Commit

Permalink
Add time-created info to download_gha_artifacts.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Dec 8, 2020
1 parent 215996b commit 29e3241
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ci/download_gha_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

"""Use the GitHub API to download built artifacts."""

import datetime
import os
import os.path
import time
import zipfile

import requests
Expand All @@ -25,6 +27,14 @@ def unpack_zipfile(filename):
print(f" extracting {name}")
z.extract(name)

def utc2local(timestring):
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")

dest = "dist"
repo_owner = "nedbat/coveragepy"
temp_zip = "artifacts.zip"
Expand All @@ -35,6 +45,8 @@ def unpack_zipfile(filename):

r = requests.get(f"https://api.github.com/repos/{repo_owner}/actions/artifacts")
latest = max(r.json()["artifacts"], key=lambda a: a["created_at"])

print(f"Artifacts created at {utc2local(latest['created_at'])}")
download_url(latest["archive_download_url"], temp_zip)
unpack_zipfile(temp_zip)
os.remove(temp_zip)

0 comments on commit 29e3241

Please sign in to comment.