Merge branch 'main' into main

This commit is contained in:
Josh Gross 2025-04-14 10:57:30 -04:00 committed by GitHub
commit 0ee31503ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 61 additions and 19 deletions

View file

@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
fetch-depth: 0 # prefer to use a full fetch for licensed workflows fetch-depth: 0 # prefer to use a full fetch for licensed workflows
- uses: ruby/setup-ruby@28c4deda893d5a96a6b2d958c5b47fc18d65c9d3 # v1.213.0 - uses: ruby/setup-ruby@354a1ad156761f5ee2b7b13fa8e09943a5e8d252 # v1.229.0
with: with:
ruby-version: ruby ruby-version: ruby
- uses: github/setup-licensed@v1 - uses: github/setup-licensed@v1

View file

@ -10,8 +10,8 @@ uses the GitHub API and the workflow run context.
To use this action, provide an input named `script` that contains the body of an asynchronous JavaScript function call. To use this action, provide an input named `script` that contains the body of an asynchronous JavaScript function call.
The following arguments will be provided: The following arguments will be provided:
- `octokit` (and `github`) A pre-authenticated - `github` A pre-authenticated
[octokit/rest.js](https://octokit.github.io/rest.js) client _instance_ with pagination plugins [octokit/rest.js](https://octokit.github.io/rest.js) client with pagination plugins
- `context` An object containing the [context of the workflow - `context` An object containing the [context of the workflow
run](https://github.com/actions/toolkit/blob/main/packages/github/src/context.ts) run](https://github.com/actions/toolkit/blob/main/packages/github/src/context.ts)
- `core` A reference to the [@actions/core](https://github.com/actions/toolkit/tree/main/packages/core) package - `core` A reference to the [@actions/core](https://github.com/actions/toolkit/tree/main/packages/core) package
@ -102,14 +102,14 @@ By default, requests made with the `github` instance will not be retried. You ca
result-encoding: string result-encoding: string
retries: 3 retries: 3
script: | script: |
octokit.rest.issues.get({ github.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 `octokit.rest.issues.get()` will be retried up to 3 times. In this example, request failures from `github.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:
@ -121,7 +121,7 @@ You can also configure which status codes should be exempt from retries via the
retries: 3 retries: 3
retry-exempt-status-codes: 400,401 retry-exempt-status-codes: 400,401
script: | script: |
octokit.rest.issues.get({ github.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,
@ -165,7 +165,7 @@ jobs:
- uses: actions/github-script@v7 - uses: actions/github-script@v7
with: with:
script: | script: |
octokit.rest.issues.createComment({ github.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,
@ -187,7 +187,7 @@ jobs:
- uses: actions/github-script@v7 - uses: actions/github-script@v7
with: with:
script: | script: |
octokit.rest.issues.addLabels({ github.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,
@ -212,12 +212,12 @@ jobs:
// 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 = octokit.rest.issues.listForRepo.endpoint.merge({ const opts = github.rest.issues.listForRepo.endpoint.merge({
...context.issue, ...context.issue,
creator, creator,
state: 'all' state: 'all'
}) })
const issues = await octokit.paginate(opts) const issues = await github.paginate(opts)
for (const issue of issues) { for (const issue of issues) {
if (issue.number === context.issue.number) { if (issue.number === context.issue.number) {
@ -229,7 +229,7 @@ jobs:
} }
} }
await octokit.rest.issues.createComment({ await github.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,
@ -255,7 +255,7 @@ jobs:
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 octokit.request(diff_url) const result = await github.request(diff_url)
console.log(result) console.log(result)
``` ```
@ -292,7 +292,7 @@ jobs:
name: context.repo.repo, name: context.repo.repo,
label: 'wontfix' label: 'wontfix'
} }
const result = await octokit.graphql(query, variables) const result = await github.graphql(query, variables)
console.log(result) console.log(result)
``` ```
@ -313,13 +313,13 @@ jobs:
with: with:
script: | script: |
const script = require('./path/to/script.js') const script = require('./path/to/script.js')
console.log(script({octokit, context})) console.log(script({github, context}))
``` ```
And then export a function from your module: And then export a function from your module:
```javascript ```javascript
module.exports = ({octokit, context}) => { module.exports = ({github, context}) => {
return context.payload.client_payload.value return context.payload.client_payload.value
} }
``` ```
@ -353,15 +353,15 @@ jobs:
with: with:
script: | script: |
const script = require('./path/to/script.js') const script = require('./path/to/script.js')
await script({octokit, context, core}) await script({github, 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 ({octokit, context, core}) => { module.exports = async ({github, context, core}) => {
const {SHA} = process.env const {SHA} = process.env
const commit = await octokit.rest.repos.getCommit({ const commit = await github.rest.repos.getCommit({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
ref: `${SHA}` ref: `${SHA}`
@ -490,10 +490,52 @@ jobs:
with: with:
github-token: ${{ secrets.MY_PAT }} github-token: ${{ secrets.MY_PAT }}
script: | script: |
octokit.rest.issues.addLabels({ github.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,
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)
```