Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6407307
commit a14a208
Showing
6 changed files
with
243 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: run-benchmark | ||
on: | ||
workflow_call: | ||
inputs: | ||
pullRequestJSON: | ||
required: true | ||
type: string | ||
outputs: | ||
replyMessage: | ||
value: ${{ jobs.benchmark.outputs.replyMessage }} | ||
jobs: | ||
benchmark: | ||
name: Run benchmark | ||
outputs: | ||
replyMessage: ${{ steps.set_replyMessage.outputs.replyMessage }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v2 | ||
with: | ||
persist-credentials: false | ||
ref: ${{ fromJSON(inputs.pullRequestJSON).merge_commit_sha }} | ||
|
||
- name: Deepen cloned repo | ||
env: | ||
BASE_SHA: ${{ fromJSON(inputs.pullRequestJSON).base.sha }} | ||
run: 'git fetch --depth=1 origin $BASE_SHA:refs/tags/BASE' | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
cache: npm | ||
node-version-file: '.node-version' | ||
|
||
- name: Install Dependencies | ||
run: npm ci --ignore-scripts | ||
|
||
- name: Run Benchmark | ||
run: | | ||
npm run benchmark -- --revs HEAD BASE | tee benchmark.log | ||
- name: Set 'replyMessage' output variable | ||
id: set_replyMessage | ||
uses: actions/github-script@v5 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
const fs = require('fs'); | ||
const replyMessage = ` | ||
<details> | ||
<summary> Benchmark output </summary> | ||
${ fs.readFileSync('./benchmark.log', 'utf-8') } | ||
</details> | ||
`; | ||
core.setOutput('replyMessage', replyMessage); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: GitHubActionsBotHello | ||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
|
||
jobs: | ||
hello-message: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Add comment on PR | ||
uses: actions/github-script@v5 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
const sender = context.payload.sender.login; | ||
github.rest.issues.createComment({ | ||
...context.repo, | ||
issue_number: context.issue.number, | ||
body: | ||
`Hi @${sender}, I'm @github-actions bot happy to help you with this PR 👋\n\n` + | ||
process.env.SUPPORTED_COMMANDS, | ||
}) | ||
env: | ||
SUPPORTED_COMMANDS: | | ||
<details> | ||
<summary> Supported commands </summary> | ||
Please post this commands in separate comments and only one per comment: | ||
* `@github-actions run-benchmark` - Run benchmark comparing base and merge commits for this PR | ||
* `@github-actions publish-pr-on-npm` - Build package from this PR and publish it on NPM | ||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
name: GitHubActionsBot | ||
on: | ||
issue_comment: | ||
types: | ||
- created | ||
|
||
jobs: | ||
accept-cmd: | ||
if: | | ||
github.event.issue.pull_request && | ||
startsWith(github.event.comment.body, '@github-actions ') | ||
runs-on: ubuntu-latest | ||
outputs: | ||
cmd: ${{ steps.parse-cmd.outputs.cmd }} | ||
replyMessage: ${{ steps.parse-cmd.outputs.replyMessage }} | ||
pullRequestJSON: ${{ steps.get-pull_request-json.outputs.data }} | ||
steps: | ||
- uses: actions/github-script@v5 | ||
with: | ||
script: | | ||
github.rest.reactions.createForIssueComment({ | ||
...context.repo, | ||
comment_id: context.payload.comment.id, | ||
content: 'eyes', | ||
}); | ||
- id: parse-cmd | ||
uses: actions/github-script@v5 | ||
with: | ||
script: | | ||
const cmd = context.payload.comment.body.replace('@github-actions', '').trim(); | ||
core.setOutput('cmd', cmd); | ||
- id: get-pull_request-json | ||
uses: octokit/request-action@v2.x | ||
with: | ||
route: GET ${{ github.event.issue.pull_request.url }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
cmd-publish-pr-on-npm: | ||
needs: [accept-cmd] | ||
if: needs.accept-cmd.outputs.cmd == 'publish-pr-on-npm' | ||
uses: ./.github/workflows/cmd-publish-pr-on-npm.yml | ||
with: | ||
pullRequestJSON: ${{ needs.accept-cmd.outputs.pullRequestJSON }} | ||
|
||
cmd-run-benchmark: | ||
needs: [accept-cmd] | ||
if: needs.accept-cmd.outputs.cmd == 'run-benchmark' | ||
uses: ./.github/workflows/cmd-run-benchmark.yml | ||
with: | ||
pullRequestJSON: ${{ needs.accept-cmd.outputs.pullRequestJSON }} | ||
|
||
respond-to-cmd: | ||
needs: | ||
- cmd-publish-pr-on-npm | ||
- cmd-run-benchmark | ||
if: always() | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/github-script@v5 | ||
with: | ||
script: | | ||
const { issue, comment, sender } = context.payload; | ||
const needs = JSON.parse(process.env.NEEDS); | ||
let replyMessage; | ||
let allSkipped = true; | ||
for (const { result, outputs } of Object.values(needs)) { | ||
allSkipped = allSkipped && result === 'skipped'; | ||
replyMessage = replyMessage || outputs.replyMessage; | ||
} | ||
if (!replyMessage) { | ||
replyMessage = allSkipped | ||
? 'Unknown command, please check help message at the top of PR.' | ||
: `Something went wrong, please check logs here:\n${process.env.RUN_URL}`; | ||
} | ||
const quoteRequest = comment.body | ||
.split('\n') | ||
.map((line) => '> ' + line) | ||
.join('\n'); | ||
github.rest.issues.createComment({ | ||
...context.repo, | ||
issue_number: issue.number, | ||
body: quoteRequest + `\n\n@${sender.login} ` + replyMessage, | ||
}); | ||
// `github.rest` doesn't have this method :( so use graphql instead | ||
github.graphql(` | ||
mutation ($subjectId: ID!) { | ||
minimizeComment(input: { subjectId: $subjectId, classifier: RESOLVED}) | ||
{ __typename } | ||
} | ||
`, { subjectId: comment.node_id }); | ||
env: | ||
RUN_URL: ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}} | ||
NEEDS: ${{ toJSON(needs) }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters