Skip to main content
REST API 现已经过版本控制。 有关详细信息,请参阅“关于 API 版本控制”。

GitHub Actions 缓存的 REST API 终结点

使用 REST API 与 GitHub Actions 中的存储库缓存进行交互。

关于 GitHub Actions

中的缓存

可以使用 REST API 查询和管理 GitHub Actions 中的存储库缓存。 你还可以安装 GitHub CLI 扩展来从命令行管理缓存。 有关详细信息,请参阅“缓存依赖项以加快工作流程”。

Get GitHub Actions cache usage for an enterprise

Gets the total GitHub Actions cache usage for an enterprise. The data fetched using this API is refreshed approximately every 5 minutes, so values returned from this endpoint may take at least 5 minutes to get updated.

OAuth tokens and personal access tokens (classic) need the admin:enterprise scope to use this endpoint.

“Get GitHub Actions cache usage for an enterprise”的细粒度访问令牌

此端点支持以下精细令牌类型:

精细令牌必须具有以下权限集:

  • "Enterprise administration" business permissions (write)

“Get GitHub Actions cache usage for an enterprise”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
enterprise string 必须

The slug version of the enterprise name. You can also substitute this value with the enterprise id.

“Get GitHub Actions cache usage for an enterprise”的 HTTP 响应状态代码

状态代码说明
200

OK

“Get GitHub Actions cache usage for an enterprise”的示例代码

请求示例

get/enterprises/{enterprise}/actions/cache/usage
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ http(s)://HOSTNAME/api/v3/enterprises/ENTERPRISE/actions/cache/usage

Response

Status: 200
{ "total_active_caches_size_in_bytes": 3344284, "total_active_caches_count": 5 }

Get GitHub Actions cache usage policy for an enterprise

Gets the GitHub Actions cache usage policy for an enterprise.

OAuth tokens and personal access tokens (classic) need the admin:enterprise scope to use this endpoint.

“Get GitHub Actions cache usage policy for an enterprise”的细粒度访问令牌

此端点支持以下精细令牌类型:

精细令牌必须具有以下权限集:

  • "Enterprise administration" business permissions (write)

“Get GitHub Actions cache usage policy for an enterprise”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
enterprise string 必须

The slug version of the enterprise name. You can also substitute this value with the enterprise id.

“Get GitHub Actions cache usage policy for an enterprise”的 HTTP 响应状态代码

状态代码说明
200

OK

“Get GitHub Actions cache usage policy for an enterprise”的示例代码

请求示例

get/enterprises/{enterprise}/actions/cache/usage-policy
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ http(s)://HOSTNAME/api/v3/enterprises/ENTERPRISE/actions/cache/usage-policy

Response

Status: 200
{ "repo_cache_size_limit_in_gb": 10, "max_repo_cache_size_limit_in_gb": 15 }

Set GitHub Actions cache usage policy for an enterprise

Sets the GitHub Actions cache usage policy for an enterprise.

OAuth app tokens and personal access tokens (classic) need the admin:enterprise scope to use this endpoint.

“Set GitHub Actions cache usage policy for an enterprise”的细粒度访问令牌

此端点支持以下精细令牌类型:

精细令牌必须具有以下权限集:

  • "Enterprise administration" business permissions (write)

“Set GitHub Actions cache usage policy for an enterprise”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
enterprise string 必须

The slug version of the enterprise name. You can also substitute this value with the enterprise id.

正文参数
名称, 类型, 说明
repo_cache_size_limit_in_gb integer

For repositories in an enterprise, the default size limit for the sum of all caches in a repository, in gigabytes.

max_repo_cache_size_limit_in_gb integer

For repositories in an enterprise, the maximum value that can be set as the limit for the sum of all caches in a repository, in gigabytes.

“Set GitHub Actions cache usage policy for an enterprise”的 HTTP 响应状态代码

状态代码说明
204

No Content

“Set GitHub Actions cache usage policy for an enterprise”的示例代码

请求示例

patch/enterprises/{enterprise}/actions/cache/usage-policy
curl -L \ -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ http(s)://HOSTNAME/api/v3/enterprises/ENTERPRISE/actions/cache/usage-policy \ -d '{"repo_cache_size_limit_in_gb":10,"max_repo_cache_size_limit_in_gb":15}'

Response

Status: 204

Get GitHub Actions cache usage for an organization

Gets the total GitHub Actions cache usage for an organization. The data fetched using this API is refreshed approximately every 5 minutes, so values returned from this endpoint may take at least 5 minutes to get updated.

OAuth tokens and personal access tokens (classic) need the read:org scope to use this endpoint.

“Get GitHub Actions cache usage for an organization”的细粒度访问令牌

此端点支持以下精细令牌类型:

精细令牌必须具有以下权限集:

  • "Administration" organization permissions (read)

“Get GitHub Actions cache usage for an organization”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
org string 必须

The organization name. The name is not case sensitive.

“Get GitHub Actions cache usage for an organization”的 HTTP 响应状态代码

状态代码说明
200

OK

“Get GitHub Actions cache usage for an organization”的示例代码

请求示例

get/orgs/{org}/actions/cache/usage
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ http(s)://HOSTNAME/api/v3/orgs/ORG/actions/cache/usage

Response

Status: 200
{ "total_active_caches_size_in_bytes": 3344284, "total_active_caches_count": 5 }

List repositories with GitHub Actions cache usage for an organization

Lists repositories and their GitHub Actions cache usage for an organization. The data fetched using this API is refreshed approximately every 5 minutes, so values returned from this endpoint may take at least 5 minutes to get updated.

OAuth tokens and personal access tokens (classic) need the read:org scope to use this endpoint.

“List repositories with GitHub Actions cache usage for an organization”的细粒度访问令牌

此端点支持以下精细令牌类型:

精细令牌必须具有以下权限集:

  • "Administration" organization permissions (read)

“List repositories with GitHub Actions cache usage for an organization”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
org string 必须

The organization name. The name is not case sensitive.

查询参数
名称, 类型, 说明
per_page integer

The number of results per page (max 100). For more information, see "Using pagination in the REST API."

默认: 30

page integer

The page number of the results to fetch. For more information, see "Using pagination in the REST API."

默认: 1

“List repositories with GitHub Actions cache usage for an organization”的 HTTP 响应状态代码

状态代码说明
200

OK

“List repositories with GitHub Actions cache usage for an organization”的示例代码

请求示例

get/orgs/{org}/actions/cache/usage-by-repository
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ http(s)://HOSTNAME/api/v3/orgs/ORG/actions/cache/usage-by-repository

Response

Status: 200
{ "total_count": 2, "repository_cache_usages": [ { "full_name": "octo-org/Hello-World", "active_caches_size_in_bytes": 2322142, "active_caches_count": 3 }, { "full_name": "octo-org/server", "active_caches_size_in_bytes": 1022142, "active_caches_count": 2 } ] }

Get GitHub Actions cache usage for a repository

Gets GitHub Actions cache usage for a repository. The data fetched using this API is refreshed approximately every 5 minutes, so values returned from this endpoint may take at least 5 minutes to get updated.

Anyone with read access to the repository can use this endpoint.

If the repository is private, OAuth tokens and personal access tokens (classic) need the repo scope to use this endpoint.

“Get GitHub Actions cache usage for a repository”的细粒度访问令牌

此端点支持以下精细令牌类型:

精细令牌必须具有以下权限集:

  • "Actions" repository permissions (read)

如果仅请求公共资源,则无需身份验证或上述权限即可使用此终结点。

“Get GitHub Actions cache usage for a repository”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
owner string 必须

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

repo string 必须

The name of the repository without the .git extension. The name is not case sensitive.

“Get GitHub Actions cache usage for a repository”的 HTTP 响应状态代码

状态代码说明
200

OK

“Get GitHub Actions cache usage for a repository”的示例代码

请求示例

get/repos/{owner}/{repo}/actions/cache/usage
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/actions/cache/usage

Response

Status: 200
{ "full_name": "octo-org/Hello-World", "active_caches_size_in_bytes": 2322142, "active_caches_count": 3 }

Get GitHub Actions cache usage policy for a repository

Gets GitHub Actions cache usage policy for a repository.

OAuth tokens and personal access tokens (classic) need the repo scope to use this endpoint.

“Get GitHub Actions cache usage policy for a repository”的细粒度访问令牌

此端点支持以下精细令牌类型:

精细令牌必须具有以下权限集:

  • "Actions" repository permissions (read)

如果仅请求公共资源,则无需身份验证或上述权限即可使用此终结点。

“Get GitHub Actions cache usage policy for a repository”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
owner string 必须

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

repo string 必须

The name of the repository without the .git extension. The name is not case sensitive.

“Get GitHub Actions cache usage policy for a repository”的 HTTP 响应状态代码

状态代码说明
200

OK

“Get GitHub Actions cache usage policy for a repository”的示例代码

请求示例

get/repos/{owner}/{repo}/actions/cache/usage-policy
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/actions/cache/usage-policy

Response

Status: 200
{ "repo_cache_size_limit_in_gb": 14 }

Set GitHub Actions cache usage policy for a repository

Sets GitHub Actions cache usage policy for a repository.

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.

“Set GitHub Actions cache usage policy for a repository”的细粒度访问令牌

此端点支持以下精细令牌类型:

精细令牌必须具有以下权限集:

  • "Administration" repository permissions (write)

“Set GitHub Actions cache usage policy for a repository”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
owner string 必须

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

repo string 必须

The name of the repository without the .git extension. The name is not case sensitive.

正文参数
名称, 类型, 说明
repo_cache_size_limit_in_gb integer 必须

The size limit for the sum of all caches, in gigabytes.

“Set GitHub Actions cache usage policy for a repository”的 HTTP 响应状态代码

状态代码说明
204

No Content

“Set GitHub Actions cache usage policy for a repository”的示例代码

请求示例

patch/repos/{owner}/{repo}/actions/cache/usage-policy
curl -L \ -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/actions/cache/usage-policy \ -d '{"repo_cache_size_limit_in_gb":14}'

Response

Status: 204

List GitHub Actions caches for a repository

Lists the GitHub Actions caches for a repository.

OAuth tokens and personal access tokens (classic) need the repo scope to use this endpoint.

“List GitHub Actions caches for a repository”的细粒度访问令牌

此端点支持以下精细令牌类型:

精细令牌必须具有以下权限集:

  • "Actions" repository permissions (read)

如果仅请求公共资源,则无需身份验证或上述权限即可使用此终结点。

“List GitHub Actions caches for a repository”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
owner string 必须

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

repo string 必须

The name of the repository without the .git extension. The name is not case sensitive.

查询参数
名称, 类型, 说明
per_page integer

The number of results per page (max 100). For more information, see "Using pagination in the REST API."

默认: 30

page integer

The page number of the results to fetch. For more information, see "Using pagination in the REST API."

默认: 1

ref string

The full Git reference for narrowing down the cache. The ref for a branch should be formatted as refs/heads/<branch name>. To reference a pull request use refs/pull/<number>/merge.

key string

An explicit key or prefix for identifying the cache

sort string

The property to sort the results by. created_at means when the cache was created. last_accessed_at means when the cache was last accessed. size_in_bytes is the size of the cache in bytes.

默认: last_accessed_at

可以是以下选项之一: created_at, last_accessed_at, size_in_bytes

direction string

The direction to sort the results by.

默认: desc

可以是以下选项之一: asc, desc

“List GitHub Actions caches for a repository”的 HTTP 响应状态代码

状态代码说明
200

OK

“List GitHub Actions caches for a repository”的示例代码

请求示例

get/repos/{owner}/{repo}/actions/caches
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/actions/caches

Response

Status: 200
{ "total_count": 1, "actions_caches": [ { "id": 505, "ref": "refs/heads/main", "key": "Linux-node-958aff96db2d75d67787d1e634ae70b659de937b", "version": "73885106f58cc52a7df9ec4d4a5622a5614813162cb516c759a30af6bf56e6f0", "last_accessed_at": "2019-01-24T22:45:36.000Z", "created_at": "2019-01-24T22:45:36.000Z", "size_in_bytes": 1024 } ] }

Delete GitHub Actions caches for a repository (using a cache key)

Deletes one or more GitHub Actions caches for a repository, using a complete cache key. By default, all caches that match the provided key are deleted, but you can optionally provide a Git ref to restrict deletions to caches that match both the provided key and the Git ref.

OAuth tokens and personal access tokens (classic) need the repo scope to use this endpoint.

“Delete GitHub Actions caches for a repository (using a cache key)”的细粒度访问令牌

此端点支持以下精细令牌类型:

精细令牌必须具有以下权限集:

  • "Actions" repository permissions (write)

“Delete GitHub Actions caches for a repository (using a cache key)”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
owner string 必须

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

repo string 必须

The name of the repository without the .git extension. The name is not case sensitive.

查询参数
名称, 类型, 说明
key string 必须

A key for identifying the cache.

ref string

The full Git reference for narrowing down the cache. The ref for a branch should be formatted as refs/heads/<branch name>. To reference a pull request use refs/pull/<number>/merge.

“Delete GitHub Actions caches for a repository (using a cache key)”的 HTTP 响应状态代码

状态代码说明
200

OK

“Delete GitHub Actions caches for a repository (using a cache key)”的示例代码

请求示例

delete/repos/{owner}/{repo}/actions/caches
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ "http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/actions/caches?key=Linux-node-958aff96db2d75d67787d1e634ae70b659de937b"

Response

Status: 200
{ "total_count": 1, "actions_caches": [ { "id": 505, "ref": "refs/heads/main", "key": "Linux-node-958aff96db2d75d67787d1e634ae70b659de937b", "version": "73885106f58cc52a7df9ec4d4a5622a5614813162cb516c759a30af6bf56e6f0", "last_accessed_at": "2019-01-24T22:45:36.000Z", "created_at": "2019-01-24T22:45:36.000Z", "size_in_bytes": 1024 } ] }

Delete a GitHub Actions cache for a repository (using a cache ID)

Deletes a GitHub Actions cache for a repository, using a cache ID.

OAuth tokens and personal access tokens (classic) need the repo scope to use this endpoint.

“Delete a GitHub Actions cache for a repository (using a cache ID)”的细粒度访问令牌

此端点支持以下精细令牌类型:

精细令牌必须具有以下权限集:

  • "Actions" repository permissions (write)

“Delete a GitHub Actions cache for a repository (using a cache ID)”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
owner string 必须

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

repo string 必须

The name of the repository without the .git extension. The name is not case sensitive.

cache_id integer 必须

The unique identifier of the GitHub Actions cache.

“Delete a GitHub Actions cache for a repository (using a cache ID)”的 HTTP 响应状态代码

状态代码说明
204

No Content

“Delete a GitHub Actions cache for a repository (using a cache ID)”的示例代码

请求示例

delete/repos/{owner}/{repo}/actions/caches/{cache_id}
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/actions/caches/CACHE_ID

Response

Status: 204