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

Deletes a GitHub Actions cache for a repository, using a cache ID. 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.

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 367 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Delete a GitHub Actions cache for a repository (using a cache ID)
6
 * Deletes a GitHub Actions cache for a repository, using a cache ID.
7

8
You must authenticate using an access token with the `repo` scope to use this endpoint.
9

10
GitHub Apps must have the `actions:write` permission to use this endpoint.
11
 */
12
export async function main(
13
  auth: Github,
14
  owner: string,
15
  repo: string,
16
  cache_id: string
17
) {
18
  const url = new URL(
19
    `https://api.github.com/repos/${owner}/${repo}/actions/caches/${cache_id}`
20
  );
21

22
  const response = await fetch(url, {
23
    method: "DELETE",
24
    headers: {
25
      Authorization: "Bearer " + auth.token,
26
    },
27
    body: undefined,
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.text();
34
}
35