Skip to content

Commit d64914e

Browse files
authored
Add table github_actions_cache (#557)
1 parent 78680cc commit d64914e

3 files changed

Lines changed: 200 additions & 0 deletions

File tree

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
title: "Steampipe Table: github_actions_cache - Query GitHub Actions Caches using SQL"
3+
description: "Allows users to query GitHub Actions Caches, providing insights into the caches generated by GitHub Actions workflows."
4+
folder: "Actions"
5+
---
6+
7+
# Table: github_actions_cache - Query GitHub Actions Caches using SQL
8+
9+
GitHub Actions Caches are the files created to persist data to re-use in your workflows. These caches allow you to persist data after a job has completed and share that data with another job in the same workflow.
10+
11+
## Table Usage Guide
12+
13+
The `github_actions_cache` table provides insights into caches generated by GitHub Actions workflows. As a software developer or DevOps engineer, explore cache-specific details through this table, including metadata, size, versions, and timestamps.
14+
15+
To query this table using a [fine-grained access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token), the following permissions are required:
16+
- Repository permissions:
17+
- Actions (Read-only): Required to access all columns.
18+
- Metadata (Read-only): Required to access general repository metadata.
19+
20+
**Important Notes**
21+
- You must specify the `repository_full_name` column in `where` or `join` clause to query the table.
22+
23+
## Examples
24+
25+
### List caches
26+
Explore which caches are associated with the 'turbot/steampipe' repository on GitHub. This can be useful for developers needing to understand or manage the resources related to this specific project.
27+
28+
```sql+postgres
29+
select
30+
*
31+
from
32+
github_actions_cache
33+
where
34+
repository_full_name = 'turbot/steampipe';
35+
```
36+
37+
```sql+sqlite
38+
select
39+
*
40+
from
41+
github_actions_cache
42+
where
43+
repository_full_name = 'turbot/steampipe';
44+
```
45+
46+
### List caches on branch
47+
Discover the caches within a specific repository on a branch, which is useful in scenarios where you need to track and manage these caches for ongoing workflows.
48+
49+
```sql+postgres
50+
select
51+
id,
52+
key,
53+
version,
54+
created_at,
55+
last_accessed_at,
56+
size_in_bytes
57+
from
58+
github_actions_cache
59+
where
60+
repository_full_name = 'turbot/steampipe'
61+
and ref = 'refs/heads/develop';
62+
```
63+
64+
```sql+sqlite
65+
select
66+
id,
67+
key,
68+
version,
69+
created_at,
70+
last_accessed_at,
71+
size_in_bytes
72+
from
73+
github_actions_cache
74+
where
75+
repository_full_name = 'turbot/steampipe'
76+
and ref = 'refs/heads/develop';
77+
```
78+
79+
### List caches matching key regex
80+
Discover the caches that match a pattern based on developer-defined key.
81+
82+
```sql+postgres
83+
select
84+
id,
85+
key,
86+
version,
87+
created_at,
88+
last_accessed_at,
89+
size_in_bytes
90+
from
91+
github_actions_cache
92+
where
93+
repository_full_name = 'turbot/steampipe'
94+
and key like 'codeql-%';
95+
```
96+
97+
```sql+sqlite
98+
select
99+
id,
100+
key,
101+
version,
102+
created_at,
103+
last_accessed_at,
104+
size_in_bytes
105+
from
106+
github_actions_cache
107+
where
108+
repository_full_name = 'turbot/steampipe'
109+
and key like 'codeql-%';
110+
```

github/plugin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
2424
DefaultRetryConfig: retryConfig(),
2525
TableMap: map[string]*plugin.Table{
2626
"github_actions_artifact": tableGitHubActionsArtifact(),
27+
"github_actions_cache": tableGitHubActionsCache(),
2728
"github_actions_environment_variable": tableGitHubActionsEnvironmentVariable(),
2829
"github_actions_organization_variable": tableGitHubActionsOrganizationVariable(),
2930
"github_actions_repository_runner": tableGitHubActionsRepositoryRunner(),
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package github
2+
3+
import (
4+
"context"
5+
6+
"github.com/google/go-github/v55/github"
7+
8+
"github.com/turbot/steampipe-plugin-sdk/v6/grpc/proto"
9+
"github.com/turbot/steampipe-plugin-sdk/v6/plugin"
10+
"github.com/turbot/steampipe-plugin-sdk/v6/plugin/transform"
11+
)
12+
13+
func tableGitHubActionsCache() *plugin.Table {
14+
return &plugin.Table{
15+
Name: "github_actions_cache",
16+
Description: "Caches are a built-in storage mechanism to speed up jobs in a workflow by persisting data for re-use.",
17+
List: &plugin.ListConfig{
18+
KeyColumns: []*plugin.KeyColumn{
19+
{Name: "repository_full_name", Require: plugin.Required},
20+
{Name: "key", Require: plugin.Optional},
21+
{Name: "ref", Require: plugin.Optional},
22+
},
23+
ShouldIgnoreError: isNotFoundError([]string{"404"}),
24+
Hydrate: tableGitHubCacheList,
25+
},
26+
Columns: commonColumns([]*plugin.Column{
27+
// Top columns
28+
{Name: "repository_full_name", Type: proto.ColumnType_STRING, Transform: transform.FromQual("repository_full_name"), Description: "Full name of the repository that contains the cache."},
29+
{Name: "id", Type: proto.ColumnType_INT, Description: "Unique ID of the cache."},
30+
{Name: "key", Type: proto.ColumnType_STRING, Description: "Developer-defined string identifier of the cache."},
31+
32+
// Other columns
33+
{Name: "ref", Type: proto.ColumnType_STRING, Description: "The git reference of the cache."},
34+
{Name: "version", Type: proto.ColumnType_STRING, Description: "Hash generated from combination of compression tool, runner OS, and path."},
35+
{Name: "last_accessed_at", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("LastAccessedAt").Transform(convertTimestamp), Description: "Time of the most recent cache access."},
36+
{Name: "created_at", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("CreatedAt").Transform(convertTimestamp), Description: "Time when the cache was created."},
37+
{Name: "size_in_bytes", Type: proto.ColumnType_INT, Description: "Size of the cache in bytes."},
38+
}),
39+
}
40+
}
41+
42+
func tableGitHubCacheList(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
43+
client := connect(ctx, d)
44+
45+
fullName := d.EqualsQuals["repository_full_name"].GetStringValue()
46+
owner, repo := parseRepoFullName(fullName)
47+
opts := &github.ActionsCacheListOptions{
48+
ListOptions: github.ListOptions{PerPage: 100},
49+
}
50+
if key := d.EqualsQualString("key"); key != "" {
51+
opts.Key = github.String(key)
52+
}
53+
if ref := d.EqualsQualString("ref"); ref != "" {
54+
opts.Ref = github.String(ref)
55+
}
56+
57+
limit := d.QueryContext.Limit
58+
if limit != nil {
59+
if *limit < int64(opts.PerPage) {
60+
opts.PerPage = int(*limit)
61+
}
62+
}
63+
64+
for {
65+
caches, resp, err := client.Actions.ListCaches(ctx, owner, repo, opts)
66+
if err != nil {
67+
return nil, err
68+
}
69+
70+
for _, i := range caches.ActionsCaches {
71+
if i != nil {
72+
d.StreamListItem(ctx, i)
73+
}
74+
75+
// Context can be cancelled due to manual cancellation or the limit has been hit
76+
if d.RowsRemaining(ctx) == 0 {
77+
return nil, nil
78+
}
79+
}
80+
81+
if resp.NextPage == 0 {
82+
break
83+
}
84+
85+
opts.Page = resp.NextPage
86+
}
87+
88+
return nil, nil
89+
}

0 commit comments

Comments
 (0)