Skip to main content

此版本的 GitHub Enterprise 已停止服务 2022-06-03. 即使针对重大安全问题,也不会发布补丁。 要获得更好的性能、改进的安全性和新功能,请升级到 GitHub Enterprise 的最新版本。 如需升级方面的帮助,请联系 GitHub Enterprise 支持

工作流程

工作流程 API 允许您查看仓库的工作流程。

关于工作流程作业 API

工作流程 API 允许您查看仓库的工作流程。 工作流程通过广泛的各种工具和服务自动化软件开发生命周期。 更多信息请参阅“使用 GitHub Actions 自动化工作流程”。

此 API 适用于经过身份验证的用户、OAuth 应用程序 和 GitHub 应用程序。 访问令牌需要 repo 作用域(对于私有仓库)和 public_repo 作用域(对于公共仓库)。 GitHub 应用程序 必须具有 actions 权限才可使用此 API。

List repository workflows

Lists the workflows in a repository. Anyone with read access to the repository can use this endpoint. If the repository is private you must use an access token with the repo scope. GitHub Apps must have the actions:read permission to use this endpoint.

参数

� �头
名称, 类型, 描述
acceptstring

Setting to application/vnd.github.v3+json is recommended.

路径参数
名称, 类型, 描述
ownerstring必选

The account owner of the repository. The name is not case sensitive.

repostring必选

The name of the repository. The name is not case sensitive.

查询参数
名称, 类型, 描述
per_pageinteger

The number of results per page (max 100).

默认值: 30

pageinteger

Page number of the results to fetch.

默认值: 1

HTTP 响应状态代� �

状态代� �描述
200

OK

代� �示例

get/repos/{owner}/{repo}/actions/workflows
curl \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: token <TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/actions/workflows

Response

Status: 200
{ "total_count": 2, "workflows": [ { "id": 161335, "node_id": "MDg6V29ya2Zsb3cxNjEzMzU=", "name": "CI", "path": ".github/workflows/blank.yaml", "state": "active", "created_at": "2020-01-08T23:48:37.000-08:00", "updated_at": "2020-01-08T23:50:21.000-08:00", "url": "https://api.github.com/repos/octo-org/octo-repo/actions/workflows/161335", "html_url": "https://github.com/octo-org/octo-repo/blob/master/.github/workflows/161335", "badge_url": "https://github.com/octo-org/octo-repo/workflows/CI/badge.svg" }, { "id": 269289, "node_id": "MDE4OldvcmtmbG93IFNlY29uZGFyeTI2OTI4OQ==", "name": "Linter", "path": ".github/workflows/linter.yaml", "state": "active", "created_at": "2020-01-08T23:48:37.000-08:00", "updated_at": "2020-01-08T23:50:21.000-08:00", "url": "https://api.github.com/repos/octo-org/octo-repo/actions/workflows/269289", "html_url": "https://github.com/octo-org/octo-repo/blob/master/.github/workflows/269289", "badge_url": "https://github.com/octo-org/octo-repo/workflows/Linter/badge.svg" } ] }

Get a workflow

Gets a specific workflow. You can replace workflow_id with the workflow file name. For example, you could use main.yaml. Anyone with read access to the repository can use this endpoint. If the repository is private you must use an access token with the repo scope. GitHub Apps must have the actions:read permission to use this endpoint.

参数

� �头
名称, 类型, 描述
acceptstring

Setting to application/vnd.github.v3+json is recommended.

路径参数
名称, 类型, 描述
ownerstring必选

The account owner of the repository. The name is not case sensitive.

repostring必选

The name of the repository. The name is not case sensitive.

workflow_id必选

The ID of the workflow. You can also pass the workflow file name as a string.

HTTP 响应状态代� �

状态代� �描述
200

OK

代� �示例

get/repos/{owner}/{repo}/actions/workflows/{workflow_id}
curl \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: token <TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/actions/workflows/WORKFLOW_ID

Response

Status: 200
{ "id": 161335, "node_id": "MDg6V29ya2Zsb3cxNjEzMzU=", "name": "CI", "path": ".github/workflows/blank.yaml", "state": "active", "created_at": "2020-01-08T23:48:37.000-08:00", "updated_at": "2020-01-08T23:50:21.000-08:00", "url": "https://api.github.com/repos/octo-org/octo-repo/actions/workflows/161335", "html_url": "https://github.com/octo-org/octo-repo/blob/master/.github/workflows/161335", "badge_url": "https://github.com/octo-org/octo-repo/workflows/CI/badge.svg" }

Disable a workflow

Disables a workflow and sets the state of the workflow to disabled_manually. You can replace workflow_id with the workflow file name. For example, you could use main.yaml.

You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have the actions:write permission to use this endpoint.

参数

� �头
名称, 类型, 描述
acceptstring

Setting to application/vnd.github.v3+json is recommended.

路径参数
名称, 类型, 描述
ownerstring必选

The account owner of the repository. The name is not case sensitive.

repostring必选

The name of the repository. The name is not case sensitive.

workflow_id必选

The ID of the workflow. You can also pass the workflow file name as a string.

HTTP 响应状态代� �

状态代� �描述
204

No Content

代� �示例

put/repos/{owner}/{repo}/actions/workflows/{workflow_id}/disable
curl \ -X PUT \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: token <TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/actions/workflows/WORKFLOW_ID/disable

Response

Status: 204

Create a workflow dispatch event

You can use this endpoint to manually trigger a GitHub Actions workflow run. You can replace workflow_id with the workflow file name. For example, you could use main.yaml.

You must configure your GitHub Actions workflow to run when the workflow_dispatch webhook event occurs. The inputs are configured in the workflow file. For more information about how to configure the workflow_dispatch event in the workflow file, see "Events that trigger workflows."

You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have the actions:write permission to use this endpoint. For more information, see "Creating a personal access token for the command line."

参数

� �头
名称, 类型, 描述
acceptstring

Setting to application/vnd.github.v3+json is recommended.

路径参数
名称, 类型, 描述
ownerstring必选

The account owner of the repository. The name is not case sensitive.

repostring必选

The name of the repository. The name is not case sensitive.

workflow_id必选

The ID of the workflow. You can also pass the workflow file name as a string.

正文参数
名称, 类型, 描述
refstring必选

The git reference for the workflow. The reference can be a branch or tag name.

inputsobject

Input keys and values configured in the workflow file. The maximum number of properties is 10. Any default properties configured in the workflow file will be used when inputs are omitted.

HTTP 响应状态代� �

状态代� �描述
204

No Content

代� �示例

post/repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches
curl \ -X POST \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: token <TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/actions/workflows/WORKFLOW_ID/dispatches \ -d '{"ref":"topic-branch","inputs":{"name":"Mona the Octocat","home":"San Francisco, CA"}}'

Response

Status: 204

Enable a workflow

Enables a workflow and sets the state of the workflow to active. You can replace workflow_id with the workflow file name. For example, you could use main.yaml.

You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have the actions:write permission to use this endpoint.

参数

� �头
名称, 类型, 描述
acceptstring

Setting to application/vnd.github.v3+json is recommended.

路径参数
名称, 类型, 描述
ownerstring必选

The account owner of the repository. The name is not case sensitive.

repostring必选

The name of the repository. The name is not case sensitive.

workflow_id必选

The ID of the workflow. You can also pass the workflow file name as a string.

HTTP 响应状态代� �

状态代� �描述
204

No Content

代� �示例

put/repos/{owner}/{repo}/actions/workflows/{workflow_id}/enable
curl \ -X PUT \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: token <TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/actions/workflows/WORKFLOW_ID/enable

Response

Status: 204