Some checks failed
Build and Release / Create Release (push) Successful in 0s
Trigger Vault Plugin Rebuild / Trigger Vault Rebuild (push) Successful in 0s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 2m48s
Build and Release / Lint (push) Failing after 5m2s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, linux, linux-latest) (push) Has been skipped
Build and Release / Unit Tests (push) Successful in 5m37s
Go's semantic import versioning requires v2+ modules to include the major version in the module path. This enables using proper version tags (v3.x.x) instead of pseudo-versions. Updated module path: code.gitcaddy.com/server/v3
56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"context"
|
|
|
|
"code.gitcaddy.com/server/v3/models/db"
|
|
)
|
|
|
|
// ActionTaskOutput represents an output of ActionTask.
|
|
// So the outputs are bound to a task, that means when a completed job has been rerun,
|
|
// the outputs of the job will be reset because the task is new.
|
|
// It's by design, to avoid the outputs of the old task to be mixed with the new task.
|
|
type ActionTaskOutput struct {
|
|
ID int64
|
|
TaskID int64 `xorm:"INDEX UNIQUE(task_id_output_key)"`
|
|
OutputKey string `xorm:"VARCHAR(255) UNIQUE(task_id_output_key)"`
|
|
OutputValue string `xorm:"MEDIUMTEXT"`
|
|
}
|
|
|
|
func init() {
|
|
db.RegisterModel(new(ActionTaskOutput))
|
|
}
|
|
|
|
// FindTaskOutputByTaskID returns the outputs of the task.
|
|
func FindTaskOutputByTaskID(ctx context.Context, taskID int64) ([]*ActionTaskOutput, error) {
|
|
var outputs []*ActionTaskOutput
|
|
return outputs, db.GetEngine(ctx).Where("task_id=?", taskID).Find(&outputs)
|
|
}
|
|
|
|
// FindTaskOutputKeyByTaskID returns the keys of the outputs of the task.
|
|
func FindTaskOutputKeyByTaskID(ctx context.Context, taskID int64) ([]string, error) {
|
|
var keys []string
|
|
return keys, db.GetEngine(ctx).Table(ActionTaskOutput{}).Where("task_id=?", taskID).Cols("output_key").Find(&keys)
|
|
}
|
|
|
|
// InsertTaskOutputIfNotExist inserts a new task output if it does not exist.
|
|
func InsertTaskOutputIfNotExist(ctx context.Context, taskID int64, key, value string) error {
|
|
return db.WithTx(ctx, func(ctx context.Context) error {
|
|
sess := db.GetEngine(ctx)
|
|
if exist, err := sess.Exist(&ActionTaskOutput{TaskID: taskID, OutputKey: key}); err != nil {
|
|
return err
|
|
} else if exist {
|
|
return nil
|
|
}
|
|
_, err := sess.Insert(&ActionTaskOutput{
|
|
TaskID: taskID,
|
|
OutputKey: key,
|
|
OutputValue: value,
|
|
})
|
|
return err
|
|
})
|
|
}
|