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;
85
 
85
 
86
 -- name: ListJobsForRun :many
86
 -- name: ListJobsForRun :many
87
 SELECT id, run_id, job_index, job_key, job_name, runs_on, status,
87
 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
89
 FROM workflow_jobs
89
 FROM workflow_jobs
90
 WHERE run_id = $1
90
 WHERE run_id = $1
91
 ORDER BY job_index ASC;
91
 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,
62
 FROM workflow_runs
62
 FROM workflow_runs
63
 WHERE id = $1;
63
 WHERE id = $1;
64
 
64
 
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
+
65
 -- name: MarkWorkflowRunRunning :exec
76
 -- name: MarkWorkflowRunRunning :exec
66
 UPDATE workflow_runs
77
 UPDATE workflow_runs
67
 SET status = 'running',
78
 SET status = 'running',
internal/actions/queries/workflow_step_log_chunks.sqlmodified
@@ -13,6 +13,12 @@ WHERE step_id = $1 AND seq > $2
13
 ORDER BY seq ASC
13
 ORDER BY seq ASC
14
 LIMIT $3;
14
 LIMIT $3;
15
 
15
 
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
+
16
 -- name: GetStepLogChunkBefore :one
22
 -- name: GetStepLogChunkBefore :one
17
 SELECT id, step_id, seq, chunk, created_at
23
 SELECT id, step_id, seq, chunk, created_at
18
 FROM workflow_step_log_chunks
24
 FROM workflow_step_log_chunks
internal/actions/queries/workflow_steps.sqlmodified
@@ -73,8 +73,8 @@ LIMIT 1;
73
 
73
 
74
 -- name: ListStepsForJob :many
74
 -- name: ListStepsForJob :many
75
 SELECT id, job_id, step_index, step_id, step_name, run_command,
75
 SELECT id, job_id, step_index, step_id, step_name, run_command,
76
-       uses_alias, status, conclusion, log_byte_count,
76
+       uses_alias, status, conclusion, log_object_key, log_byte_count,
77
-       started_at, completed_at, created_at
77
+       started_at, completed_at, created_at, updated_at
78
 FROM workflow_steps
78
 FROM workflow_steps
79
 WHERE job_id = $1
79
 WHERE job_id = $1
80
 ORDER BY step_index ASC;
80
 ORDER BY step_index ASC;
internal/actions/sqlc/querier.gomodified
@@ -48,6 +48,7 @@ type Querier interface {
48
 	GetWorkflowJobByID(ctx context.Context, db DBTX, id int64) (WorkflowJob, error)
48
 	GetWorkflowJobByID(ctx context.Context, db DBTX, id int64) (WorkflowJob, error)
49
 	GetWorkflowJobSecretMask(ctx context.Context, db DBTX, jobID int64) (WorkflowJobSecretMask, error)
49
 	GetWorkflowJobSecretMask(ctx context.Context, db DBTX, jobID int64) (WorkflowJobSecretMask, error)
50
 	GetWorkflowRunByID(ctx context.Context, db DBTX, id int64) (WorkflowRun, error)
50
 	GetWorkflowRunByID(ctx context.Context, db DBTX, id int64) (WorkflowRun, error)
51
+	GetWorkflowRunForRepoByIndex(ctx context.Context, db DBTX, arg GetWorkflowRunForRepoByIndexParams) (GetWorkflowRunForRepoByIndexRow, error)
51
 	GetWorkflowStepByID(ctx context.Context, db DBTX, id int64) (WorkflowStep, error)
52
 	GetWorkflowStepByID(ctx context.Context, db DBTX, id int64) (WorkflowStep, error)
52
 	HeartbeatRunner(ctx context.Context, db DBTX, arg HeartbeatRunnerParams) (WorkflowRunner, error)
53
 	HeartbeatRunner(ctx context.Context, db DBTX, arg HeartbeatRunnerParams) (WorkflowRunner, error)
53
 	// SPDX-License-Identifier: AGPL-3.0-or-later
54
 	// SPDX-License-Identifier: AGPL-3.0-or-later
@@ -61,6 +62,7 @@ type Querier interface {
61
 	InsertWorkflowRun(ctx context.Context, db DBTX, arg InsertWorkflowRunParams) (WorkflowRun, error)
62
 	InsertWorkflowRun(ctx context.Context, db DBTX, arg InsertWorkflowRunParams) (WorkflowRun, error)
62
 	// SPDX-License-Identifier: AGPL-3.0-or-later
63
 	// SPDX-License-Identifier: AGPL-3.0-or-later
63
 	InsertWorkflowStep(ctx context.Context, db DBTX, arg InsertWorkflowStepParams) (WorkflowStep, error)
64
 	InsertWorkflowStep(ctx context.Context, db DBTX, arg InsertWorkflowStepParams) (WorkflowStep, error)
65
+	ListAllStepLogChunksForStep(ctx context.Context, db DBTX, stepID int64) ([]WorkflowStepLogChunk, error)
64
 	ListArtifactsForRun(ctx context.Context, db DBTX, runID int64) ([]ListArtifactsForRunRow, error)
66
 	ListArtifactsForRun(ctx context.Context, db DBTX, runID int64) ([]ListArtifactsForRunRow, error)
65
 	ListJobsForRun(ctx context.Context, db DBTX, runID int64) ([]ListJobsForRunRow, error)
67
 	ListJobsForRun(ctx context.Context, db DBTX, runID int64) ([]ListJobsForRunRow, error)
66
 	ListOrgSecrets(ctx context.Context, db DBTX, orgID pgtype.Int8) ([]ListOrgSecretsRow, error)
68
 	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
247
 
247
 
248
 const listJobsForRun = `-- name: ListJobsForRun :many
248
 const listJobsForRun = `-- name: ListJobsForRun :many
249
 SELECT id, run_id, job_index, job_key, job_name, runs_on, status,
249
 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
251
 FROM workflow_jobs
251
 FROM workflow_jobs
252
 WHERE run_id = $1
252
 WHERE run_id = $1
253
 ORDER BY job_index ASC
253
 ORDER BY job_index ASC
@@ -262,9 +262,11 @@ type ListJobsForRunRow struct {
262
 	RunsOn      string
262
 	RunsOn      string
263
 	Status      WorkflowJobStatus
263
 	Status      WorkflowJobStatus
264
 	Conclusion  NullCheckConclusion
264
 	Conclusion  NullCheckConclusion
265
+	NeedsJobs   []string
265
 	StartedAt   pgtype.Timestamptz
266
 	StartedAt   pgtype.Timestamptz
266
 	CompletedAt pgtype.Timestamptz
267
 	CompletedAt pgtype.Timestamptz
267
 	CreatedAt   pgtype.Timestamptz
268
 	CreatedAt   pgtype.Timestamptz
269
+	UpdatedAt   pgtype.Timestamptz
268
 }
270
 }
269
 
271
 
270
 func (q *Queries) ListJobsForRun(ctx context.Context, db DBTX, runID int64) ([]ListJobsForRunRow, error) {
272
 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
285
 			&i.RunsOn,
287
 			&i.RunsOn,
286
 			&i.Status,
288
 			&i.Status,
287
 			&i.Conclusion,
289
 			&i.Conclusion,
290
+			&i.NeedsJobs,
288
 			&i.StartedAt,
291
 			&i.StartedAt,
289
 			&i.CompletedAt,
292
 			&i.CompletedAt,
290
 			&i.CreatedAt,
293
 			&i.CreatedAt,
294
+			&i.UpdatedAt,
291
 		); err != nil {
295
 		); err != nil {
292
 			return nil, err
296
 			return nil, err
293
 		}
297
 		}
internal/actions/sqlc/workflow_runs.sql.gomodified
@@ -230,6 +230,82 @@ func (q *Queries) GetWorkflowRunByID(ctx context.Context, db DBTX, id int64) (Wo
230
 	return i, err
230
 	return i, err
231
 }
231
 }
232
 
232
 
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
+
233
 const insertWorkflowRun = `-- name: InsertWorkflowRun :one
309
 const insertWorkflowRun = `-- name: InsertWorkflowRun :one
234
 
310
 
235
 INSERT INTO workflow_runs (
311
 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
104
 	return i, err
104
 	return i, err
105
 }
105
 }
106
 
106
 
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
+
107
 const listStepLogChunks = `-- name: ListStepLogChunks :many
140
 const listStepLogChunks = `-- name: ListStepLogChunks :many
108
 SELECT id, step_id, seq, chunk, created_at
141
 SELECT id, step_id, seq, chunk, created_at
109
 FROM workflow_step_log_chunks
142
 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
235
 
235
 
236
 const listStepsForJob = `-- name: ListStepsForJob :many
236
 const listStepsForJob = `-- name: ListStepsForJob :many
237
 SELECT id, job_id, step_index, step_id, step_name, run_command,
237
 SELECT id, job_id, step_index, step_id, step_name, run_command,
238
-       uses_alias, status, conclusion, log_byte_count,
238
+       uses_alias, status, conclusion, log_object_key, log_byte_count,
239
-       started_at, completed_at, created_at
239
+       started_at, completed_at, created_at, updated_at
240
 FROM workflow_steps
240
 FROM workflow_steps
241
 WHERE job_id = $1
241
 WHERE job_id = $1
242
 ORDER BY step_index ASC
242
 ORDER BY step_index ASC
@@ -252,10 +252,12 @@ type ListStepsForJobRow struct {
252
 	UsesAlias    string
252
 	UsesAlias    string
253
 	Status       WorkflowStepStatus
253
 	Status       WorkflowStepStatus
254
 	Conclusion   NullCheckConclusion
254
 	Conclusion   NullCheckConclusion
255
+	LogObjectKey pgtype.Text
255
 	LogByteCount int64
256
 	LogByteCount int64
256
 	StartedAt    pgtype.Timestamptz
257
 	StartedAt    pgtype.Timestamptz
257
 	CompletedAt  pgtype.Timestamptz
258
 	CompletedAt  pgtype.Timestamptz
258
 	CreatedAt    pgtype.Timestamptz
259
 	CreatedAt    pgtype.Timestamptz
260
+	UpdatedAt    pgtype.Timestamptz
259
 }
261
 }
260
 
262
 
261
 func (q *Queries) ListStepsForJob(ctx context.Context, db DBTX, jobID int64) ([]ListStepsForJobRow, error) {
263
 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) ([]
277
 			&i.UsesAlias,
279
 			&i.UsesAlias,
278
 			&i.Status,
280
 			&i.Status,
279
 			&i.Conclusion,
281
 			&i.Conclusion,
282
+			&i.LogObjectKey,
280
 			&i.LogByteCount,
283
 			&i.LogByteCount,
281
 			&i.StartedAt,
284
 			&i.StartedAt,
282
 			&i.CompletedAt,
285
 			&i.CompletedAt,
283
 			&i.CreatedAt,
286
 			&i.CreatedAt,
287
+			&i.UpdatedAt,
284
 		); err != nil {
288
 		); err != nil {
285
 			return nil, err
289
 			return nil, err
286
 		}
290
 		}