Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5467f2a

Browse filesBrowse files
authored
Merge pull request actions#131 from esker-software/Update-readme-with-async-example
Update readme with async example
2 parents f05a81d + c72dc00 commit 5467f2a
Copy full SHA for 5467f2a

File tree

1 file changed

+38
-3
lines changed
Filter options

1 file changed

+38
-3
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+38-3Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,6 @@ module.exports = ({github, context}) => {
257257
}
258258
```
259259

260-
You can also use async functions in this manner, as long as you `await` it in
261-
the inline script.
262-
263260
Note that because you can't `require` things like the GitHub context or
264261
Actions Toolkit libraries, you'll want to pass them as arguments to your
265262
external function.
@@ -268,6 +265,44 @@ Additionally, you'll want to use the [checkout
268265
action](https://github.com/actions/checkout) to make sure your script file is
269266
available.
270267

268+
### Run a separate file with an async function
269+
270+
You can also use async functions in this manner, as long as you `await` it in
271+
the inline script.
272+
273+
In your workflow:
274+
275+
```yaml
276+
on: push
277+
278+
jobs:
279+
echo-input:
280+
runs-on: ubuntu-latest
281+
steps:
282+
- uses: actions/checkout@v2
283+
- uses: actions/github-script@v3
284+
env:
285+
SHA: "${{env.parentSHA}}"
286+
with:
287+
script: |
288+
const script = require(`${process.env.GITHUB_WORKSPACE}/path/to/script.js`)
289+
await script({github, context, core})
290+
```
291+
292+
And then export an async function from your module:
293+
294+
```javascript
295+
module.exports = async ({ github, context, core }) => {
296+
const { SHA } = process.env
297+
const commit = await github.repos.getCommit({
298+
owner: context.repo.owner,
299+
repo: context.repo.repo,
300+
ref: `${SHA}`
301+
})
302+
core.exportVariable('author', commit.data.commit.author.email);
303+
}
304+
```
305+
271306
### Use npm packages
272307

273308
Like importing your own files above, you can also use installed modules:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.