diff --git a/Dockerfile b/Dockerfile index 836b0f8..dcc2146 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,5 @@ FROM python:3.7.6-alpine3.11 -RUN apk add --update gnuplot \ - fontconfig \ - ttf-ubuntu-font-family \ - msttcorefonts-installer \ - curl && \ - update-ms-fonts && \ - fc-cache -f && \ - rm -rf /var/cache/apk/* - -RUN curl -L https://github.com/sile/kurobako/releases/download/0.1.4/kurobako-0.1.4.linux-amd64 -o kurobako && \ - chmod +x ./kurobako && \ - ./kurobako -h - RUN pip install PyGithub COPY entrypoint.sh /entrypoint.sh diff --git a/README.md b/README.md index 4217e6d..9a37df9 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,28 @@ # github-actions-kurobako GitHub Action to report [kurobako](https://github.com/sile/kurobako) benchmark results on the PR. +See [github-actions-kurobako/plot](./plot) action to generate a plot image. ## Inputs -### `report-json-path` +### `report-md-path` -**Required** File path to a json generated by kurobako run command. Default `"./kurobako.json"`. +**Required** File path to a json generated by kurobako report command. -## Outputs - -### `image-path` +### `public-image-url` -A file path to the generated image of kurobako. -You need to upload this on GCS. +**Required** A public image url to kurobako plot image. -### `public-image-url` +## Outputs -URL to kurobako plot curve image which you upload later. +Comment to the pull request or edit if previous comment exists. ## Example usage ```yaml uses: c-bata/github-actions-kurobako@master with: - report-json-path: '/home/runner/kurobako-report.json' + report-md-path: './kurobako-report.md' public-image-url: 'https://storage.googleapis.com/kurobako-reports/foo.png' ``` diff --git a/action.yml b/action.yml index 7c64e77..3180588 100644 --- a/action.yml +++ b/action.yml @@ -1,14 +1,14 @@ -name: 'Kurobako' -description: 'GitHub Action to report kurobako benchmark results on the PR.' +name: 'Kurobako Report' +description: 'GitHub Action to comment kurobako benchmark results on the pull request.' inputs: - report-json-path: - description: 'File path to a json generated by kurobako run command.' + report-md-path: + description: 'File path to a json generated by kurobako report command.' required: true - default: './kurobako.json' + default: 'kurobako.md' public-image-url: - description: 'URL to kurobako plot curve image which you upload later.' - required: false - default: '' + description: 'A public image url to kurobako plot image.' + required: true + default: 'https://storage.googleapis.com/kurobako-reports/dummy.png' outputs: image-path: description: 'A file path to the generated image of kurobako. You need to upload this on GCS.' @@ -16,5 +16,5 @@ runs: using: 'docker' image: 'Dockerfile' args: - - ${{ inputs.report-json-path }} + - ${{ inputs.report-md-path }} - ${{ inputs.public-image-url }} diff --git a/plot/Dockerfile b/plot/Dockerfile new file mode 100644 index 0000000..1a8b518 --- /dev/null +++ b/plot/Dockerfile @@ -0,0 +1,17 @@ +FROM alpine:3.11 + +RUN apk add --update gnuplot \ + fontconfig \ + ttf-ubuntu-font-family \ + msttcorefonts-installer \ + curl && \ + update-ms-fonts && \ + fc-cache -f && \ + rm -rf /var/cache/apk/* + +RUN curl -L https://github.com/sile/kurobako/releases/download/0.1.4/kurobako-0.1.4.linux-amd64 -o kurobako && \ + chmod +x ./kurobako && \ + ./kurobako -h + +COPY entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/plot/README.md b/plot/README.md new file mode 100644 index 0000000..a28d2df --- /dev/null +++ b/plot/README.md @@ -0,0 +1,23 @@ +# kurobako-plot + +GitHub Action to plot a benchmark result of [kurobako](https://github.com/sile/kurobako). + +## Inputs + +### `report-json-path` + +**Required** File path to a json generated by kurobako run command. Default `"./kurobako.json"`. + +## Outputs + +### `image-path` + +A file path to the generated image of kurobako. + +## Example usage + +```yaml +uses: c-bata/github-actions-kurobako/plot@master +with: + report-json-path: '/home/runner/kurobako-report.json' +``` diff --git a/plot/action.yml b/plot/action.yml new file mode 100644 index 0000000..930c184 --- /dev/null +++ b/plot/action.yml @@ -0,0 +1,15 @@ +name: 'Kurobako Plot' +description: 'GitHub Action to run kurobako plot curve.' +inputs: + report-json-path: + description: 'File path to a json generated by kurobako run command.' + required: true + default: './kurobako.json' +outputs: + image-path: + description: 'A file path to the generated image of kurobako.' +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.report-json-path }} diff --git a/plot/entrypoint.sh b/plot/entrypoint.sh new file mode 100755 index 0000000..f10017f --- /dev/null +++ b/plot/entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/sh -l + +set -e + +cat $1 | ./kurobako plot curve -o ./output/ + +imagepath=$(ls ./output/*.png | head -1) + +echo ::set-output name=image-path::$imagepath diff --git a/report.py b/report.py index 5b54520..508394f 100644 --- a/report.py +++ b/report.py @@ -1,12 +1,9 @@ import json import os import sys -import subprocess from github import Github -KUROBAKO = os.getenv('KUROBAKO', './kurobako') -OUTPUT_DIR = os.getenv('OUTPUT_DIR', './output/') ACCESS_TOKEN = os.getenv('GITHUB_TOKEN') @@ -16,21 +13,13 @@ def get_webhook_event(): return json.load(f) -def get_kurobako_image_path(): - # TODO(c-bata): specify output filename in the option at kurobako plot curve command. - # It seems kurobako accepts multiple studies, so it seems to need more discussions. - for filepath in os.listdir(OUTPUT_DIR): - if filepath.endswith('.png'): - return os.path.join(OUTPUT_DIR, filepath) - raise Exception('kurobako image not found.') - - def generate_report(kurobako_report, public_image_url): - metadata, detail = kurobako_report[len('# Benchmark Result Report\n\n'):].split('## Table of Contents')[:2] + header_trimmed = kurobako_report[len('# Benchmark Result Report\n\n'):] + metadata, detail = header_trimmed.split('## Table of Contents\n')[:2] body = f""" # Kurobako Benchmark -{f'![plot curve image]({public_image_url})' if public_image_url else ''} +![plot curve image]({public_image_url}) {metadata} @@ -38,7 +27,6 @@ def generate_report(kurobako_report, public_image_url): See details of benchmark results ## Table of Contents - {detail} @@ -48,25 +36,18 @@ def generate_report(kurobako_report, public_image_url): def main(): print(sys.argv) - json_path = sys.argv[1] - public_image_url = sys.argv[2] if len(sys.argv) > 2 else '' + markdown_report_path = sys.argv[1] + public_image_url = sys.argv[2] event = get_webhook_event() pull_number = event.get('number') print("Pull Request:", pull_number) + repository = event.get('repository').get("full_name") print("Repository:", pull_number) - # Plot curve - subprocess.run([ - "sh", "-c", f"cat {json_path} | {KUROBAKO} plot curve -o {OUTPUT_DIR}", - ], check=True) - print(f"::set-output name=image-path::{get_kurobako_image_path()}") - - # Generate markdown report - kurobako_report = subprocess.check_output([ - "sh", "-c", f"cat {json_path} | {KUROBAKO} report", - ], text=True) + with open(markdown_report_path, 'r') as f: + kurobako_report = f.read() client = Github(ACCESS_TOKEN) issue = client.get_repo(repository).get_issue(pull_number)