diff --git a/.github/main.workflow b/.github/main.workflow index b1b61554f9..4ff7845b9d 100644 --- a/.github/main.workflow +++ b/.github/main.workflow @@ -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"] } diff --git a/tools/ci/action_manifest_build.sh b/tools/ci/action_manifest_build.sh deleted file mode 100755 index ad6a4cb16e..0000000000 --- a/tools/ci/action_manifest_build.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -set -ex - -mkdir -p ~/meta - -WPT_MANIFEST_FILE=~/meta/MANIFEST.json - -./wpt manifest -p $WPT_MANIFEST_FILE -gzip -k -f --best $WPT_MANIFEST_FILE -bzip2 -k -f --best $WPT_MANIFEST_FILE -zstd -k -f --ultra -22 $WPT_MANIFEST_FILE diff --git a/tools/ci/ci_manifest.sh b/tools/ci/ci_manifest.sh deleted file mode 100755 index 7d0d5ca041..0000000000 --- a/tools/ci/ci_manifest.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -set -ex - -SCRIPT_DIR=$(cd $(dirname "$0") && pwd -P) -WPT_ROOT=$SCRIPT_DIR/../.. -cd $WPT_ROOT - -mkdir -p ~/meta - -python tools/ci/tag_master.py -./wpt manifest -p ~/meta/MANIFEST.json -cp ~/meta/MANIFEST.json $WPT_MANIFEST_FILE -# Force overwrite of any existing file -gzip -f $WPT_MANIFEST_FILE diff --git a/tools/ci/tag_master.py b/tools/ci/manifest_build.py similarity index 79% rename from tools/ci/tag_master.py rename to tools/ci/manifest_build.py index d672d13fe2..43cfb55f20 100644 --- a/tools/ci/tag_master.py +++ b/tools/ci/manifest_build.py @@ -1,6 +1,7 @@ import json import logging import os +import subprocess import sys import requests @@ -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 = { @@ -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: @@ -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)) @@ -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) @@ -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)