forked from graphql/graphql-js
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Add '@github-actions' bot (graphql#3503)
- Loading branch information
1 parent
e1726df
commit 6bcd241
Showing
6 changed files
with
268 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,145 @@ | ||
name: GitHubActionsBot | ||
on: | ||
issue_comment: | ||
types: | ||
- created | ||
|
||
# We need to be call in context of the main branch to have write permissions | ||
# "pull_request" target is called in context of a fork | ||
# "pull_request_target" is called in context of the repository but not necessary latest main | ||
workflow_run: | ||
workflows: | ||
- PullRequestOpened | ||
types: | ||
- completed | ||
jobs: | ||
hello-message: | ||
if: github.event_name == 'workflow_run' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Download event.json | ||
run: gh run download "$WORKFLOW_ID" --repo "$REPO" --name event.json | ||
env: | ||
REPO: ${{ github.repository }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
WORKFLOW_ID: ${{github.event.workflow_run.id}} | ||
|
||
- name: Add comment on PR | ||
uses: actions/github-script@v5 | ||
with: | ||
script: | | ||
const fs = require('fs'); | ||
const event = JSON.parse(fs.readFileSync('./event.json', 'utf8')); | ||
github.rest.issues.createComment({ | ||
...context.repo, | ||
issue_number: event.pull_request.number, | ||
body: | ||
`Hi @${event.sender.login}, 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> | ||
accept-cmd: | ||
if: | | ||
github.event_name == 'issue_comment' && | ||
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/[email protected] | ||
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: github.event_name == 'issue_comment' && 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
Oops, something went wrong.