• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

actions/github-script: Write workflows scripting the GitHub API in JavaScript

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

actions/github-script

开源软件地址:

https://github.com/actions/github-script

开源编程语言:

TypeScript 98.1%

开源软件介绍:

actions/github-script

.github/workflows/integration.yml .github/workflows/ci.yml .github/workflows/licensed.yml

This action makes it easy to quickly write a script in your workflow that uses the GitHub API and the workflow run context.

In order to use this action, a script input is provided. The value of that input should be the body of an asynchronous function call. The following arguments will be provided:

  • github A pre-authenticated octokit/rest.js client with pagination plugins
  • context An object containing the context of the workflow run
  • core A reference to the @actions/core package
  • glob A reference to the @actions/glob package
  • io A reference to the @actions/io package
  • exec A reference to the @actions/exec package
  • require A proxy wrapper around the normal Node.js require to enable requiring relative paths (relative to the current working directory) and requiring npm packages installed in the current working directory. If for some reason you need the non-wrapped require, there is an escape hatch available: __original_require__ is the original value of require without our wrapping applied.

Since the script is just a function body, these values will already be defined, so you don't have to import them (see examples below).

See octokit/rest.js for the API client documentation.

Breaking Changes

Breaking changes in V6

Version 6 of this action updated the runtime to Node 16 - https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-using-nodejs-v16

All scripts are now run with Node 16 instead of Node 12 and are affected by any breaking changes between Node 12 and 16.

Breaking changes in V5

Version 5 of this action includes the version 5 of @actions/github and @octokit/plugin-rest-endpoint-methods. As part of this update, the Octokit context available via github no longer has REST methods directly. These methods are available via github.rest.* - https://github.com/octokit/plugin-rest-endpoint-methods.js/releases/tag/v5.0.0

For example, github.issues.createComment in V4 becomes github.rest.issues.createComment in V5

github.request, github.paginate, and github.graphql are unchanged.

Development

See development.md.

Reading step results

The return value of the script will be in the step's outputs under the "result" key.

- uses: actions/github-script@v6
  id: set-result
  with:
    script: return "Hello!"
    result-encoding: string
- name: Get result
  run: echo "${{steps.set-result.outputs.result}}"

See "Result encoding" for details on how the encoding of these outputs can be changed.

Result encoding

By default, the JSON-encoded return value of the function is set as the "result" in the output of a github-script step. For some workflows, string encoding is preferred. This option can be set using the result-encoding input:

- uses: actions/github-script@v6
  id: my-script
  with:
    result-encoding: string
    script: return "I will be string (not JSON) encoded!"

Examples

Note that github-token is optional in this action, and the input is there in case you need to use a non-default token.

By default, github-script will use the token provided to your workflow.

Print the available attributes of context

- name: View context attributes
  uses: actions/github-script@v6
  with:
    script: console.log(context)

Comment on an issue


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap