question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a more clear await example in the README

See original GitHub issue

Is 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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jasondamourcommented, Nov 20, 2022

The example did not work out of the box for me. I had to install the async module myself:

    # Without this step, it fails with vague MODULE_NOT_FOUND
    - run: npm install --no-save async


    - uses: actions/github-script@v6
      if: github.event_name == 'pull_request'
      with:
        script: |
          const commentOnPR = require('${{ github.workspace }}/scripts/terraform-pr-comment.js')
          await commentOnPR({github, context, steps})
0reactions
joshmgrosscommented, Apr 15, 2021

Merged #131, thanks all!

Read more comments on GitHub >

github_iconTop Results From Across the Web

getting fs.readme to work with async await and promisify
1 Answer 1 · You are creating a promisified function but you are using it with a callback. · I can that the...
Read more >
Using async/await in Node.js 7.6.0 - The ReadMe Blog
Async functions makes promise-using code more readable than before. Now instead of using Promise. then() to resolve your promise to a value, ...
Read more >
Using Async and Await in C# - Aaron Bos
The async and await keywords are vital to asynchronous code in C#. When used together, async ... An example will help provide more...
Read more >
How to use promises - Learn web development | MDN
Promises are the foundation of asynchronous programming in modern JavaScript. A promise is an object returned by an asynchronous function, ...
Read more >
Write code using async/await in Rust - developerlife.com
The README has excellent documentation on async traits, parallel and concurrent execution, and Tokio. So, a middleware function is of type ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found