def create_latest(bucket, sha, target): """Create a file in GCS with information about the latest release. Args: bucket: A google cloud storage bucket object sha: SHA of the release we just created target: The GCS path of the release we just produced. """ path = os.path.join("latest_release.json") logging.info("Creating GCS output: %s", util.to_gcs_uri(bucket.name, path)) data = { "sha": sha.strip(), "target": target, } blob = bucket.blob(path) blob.upload_from_string(json.dumps(data))
def get_last_release(bucket): """Return the sha of the last release. Args: bucket: A google cloud storage bucket object Returns: sha: The sha of the latest release. """ path = "latest_release.json" blob = bucket.blob(path) if not blob.exists(): logging.info("File %s doesn't exist.", util.to_gcs_uri(bucket.name, path)) return "" contents = blob.download_as_string() data = json.loads(contents) return data.get("sha", "").strip()