mirror of
https://github.com/actions/github-script.git
synced 2026-02-08 03:57:27 +00:00
Update README to use v8 and octokit by default
This commit is contained in:
parent
0e0b836b33
commit
b0ee7adf36
1 changed files with 35 additions and 35 deletions
68
README.md
68
README.md
|
|
@ -75,7 +75,7 @@ and potential `SyntaxError`s when the expression is not valid JavaScript code (p
|
||||||
To pass inputs, set `env` vars on the action step and reference them in your script with `process.env`:
|
To pass inputs, set `env` vars on the action step and reference them in your script with `process.env`:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v8
|
||||||
env:
|
env:
|
||||||
TITLE: ${{ github.event.pull_request.title }}
|
TITLE: ${{ github.event.pull_request.title }}
|
||||||
with:
|
with:
|
||||||
|
|
@ -94,7 +94,7 @@ The return value of the script will be in the step's outputs under the
|
||||||
"result" key.
|
"result" key.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v8
|
||||||
id: set-result
|
id: set-result
|
||||||
with:
|
with:
|
||||||
script: return "Hello!"
|
script: return "Hello!"
|
||||||
|
|
@ -113,7 +113,7 @@ output of a github-script step. For some workflows, string encoding is preferred
|
||||||
`result-encoding` input:
|
`result-encoding` input:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v8
|
||||||
id: my-script
|
id: my-script
|
||||||
with:
|
with:
|
||||||
result-encoding: string
|
result-encoding: string
|
||||||
|
|
@ -125,32 +125,32 @@ output of a github-script step. For some workflows, string encoding is preferred
|
||||||
By default, requests made with the `github` instance will not be retried. You can configure this with the `retries` option:
|
By default, requests made with the `github` instance will not be retried. You can configure this with the `retries` option:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v8
|
||||||
id: my-script
|
id: my-script
|
||||||
with:
|
with:
|
||||||
result-encoding: string
|
result-encoding: string
|
||||||
retries: 3
|
retries: 3
|
||||||
script: |
|
script: |
|
||||||
github.rest.issues.get({
|
octokit.rest.issues.get({
|
||||||
issue_number: context.issue.number,
|
issue_number: context.issue.number,
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
In this example, request failures from `github.rest.issues.get()` will be retried up to 3 times.
|
In this example, request failures from `octokit.rest.issues.get()` will be retried up to 3 times.
|
||||||
|
|
||||||
You can also configure which status codes should be exempt from retries via the `retry-exempt-status-codes` option:
|
You can also configure which status codes should be exempt from retries via the `retry-exempt-status-codes` option:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v8
|
||||||
id: my-script
|
id: my-script
|
||||||
with:
|
with:
|
||||||
result-encoding: string
|
result-encoding: string
|
||||||
retries: 3
|
retries: 3
|
||||||
retry-exempt-status-codes: 400,401
|
retry-exempt-status-codes: 400,401
|
||||||
script: |
|
script: |
|
||||||
github.rest.issues.get({
|
octokit.rest.issues.get({
|
||||||
issue_number: context.issue.number,
|
issue_number: context.issue.number,
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
|
|
@ -172,7 +172,7 @@ By default, github-script will use the token provided to your workflow.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: View context attributes
|
- name: View context attributes
|
||||||
uses: actions/github-script@v7
|
uses: actions/github-script@v8
|
||||||
with:
|
with:
|
||||||
script: console.log(context)
|
script: console.log(context)
|
||||||
```
|
```
|
||||||
|
|
@ -188,10 +188,10 @@ jobs:
|
||||||
comment:
|
comment:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v8
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
github.rest.issues.createComment({
|
octokit.rest.issues.createComment({
|
||||||
issue_number: context.issue.number,
|
issue_number: context.issue.number,
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
|
|
@ -210,10 +210,10 @@ jobs:
|
||||||
apply-label:
|
apply-label:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v8
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
github.rest.issues.addLabels({
|
octokit.rest.issues.addLabels({
|
||||||
issue_number: context.issue.number,
|
issue_number: context.issue.number,
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
|
|
@ -232,18 +232,18 @@ jobs:
|
||||||
welcome:
|
welcome:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v8
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
// Get a list of all issues created by the PR opener
|
// Get a list of all issues created by the PR opener
|
||||||
// See: https://octokit.github.io/rest.js/#pagination
|
// See: https://octokit.github.io/rest.js/#pagination
|
||||||
const creator = context.payload.sender.login
|
const creator = context.payload.sender.login
|
||||||
const opts = github.rest.issues.listForRepo.endpoint.merge({
|
const opts = octokit.rest.issues.listForRepo.endpoint.merge({
|
||||||
...context.issue,
|
...context.issue,
|
||||||
creator,
|
creator,
|
||||||
state: 'all'
|
state: 'all'
|
||||||
})
|
})
|
||||||
const issues = await github.paginate(opts)
|
const issues = await octokit.paginate(opts)
|
||||||
|
|
||||||
for (const issue of issues) {
|
for (const issue of issues) {
|
||||||
if (issue.number === context.issue.number) {
|
if (issue.number === context.issue.number) {
|
||||||
|
|
@ -255,7 +255,7 @@ jobs:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await github.rest.issues.createComment({
|
await octokit.rest.issues.createComment({
|
||||||
issue_number: context.issue.number,
|
issue_number: context.issue.number,
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
|
|
@ -277,11 +277,11 @@ jobs:
|
||||||
diff:
|
diff:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v8
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const diff_url = context.payload.pull_request.diff_url
|
const diff_url = context.payload.pull_request.diff_url
|
||||||
const result = await github.request(diff_url)
|
const result = await octokit.request(diff_url)
|
||||||
console.log(result)
|
console.log(result)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -301,7 +301,7 @@ jobs:
|
||||||
list-issues:
|
list-issues:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v8
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const query = `query($owner:String!, $name:String!, $label:String!) {
|
const query = `query($owner:String!, $name:String!, $label:String!) {
|
||||||
|
|
@ -318,7 +318,7 @@ jobs:
|
||||||
name: context.repo.repo,
|
name: context.repo.repo,
|
||||||
label: 'wontfix'
|
label: 'wontfix'
|
||||||
}
|
}
|
||||||
const result = await github.graphql(query, variables)
|
const result = await octokit.graphql(query, variables)
|
||||||
console.log(result)
|
console.log(result)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -335,17 +335,17 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v8
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const script = require('./path/to/script.js')
|
const script = require('./path/to/script.js')
|
||||||
console.log(script({github, context}))
|
console.log(script({octokit, context}))
|
||||||
```
|
```
|
||||||
|
|
||||||
And then export a function from your module:
|
And then export a function from your module:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
module.exports = ({github, context}) => {
|
module.exports = ({octokit, context}) => {
|
||||||
return context.payload.client_payload.value
|
return context.payload.client_payload.value
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
@ -373,21 +373,21 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v8
|
||||||
env:
|
env:
|
||||||
SHA: '${{env.parentSHA}}'
|
SHA: '${{env.parentSHA}}'
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const script = require('./path/to/script.js')
|
const script = require('./path/to/script.js')
|
||||||
await script({github, context, core})
|
await script({octokit, context, core})
|
||||||
```
|
```
|
||||||
|
|
||||||
And then export an async function from your module:
|
And then export an async function from your module:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
module.exports = async ({github, context, core}) => {
|
module.exports = async ({octokit, context, core}) => {
|
||||||
const {SHA} = process.env
|
const {SHA} = process.env
|
||||||
const commit = await github.rest.repos.getCommit({
|
const commit = await octokit.rest.repos.getCommit({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
ref: `${SHA}`
|
ref: `${SHA}`
|
||||||
|
|
@ -417,7 +417,7 @@ jobs:
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
# or one-off:
|
# or one-off:
|
||||||
- run: npm install execa
|
- run: npm install execa
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v8
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const execa = require('execa')
|
const execa = require('execa')
|
||||||
|
|
@ -447,7 +447,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v8
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const { default: printStuff } = await import('${{ github.workspace }}/src/print-stuff.js')
|
const { default: printStuff } = await import('${{ github.workspace }}/src/print-stuff.js')
|
||||||
|
|
@ -491,11 +491,11 @@ jobs:
|
||||||
apply-label:
|
apply-label:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v8
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.MY_PAT }}
|
github-token: ${{ secrets.MY_PAT }}
|
||||||
script: |
|
script: |
|
||||||
github.rest.issues.addLabels({
|
octokit.rest.issues.addLabels({
|
||||||
issue_number: context.issue.number,
|
issue_number: context.issue.number,
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
|
|
@ -515,7 +515,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v8
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const exitCode = await exec.exec('echo', ['hello'])
|
const exitCode = await exec.exec('echo', ['hello'])
|
||||||
|
|
@ -533,7 +533,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v8
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const {
|
const {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue