Skip to content

Instantly share code, notes, and snippets.

@tonyelhabr
Last active July 9, 2024 00:14
Show Gist options
  • Save tonyelhabr/25ade89d541d43b00f17bfc3a0bc984f to your computer and use it in GitHub Desktop.
Save tonyelhabr/25ade89d541d43b00f17bfc3a0bc984f to your computer and use it in GitHub Desktop.
Delete GitHub action run logs
library(gh)
library(purrr)
library(dplyr)

token <- Sys.getenv("GITHUB_PAT")
REPO <- "my-repo"
OWNER <- "me"

runs <- gh::gh(
  "GET /repos/:owner/:repo/actions/runs",
  .limit = Inf,
  owner = OWNER,
  repo = REPO,
  .token = token
)

run_ids <- runs$workflow_runs |> 
  purrr::map(
    \(.x) {
      list(
        id = as.character(.x$id),
        display_title = .x$display_title,
        status = .x$status,
        conclusion = .x$conclusion
      )
    } 
  ) |> 
  dplyr::bind_rows()

res <- run_ids |> 
  dplyr::filter(conclusion == 'failure') |> 
  dplyr::pull(id) |> 
  purrr::walk(
    \(.x) {
      gh::gh(
        paste0("DELETE /repos/:owner/:repo/actions/runs/", .x),
        owner = OWNER,
        repo = REPO,
        .token = token
      )
    }
  )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment