Skip to content

Commit

Permalink
Merge branch 'master' into fix-rendering-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
futursolo committed Aug 3, 2022
2 parents 1511f88 + 7562b65 commit 4bc1d02
Show file tree
Hide file tree
Showing 7 changed files with 787 additions and 13 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/benchmark-ssr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
name: Benchmark - SSR

on:
pull_request:
branches: [master]
paths:
- .github/workflows/benchmark-ssr.yml
- "packages/yew"
- "examples/function_router"
- "tools/benchmark-ssr"

jobs:
benchmark-ssr:
name: Benchmark - SSR
runs-on: ubuntu-latest

steps:
- name: Checkout master
uses: actions/checkout@v3
with:
repository: 'yewstack/yew'
ref: master
path: yew-master

- name: Checkout pull request
uses: actions/checkout@v3
with:
path: current-pr

- name: Setup toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-unknown
profile: minimal

- name: Restore Rust cache for master
uses: Swatinem/rust-cache@v1
with:
working-directory: yew-master
key: master

- name: Restore Rust cache for current pull request
uses: Swatinem/rust-cache@v1
with:
working-directory: current-pr
key: pr

- name: Run pull request benchmark
run: cargo run --profile=bench --bin benchmark-ssr -- --output-path ./output.json
working-directory: current-pr/tools

- name: Run master benchmark
run: cargo run --profile=bench --bin benchmark-ssr -- --output-path ./output.json
working-directory: yew-master/tools

- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: benchmark-ssr
path: |
yew-master/tools/output.json
current-pr/tools/output.json
retention-days: 1
74 changes: 74 additions & 0 deletions .github/workflows/post-benchmark-ssr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
name: Post Comment for Benchmark - SSR

on:
workflow_run:
workflows: ["Benchmark - SSR"]
types:
- completed

jobs:
post-benchmark-ssr:
name: Post Comment on Pull Request
runs-on: ubuntu-latest

steps:
- name: Download Repository
uses: actions/checkout@v2

- if: github.event.workflow_run.event == 'pull_request'
name: Download Artifact
uses: Legit-Labs/action-download-artifact@v2
with:
github_token: "${{ secrets.GITHUB_TOKEN }}"
workflow: benchmark-ssr.yml
run_id: ${{ github.event.workflow_run.id }}
name: benchmark-ssr
path: "benchmark-ssr/"

- name: Make pull request comment
run: python3 ci/make_benchmark_ssr_cmt.py

- name: Post Comment
uses: actions/github-script@v6
with:
script: |
const commentInfo = {
...context.repo,
issue_number: ${{ env.PR_NUMBER }},
};
const comment = {
...commentInfo,
body: JSON.parse(process.env.YEW_BENCH_SSR),
};
function isCommentByBot(comment) {
return comment.user.type === "Bot" && comment.body.includes("### Benchmark - SSR");
}
let commentId = null;
const comments = (await github.rest.issues.listComments(commentInfo)).data;
for (let i = comments.length; i--; ) {
const c = comments[i];
if (isCommentByBot(c)) {
commentId = c.id;
break;
}
}
if (commentId) {
try {
await github.rest.issues.updateComment({
...context.repo,
comment_id: commentId,
body: comment.body,
});
} catch (e) {
commentId = null;
}
}
if (!commentId) {
await github.rest.issues.createComment(comment);
}
56 changes: 56 additions & 0 deletions ci/make_benchmark_ssr_cmt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from typing import Dict, List, Optional, Tuple

import os
import json


header = "| Benchmark | Round | Min (ms) | Max (ms) | Mean (ms) | Standard Deviation |"
sep = "| --- | --- | --- | --- | --- | --- |"


def write_benchmark(lines: List[str], content: List[Dict[str, str]]) -> None:
lines.append("<details>")
lines.append("")
lines.append(header)
lines.append(sep)

for i in content:
lines.append(
"| {i.name} | {i.round} | {i.min} | {i.max} | {i.mean} | {i.std_dev} |"
)

lines.append("")
lines.append("</details>")


def main() -> None:
with open("benchmark-ssr/yew-master/tools/output.json") as f:
master_content = json.loads(f.read())

with open("benchmark-ssr/current-pr/tools/output.json") as f:
pr_content = json.loads(f.read())

lines: List[str] = []

lines.append("### Benchmark - SSR")
lines.append("")

lines.append("#### Yew Master")
lines.append("")

write_benchmark(lines, master_content)

lines.append("#### Pull Request")
lines.append("")

write_benchmark(lines, pr_content)

output = "\n".join(lines)

with open(os.environ["GITHUB_ENV"], "a+") as f:
f.write(f"YEW_BENCH_SSR={json.dumps(output)}\n")
f.write(f"PR_NUMBER={issue_number}\n")


if __name__ == "__main__":
main()

0 comments on commit 4bc1d02

Please sign in to comment.