mirror of
https://github.com/actions/github-script.git
synced 2025-12-08 08:06:23 +00:00
Merge pull request #546 from neilime/patch-1
docs: add "exec" usage examples
This commit is contained in:
42
README.md
42
README.md
@@ -494,3 +494,45 @@ jobs:
|
|||||||
labels: ['Triage']
|
labels: ['Triage']
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Using exec package
|
||||||
|
|
||||||
|
The provided [@actions/exec](https://github.com/actions/toolkit/tree/main/packages/exec) package allows to execute command or tools in a cross platform way:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
use-exec:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/github-script@v7
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const exitCode = await exec.exec('echo', ['hello'])
|
||||||
|
|
||||||
|
console.log(exitCode)
|
||||||
|
```
|
||||||
|
|
||||||
|
`exec` packages provides `getExecOutput` function to retrieve stdout and stderr from executed command:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
use-get-exec-output:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/github-script@v7
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const {
|
||||||
|
exitCode,
|
||||||
|
stdout,
|
||||||
|
stderr
|
||||||
|
} = await exec.getExecOutput('echo', ['hello']);
|
||||||
|
|
||||||
|
console.log(exitCode, stdout, stderr)
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user