Skip to content

Commit

Permalink
Use the 2 workflows approach, will fix after merge if not working
Browse files Browse the repository at this point in the history
  • Loading branch information
cecton committed Oct 24, 2023
1 parent 4a24e56 commit 8804b0f
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 90 deletions.
90 changes: 0 additions & 90 deletions .github/workflows/benchmark-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,93 +69,3 @@ jobs:
yew-master/tools/output.log
current-pr/tools/output.log
retention-days: 1

post-benchmark-core:
name: Post Comment on Pull Request
runs-on: ubuntu-latest
needs: benchmark-core

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

- name: Download Artifact
uses: Legit-Labs/action-download-artifact@v2
with:
github_token: "${{ secrets.GITHUB_TOKEN }}"
workflow: benchmark-core.yml
name: benchmark-core
path: "benchmark-core/"

- name: Make pull request comment
run: |
cat - >>comment.txt <<EOF
### Benchmark - core
#### Yew Master
\`\`\`
EOF
cat benchmark-core/yew-master/tools/output.log >>comment.txt
cat - >>comment.txt <<EOF
\`\`\`
#### Pull Request" >> comment.txt
\`\`\`
EOF
cat benchmark-core/current-pr/tools/output.log >>comment.txt
cat - >>comment.txt <<EOF
\`\`\`
EOF
- name: Read Pull Request ID
run: |
PR_NUMBER=$(cat "benchmark-core/.PR_NUMBER")
if ! [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then
echo "pr number invalid"
exit 1
fi
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
- name: Post Comment
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const commentInfo = {
...context.repo,
issue_number: ${{ env.PR_NUMBER }},
};
const comment = {
...commentInfo,
body: fs.readFileSync("comment.txt", 'utf-8'),
};
function isCommentByBot(comment) {
return comment.user.type === "Bot" && comment.body.includes("### Benchmark - core");
}
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);
}
100 changes: 100 additions & 0 deletions .github/workflows/post-benchmark-core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
name: Post Comment for Benchmark - core

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

jobs:
post-benchmark-core:
if: github.event.workflow_run.event == 'pull_request'
name: Post Comment on Pull Request
runs-on: ubuntu-latest

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

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

- name: Make pull request comment
run: |
cat - >>comment.txt <<EOF
### Benchmark - core
#### Yew Master
```
EOF
cat benchmark-core/yew-master/tools/output.json >>comment.txt
cat - >>comment.txt <<EOF
```
#### Pull Request" >> comment.txt
```
EOF
cat benchmark-core/current-pr/tools/output.json >>comment.txt
cat - >>comment.txt <<EOF
```
EOF
- name: Read Pull Request ID
run: |
PR_NUMBER=$(cat "benchmark-core/.PR_NUMBER")
if ! [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then
echo "pr number invalid"
exit 1
fi
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
- name: Post Comment
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const commentInfo = {
...context.repo,
issue_number: ${{ env.PR_NUMBER }},
};
const comment = {
...commentInfo,
body: fs.readFileSync("comment.txt", 'utf-8'),
};
function isCommentByBot(comment) {
return comment.user.type === "Bot" && comment.body.includes("### Benchmark - core");
}
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);
}

0 comments on commit 8804b0f

Please sign in to comment.