Provide a more clear await example in the README
See original GitHub issueIs your feature request related to a problem? Please describe.
Apologies, If I am doing this incorrectly. I would like to use your https://github.com/actions/github-script/blob/main/.github/workflows/pull-request-test.yml
example in a separate file instead of an inline script.
Describe the solution you’d like
So, I originally looked at your solution in https://github.com/actions/github-script/blob/main/.github/workflows/pull-request-test.yml
, but noticed it was all done in an inline script, I think it would be helpful if you provided a more extensive example in the README as it took me a few trys to get it working in a separate file.
Describe alternatives you’ve considered
Additional context
So, if you could provide something like the following in the README, I think it would be helpful for other people as the example in https://github.com/actions/github-script/blob/main/.github/workflows/pull-request-test.yml
is quite good and uses await.
on: push
jobs:
echo-input:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/github-script@v3
with:
script: |
const script = require(`${process.env.GITHUB_WORKSPACE}/path/to/script.js`)
await script({github, context})
and then in that js file have
module.exports = async ({ github, context }) => {
// Get the existing comments.
const { data: comments } = await github.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.number,
})
// Find any comment already made by the bot.
const botComment = await comments.find(comment => comment.user.id === 41898282)
const commentBody = "Hello from actions/github-script! (${{ github.sha }})"
if (botComment) {
return await github.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody
})
} else {
return await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.number,
body: commentBody
})
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
The example did not work out of the box for me. I had to install the async module myself:
Merged #131, thanks all!