tenseleyflow/shithub / ea43f03

Browse files

actions/sqlc: expose run detail selectors (S41f)

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
ea43f03d4f5a3f8cfb007122e52d7c878d194c3e
Parents
cabd341
Tree
26b59f4

9 changed files

StatusFile+-
M internal/actions/queries/workflow_jobs.sql 1 1
M internal/actions/queries/workflow_runs.sql 11 0
M internal/actions/queries/workflow_step_log_chunks.sql 6 0
M internal/actions/queries/workflow_steps.sql 2 2
M internal/actions/sqlc/querier.go 2 0
M internal/actions/sqlc/workflow_jobs.sql.go 5 1
M internal/actions/sqlc/workflow_runs.sql.go 76 0
M internal/actions/sqlc/workflow_step_log_chunks.sql.go 33 0
M internal/actions/sqlc/workflow_steps.sql.go 6 2
internal/actions/queries/workflow_jobs.sqlmodified
@@ -85,7 +85,7 @@ JOIN workflow_runs r ON r.id = c.run_id;
8585
 
8686
 -- name: ListJobsForRun :many
8787
 SELECT id, run_id, job_index, job_key, job_name, runs_on, status,
88
-       conclusion, started_at, completed_at, created_at
88
+       conclusion, needs_jobs, started_at, completed_at, created_at, updated_at
8989
 FROM workflow_jobs
9090
 WHERE run_id = $1
9191
 ORDER BY job_index ASC;
internal/actions/queries/workflow_runs.sqlmodified
@@ -62,6 +62,17 @@ SELECT id, repo_id, run_index, workflow_file, workflow_name,
6262
 FROM workflow_runs
6363
 WHERE id = $1;
6464
 
65
+-- name: GetWorkflowRunForRepoByIndex :one
66
+SELECT r.id, r.repo_id, r.run_index, r.workflow_file, r.workflow_name,
67
+       r.head_sha, r.head_ref, r.event, r.event_payload,
68
+       r.actor_user_id, COALESCE(u.username::text, '')::text AS actor_username,
69
+       r.parent_run_id, r.concurrency_group,
70
+       r.status, r.conclusion, r.pinned, r.need_approval, r.approved_by_user_id,
71
+       r.started_at, r.completed_at, r.version, r.created_at, r.updated_at, r.trigger_event_id
72
+FROM workflow_runs r
73
+LEFT JOIN users u ON u.id = r.actor_user_id
74
+WHERE r.repo_id = $1 AND r.run_index = $2;
75
+
6576
 -- name: MarkWorkflowRunRunning :exec
6677
 UPDATE workflow_runs
6778
 SET status = 'running',
internal/actions/queries/workflow_step_log_chunks.sqlmodified
@@ -13,6 +13,12 @@ WHERE step_id = $1 AND seq > $2
1313
 ORDER BY seq ASC
1414
 LIMIT $3;
1515
 
16
+-- name: ListAllStepLogChunksForStep :many
17
+SELECT id, step_id, seq, chunk, created_at
18
+FROM workflow_step_log_chunks
19
+WHERE step_id = $1
20
+ORDER BY seq ASC;
21
+
1622
 -- name: GetStepLogChunkBefore :one
1723
 SELECT id, step_id, seq, chunk, created_at
1824
 FROM workflow_step_log_chunks
internal/actions/queries/workflow_steps.sqlmodified
@@ -73,8 +73,8 @@ LIMIT 1;
7373
 
7474
 -- name: ListStepsForJob :many
7575
 SELECT id, job_id, step_index, step_id, step_name, run_command,
76
-       uses_alias, status, conclusion, log_byte_count,
77
-       started_at, completed_at, created_at
76
+       uses_alias, status, conclusion, log_object_key, log_byte_count,
77
+       started_at, completed_at, created_at, updated_at
7878
 FROM workflow_steps
7979
 WHERE job_id = $1
8080
 ORDER BY step_index ASC;
internal/actions/sqlc/querier.gomodified
@@ -48,6 +48,7 @@ type Querier interface {
4848
 	GetWorkflowJobByID(ctx context.Context, db DBTX, id int64) (WorkflowJob, error)
4949
 	GetWorkflowJobSecretMask(ctx context.Context, db DBTX, jobID int64) (WorkflowJobSecretMask, error)
5050
 	GetWorkflowRunByID(ctx context.Context, db DBTX, id int64) (WorkflowRun, error)
51
+	GetWorkflowRunForRepoByIndex(ctx context.Context, db DBTX, arg GetWorkflowRunForRepoByIndexParams) (GetWorkflowRunForRepoByIndexRow, error)
5152
 	GetWorkflowStepByID(ctx context.Context, db DBTX, id int64) (WorkflowStep, error)
5253
 	HeartbeatRunner(ctx context.Context, db DBTX, arg HeartbeatRunnerParams) (WorkflowRunner, error)
5354
 	// SPDX-License-Identifier: AGPL-3.0-or-later
@@ -61,6 +62,7 @@ type Querier interface {
6162
 	InsertWorkflowRun(ctx context.Context, db DBTX, arg InsertWorkflowRunParams) (WorkflowRun, error)
6263
 	// SPDX-License-Identifier: AGPL-3.0-or-later
6364
 	InsertWorkflowStep(ctx context.Context, db DBTX, arg InsertWorkflowStepParams) (WorkflowStep, error)
65
+	ListAllStepLogChunksForStep(ctx context.Context, db DBTX, stepID int64) ([]WorkflowStepLogChunk, error)
6466
 	ListArtifactsForRun(ctx context.Context, db DBTX, runID int64) ([]ListArtifactsForRunRow, error)
6567
 	ListJobsForRun(ctx context.Context, db DBTX, runID int64) ([]ListJobsForRunRow, error)
6668
 	ListOrgSecrets(ctx context.Context, db DBTX, orgID pgtype.Int8) ([]ListOrgSecretsRow, error)
internal/actions/sqlc/workflow_jobs.sql.gomodified
@@ -247,7 +247,7 @@ func (q *Queries) InsertWorkflowJob(ctx context.Context, db DBTX, arg InsertWork
247247
 
248248
 const listJobsForRun = `-- name: ListJobsForRun :many
249249
 SELECT id, run_id, job_index, job_key, job_name, runs_on, status,
250
-       conclusion, started_at, completed_at, created_at
250
+       conclusion, needs_jobs, started_at, completed_at, created_at, updated_at
251251
 FROM workflow_jobs
252252
 WHERE run_id = $1
253253
 ORDER BY job_index ASC
@@ -262,9 +262,11 @@ type ListJobsForRunRow struct {
262262
 	RunsOn      string
263263
 	Status      WorkflowJobStatus
264264
 	Conclusion  NullCheckConclusion
265
+	NeedsJobs   []string
265266
 	StartedAt   pgtype.Timestamptz
266267
 	CompletedAt pgtype.Timestamptz
267268
 	CreatedAt   pgtype.Timestamptz
269
+	UpdatedAt   pgtype.Timestamptz
268270
 }
269271
 
270272
 func (q *Queries) ListJobsForRun(ctx context.Context, db DBTX, runID int64) ([]ListJobsForRunRow, error) {
@@ -285,9 +287,11 @@ func (q *Queries) ListJobsForRun(ctx context.Context, db DBTX, runID int64) ([]L
285287
 			&i.RunsOn,
286288
 			&i.Status,
287289
 			&i.Conclusion,
290
+			&i.NeedsJobs,
288291
 			&i.StartedAt,
289292
 			&i.CompletedAt,
290293
 			&i.CreatedAt,
294
+			&i.UpdatedAt,
291295
 		); err != nil {
292296
 			return nil, err
293297
 		}
internal/actions/sqlc/workflow_runs.sql.gomodified
@@ -230,6 +230,82 @@ func (q *Queries) GetWorkflowRunByID(ctx context.Context, db DBTX, id int64) (Wo
230230
 	return i, err
231231
 }
232232
 
233
+const getWorkflowRunForRepoByIndex = `-- name: GetWorkflowRunForRepoByIndex :one
234
+SELECT r.id, r.repo_id, r.run_index, r.workflow_file, r.workflow_name,
235
+       r.head_sha, r.head_ref, r.event, r.event_payload,
236
+       r.actor_user_id, COALESCE(u.username::text, '')::text AS actor_username,
237
+       r.parent_run_id, r.concurrency_group,
238
+       r.status, r.conclusion, r.pinned, r.need_approval, r.approved_by_user_id,
239
+       r.started_at, r.completed_at, r.version, r.created_at, r.updated_at, r.trigger_event_id
240
+FROM workflow_runs r
241
+LEFT JOIN users u ON u.id = r.actor_user_id
242
+WHERE r.repo_id = $1 AND r.run_index = $2
243
+`
244
+
245
+type GetWorkflowRunForRepoByIndexParams struct {
246
+	RepoID   int64
247
+	RunIndex int64
248
+}
249
+
250
+type GetWorkflowRunForRepoByIndexRow struct {
251
+	ID               int64
252
+	RepoID           int64
253
+	RunIndex         int64
254
+	WorkflowFile     string
255
+	WorkflowName     string
256
+	HeadSha          string
257
+	HeadRef          string
258
+	Event            WorkflowRunEvent
259
+	EventPayload     []byte
260
+	ActorUserID      pgtype.Int8
261
+	ActorUsername    string
262
+	ParentRunID      pgtype.Int8
263
+	ConcurrencyGroup string
264
+	Status           WorkflowRunStatus
265
+	Conclusion       NullCheckConclusion
266
+	Pinned           bool
267
+	NeedApproval     bool
268
+	ApprovedByUserID pgtype.Int8
269
+	StartedAt        pgtype.Timestamptz
270
+	CompletedAt      pgtype.Timestamptz
271
+	Version          int32
272
+	CreatedAt        pgtype.Timestamptz
273
+	UpdatedAt        pgtype.Timestamptz
274
+	TriggerEventID   string
275
+}
276
+
277
+func (q *Queries) GetWorkflowRunForRepoByIndex(ctx context.Context, db DBTX, arg GetWorkflowRunForRepoByIndexParams) (GetWorkflowRunForRepoByIndexRow, error) {
278
+	row := db.QueryRow(ctx, getWorkflowRunForRepoByIndex, arg.RepoID, arg.RunIndex)
279
+	var i GetWorkflowRunForRepoByIndexRow
280
+	err := row.Scan(
281
+		&i.ID,
282
+		&i.RepoID,
283
+		&i.RunIndex,
284
+		&i.WorkflowFile,
285
+		&i.WorkflowName,
286
+		&i.HeadSha,
287
+		&i.HeadRef,
288
+		&i.Event,
289
+		&i.EventPayload,
290
+		&i.ActorUserID,
291
+		&i.ActorUsername,
292
+		&i.ParentRunID,
293
+		&i.ConcurrencyGroup,
294
+		&i.Status,
295
+		&i.Conclusion,
296
+		&i.Pinned,
297
+		&i.NeedApproval,
298
+		&i.ApprovedByUserID,
299
+		&i.StartedAt,
300
+		&i.CompletedAt,
301
+		&i.Version,
302
+		&i.CreatedAt,
303
+		&i.UpdatedAt,
304
+		&i.TriggerEventID,
305
+	)
306
+	return i, err
307
+}
308
+
233309
 const insertWorkflowRun = `-- name: InsertWorkflowRun :one
234310
 
235311
 INSERT INTO workflow_runs (
internal/actions/sqlc/workflow_step_log_chunks.sql.gomodified
@@ -104,6 +104,39 @@ func (q *Queries) GetStepLogChunkByStepSeq(ctx context.Context, db DBTX, arg Get
104104
 	return i, err
105105
 }
106106
 
107
+const listAllStepLogChunksForStep = `-- name: ListAllStepLogChunksForStep :many
108
+SELECT id, step_id, seq, chunk, created_at
109
+FROM workflow_step_log_chunks
110
+WHERE step_id = $1
111
+ORDER BY seq ASC
112
+`
113
+
114
+func (q *Queries) ListAllStepLogChunksForStep(ctx context.Context, db DBTX, stepID int64) ([]WorkflowStepLogChunk, error) {
115
+	rows, err := db.Query(ctx, listAllStepLogChunksForStep, stepID)
116
+	if err != nil {
117
+		return nil, err
118
+	}
119
+	defer rows.Close()
120
+	items := []WorkflowStepLogChunk{}
121
+	for rows.Next() {
122
+		var i WorkflowStepLogChunk
123
+		if err := rows.Scan(
124
+			&i.ID,
125
+			&i.StepID,
126
+			&i.Seq,
127
+			&i.Chunk,
128
+			&i.CreatedAt,
129
+		); err != nil {
130
+			return nil, err
131
+		}
132
+		items = append(items, i)
133
+	}
134
+	if err := rows.Err(); err != nil {
135
+		return nil, err
136
+	}
137
+	return items, nil
138
+}
139
+
107140
 const listStepLogChunks = `-- name: ListStepLogChunks :many
108141
 SELECT id, step_id, seq, chunk, created_at
109142
 FROM workflow_step_log_chunks
internal/actions/sqlc/workflow_steps.sql.gomodified
@@ -235,8 +235,8 @@ func (q *Queries) ListRunnerStepsForJob(ctx context.Context, db DBTX, jobID int6
235235
 
236236
 const listStepsForJob = `-- name: ListStepsForJob :many
237237
 SELECT id, job_id, step_index, step_id, step_name, run_command,
238
-       uses_alias, status, conclusion, log_byte_count,
239
-       started_at, completed_at, created_at
238
+       uses_alias, status, conclusion, log_object_key, log_byte_count,
239
+       started_at, completed_at, created_at, updated_at
240240
 FROM workflow_steps
241241
 WHERE job_id = $1
242242
 ORDER BY step_index ASC
@@ -252,10 +252,12 @@ type ListStepsForJobRow struct {
252252
 	UsesAlias    string
253253
 	Status       WorkflowStepStatus
254254
 	Conclusion   NullCheckConclusion
255
+	LogObjectKey pgtype.Text
255256
 	LogByteCount int64
256257
 	StartedAt    pgtype.Timestamptz
257258
 	CompletedAt  pgtype.Timestamptz
258259
 	CreatedAt    pgtype.Timestamptz
260
+	UpdatedAt    pgtype.Timestamptz
259261
 }
260262
 
261263
 func (q *Queries) ListStepsForJob(ctx context.Context, db DBTX, jobID int64) ([]ListStepsForJobRow, error) {
@@ -277,10 +279,12 @@ func (q *Queries) ListStepsForJob(ctx context.Context, db DBTX, jobID int64) ([]
277279
 			&i.UsesAlias,
278280
 			&i.Status,
279281
 			&i.Conclusion,
282
+			&i.LogObjectKey,
280283
 			&i.LogByteCount,
281284
 			&i.StartedAt,
282285
 			&i.CompletedAt,
283286
 			&i.CreatedAt,
287
+			&i.UpdatedAt,
284288
 		); err != nil {
285289
 			return nil, err
286290
 		}