Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Use a single action to generate and tag the manifest.
Browse files Browse the repository at this point in the history
This cuts down on quota usage. Also apply filters before the manifest
generation so we cut down on unnecessary work in PRs and return the
magic status 78 in cases where the filter doesn't match so if we expand
to multiple actions in the future things work correctly.
  • Loading branch information
jgraham committed Apr 1, 2019
1 parent bfb65bf commit 3e0d33a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 41 deletions.
12 changes: 3 additions & 9 deletions .github/main.workflow
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
workflow "Build & Release Manifest" {
on = "push"
resolves = ["tag-master"]
resolves = ["manifest-build-and-tag"]
}

action "build-manifest" {
action "manifest-build-and-tag" {
uses = "./tools/docker/github"
runs = ["bash", "-c", "tools/ci/action_manifest_build.sh"]
}

action "tag-master" {
needs = "build-manifest"
uses = "./tools/docker/github"
runs = ["python", "tools/ci/tag_master.py"]
runs = ["python", "tools/ci/manifest_build.py"]
secrets = ["GITHUB_TOKEN"]
}
11 changes: 0 additions & 11 deletions tools/ci/action_manifest_build.sh

This file was deleted.

14 changes: 0 additions & 14 deletions tools/ci/ci_manifest.sh

This file was deleted.

53 changes: 46 additions & 7 deletions tools/ci/tag_master.py → tools/ci/manifest_build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
import os
import subprocess
import sys

import requests
Expand All @@ -17,6 +18,32 @@
logger = logging.getLogger(__name__)


class Status(object):
SUCCESS = 0
FAIL = 1
NEUTRAL = 78


def run(cmd, return_stdout=False, **kwargs):
print(" ".join(cmd))
if return_stdout:
f = subprocess.check_output
else:
f = subprocess.check_call
return f(cmd, **kwargs)


def create_manifest(path):
run(["./wpt", "manifest", "-p", path])


def compress_manifest(path):
for args in [["gzip", "-k", "-f", "--best"],
["bzip2", "-k", "-f", "--best"],
["zstd", "-k", "-f", "--ultra", "-22"]]:
run(args + [path])


def request(url, desc, data=None, json_data=None, params=None, headers=None):
github_token = os.environ.get("GITHUB_TOKEN")
default_headers = {
Expand Down Expand Up @@ -92,7 +119,7 @@ def tag(owner, repo, sha, tag):
return True


def create_release(owner, repo, sha, tag, summary, body):
def create_release(manifest_path, owner, repo, sha, tag, summary, body):
if body:
body = "%s\n%s" % (summary, body)
else:
Expand All @@ -117,7 +144,7 @@ def create_release(owner, repo, sha, tag, summary, body):
params = {"name": upload_filename,
"label": "MANIFEST.json%s" % upload_ext}

with open(os.path.expanduser("~/meta/MANIFEST.json%s" % upload_ext), "rb") as f:
with open("%s%s" % (manifest_path, upload_ext), "rb") as f:
upload_data = f.read()

logger.info("Uploading %s bytes" % len(upload_data))
Expand Down Expand Up @@ -148,7 +175,7 @@ def main():
repo_key = "GITHUB_REPOSITORY"

if not should_run_action():
return
return Status.NEUTRAL

owner, repo = os.environ[repo_key].split("/", 1)

Expand All @@ -162,16 +189,28 @@ def main():
else:
tag_name = "merge_pr_%s" % pr

manifest_path = os.path.expanduser(os.path.join("~", "meta", "MANIFEST.json"))

os.makedirs(os.path.dirname(manifest_path))

create_manifest(manifest_path)

compress_manifest(manifest_path)

tagged = tag(owner, repo, head_rev, tag_name)
if not tagged:
sys.exit(1)
return Status.FAIL

summary = git("show", "--no-patch", '--format="%s"', "HEAD")
body = git("show", "--no-patch", '--format="%b"', "HEAD")

if not create_release(owner, repo, head_rev, tag_name, summary, body):
sys.exit(1)
if not create_release(manifest_path, owner, repo, head_rev, tag_name, summary, body):
return Status.FAIL

return Status.SUCCESS


if __name__ == "__main__":
main()
code = main()
assert isinstance(code, int)
sys.exit(code)

0 comments on commit 3e0d33a

Please sign in to comment.