Skip to content

Commit

Permalink
feat(github-actions-usage): Add view_github_actions SQL view
Browse files Browse the repository at this point in the history
This view shows the archived status of a repository, the name of the Action being used, and the version.
  • Loading branch information
akash1810 committed Feb 23, 2024
1 parent 55c6739 commit e4fb0d2
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,27 @@ CREATE TABLE guardian_github_actions_usage (
);

CREATE UNIQUE INDEX guardian_github_actions_usage_full_name_key ON guardian_github_actions_usage(full_name, workflow_path);

DROP VIEW IF EXISTS view_github_actions;

CREATE VIEW view_github_actions AS
WITH data AS (
SELECT tbl.evaluated_on
, tbl.full_name
, tbl.workflow_path
, use_string AS action
, split_part(use_string, '@', 1) AS action_name -- after splitting, take the first item
, split_part(use_string, '@', -1) AS version -- after splitting, take the last item
FROM guardian_github_actions_usage tbl
, unnest(tbl.workflow_uses) AS use_string -- expand the string array into rows, e.g. an array of 2 items becomes 2 rows
)

SELECT d.evaluated_on
, d.full_name
, r.archived
, d.workflow_path
, d.action
, d.action_name
, d.version
FROM data d
JOIN github_repositories r ON d.full_name = r.full_name;
13 changes: 13 additions & 0 deletions packages/common/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -690,3 +690,16 @@ view view_snyk_project_tags {
@@ignore
}

/// The underlying view does not contain a valid unique identifier and can therefore currently not be handled by Prisma Client.
view view_github_actions {
evaluated_on DateTime?
full_name String?
archived Boolean?
workflow_path String?
action String?
action_name String?
version String?
@@ignore
}
25 changes: 25 additions & 0 deletions packages/common/prisma/views/public/view_github_actions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
WITH data AS (
SELECT
tbl.evaluated_on,
tbl.full_name,
tbl.workflow_path,
use_string.use_string AS ACTION,
split_part(use_string.use_string, '@' :: text, 1) AS action_name,
split_part(use_string.use_string, '@' :: text, '-1' :: integer) AS version
FROM
guardian_github_actions_usage tbl,
LATERAL unnest(tbl.workflow_uses) use_string(use_string)
)
SELECT
d.evaluated_on,
d.full_name,
r.archived,
d.workflow_path,
d.action,
d.action_name,
d.version
FROM
(
data d
JOIN github_repositories r ON ((d.full_name = r.full_name))
);
7 changes: 7 additions & 0 deletions packages/github-actions-usage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ This app, deployed as an AWS Lambda, tracks which GitHub Actions are in use acro
3. Extract the `uses` string from the `contents`
4. Save results to database

## Querying the data
This lambda writes to the [`github_actions_usage` table](../common/prisma/migrations/20240222201635_guardian_github_actions_usage/migration.sql).

The [`view_github_actions` SQL view](../common/prisma/migrations/20240222201635_guardian_github_actions_usage/migration.sql) also exists
to make it easier to query the data.
This view shows the archived status of a repository, the name of the Action being used, and the version.

## Updating the schema
The [schema](./src/schema/github-workflow.json) might need updating from time to time.

Expand Down

0 comments on commit e4fb0d2

Please sign in to comment.