Documentation ¶
Index ¶
- Constants
- Variables
- func NewGHAction(getenv func(string) string, w io.Writer) *ghAction
- func OldAgentHash(src string) string
- func RenderTemplate(name string, data any) (string, error)
- type Action
- type Actions
- func (a *Actions) DeployRunContext() *atlasexec.DeployRunContext
- func (a *Actions) GetArrayInput(name string) []string
- func (a *Actions) GetAtlasURLInput(name string, paramsName ...string) string
- func (a *Actions) GetBoolInput(name string) bool
- func (a *Actions) GetDurationInput(name string) time.Duration
- func (a *Actions) GetRunContext(_ context.Context, tc *TriggerContext) *atlasexec.RunContext
- func (a *Actions) GetURLInput(name string) (*url.URL, error)
- func (a *Actions) GetUin64Input(name string) uint64
- func (a *Actions) GetVarsInput(name string) atlasexec.VarArgs
- func (a *Actions) MigrateApply(ctx context.Context) error
- func (a *Actions) MigrateDown(ctx context.Context) (err error)
- func (a *Actions) MigrateLint(ctx context.Context) error
- func (a *Actions) MigratePush(ctx context.Context) error
- func (a *Actions) MigrateTest(ctx context.Context) error
- func (a *Actions) MonitorSchema(ctx context.Context) error
- func (a *Actions) RequiredInputs(input ...string) error
- func (a *Actions) Run(ctx context.Context, act string) error
- func (a *Actions) SchemaApply(ctx context.Context) error
- func (a *Actions) SchemaPlan(ctx context.Context) error
- func (a *Actions) SchemaPlanApprove(ctx context.Context) error
- func (a *Actions) SchemaPush(ctx context.Context) error
- func (a *Actions) SchemaTest(ctx context.Context) error
- func (a *Actions) WorkingDir() string
- type Actor
- type AtlasExec
- type CloudClient
- type GitlabComment
- type Logger
- type Option
- func WithAction(a Action) Option
- func WithAtlas(a AtlasExec) Option
- func WithAtlasPath(bin string) Option
- func WithCloudClient[T CloudClient](cc func(token, version, cliVersion string) T) Option
- func WithGetenv(getenv func(string) string) Option
- func WithOut(out io.Writer) Option
- func WithRuntimeAction() Option
- func WithVersion(v string) Option
- type PullRequest
- type SCM
- type SCMClient
- type Suggestion
- type TriggerContext
Constants ¶
const ( // Versioned workflow Commands CmdMigratePush = "migrate/push" CmdMigrateLint = "migrate/lint" CmdMigrateApply = "migrate/apply" CmdMigrateDown = "migrate/down" CmdMigrateTest = "migrate/test" // Declarative workflow Commands CmdSchemaPush = "schema/push" CmdSchemaTest = "schema/test" CmdSchemaPlan = "schema/plan" CmdSchemaPlanApprove = "schema/plan/approve" CmdSchemaApply = "schema/apply" // Montioring Commands CmdMonitorSchema = "monitor/schema" )
const ( StatePending = "PENDING_USER" StateApproved = "APPROVED" StateAborted = "ABORTED" StateApplied = "APPLIED" )
Variables ¶
var ErrNoSCM = errors.New("atlasaction: no SCM client found")
ErrNoSCM is returned when no SCM client is found.
Functions ¶
func NewGHAction ¶ added in v1.1.0
NewGHAction returns a new Action for GitHub Actions.
func OldAgentHash ¶ added in v1.3.9
OldAgentHash computes a hash of the input. Used by the agent to determine if a new snapshot is needed.
Only here for backwards compatability as for new snapshots the Atlas CLI computed hash is used.
Types ¶
type Action ¶ added in v1.1.0
type Action interface { Logger // GetType returns the type of atlasexec trigger Type. e.g. "GITHUB_ACTION" // The value is used to identify the type on CI-Run page in Atlas Cloud. GetType() atlasexec.TriggerType // GetInput returns the value of the input with the given name. GetInput(string) string // SetOutput sets the value of the output with the given name. SetOutput(string, string) // GetTriggerContext returns the context of the trigger event. GetTriggerContext() (*TriggerContext, error) // AddStepSummary adds a summary to the action step. AddStepSummary(string) // SCM returns a SCMClient. SCM() (SCMClient, error) }
Action interface for Atlas.
func NewBitBucketPipe ¶ added in v1.3.10
NewBitBucketPipe returns a new Action for BitBucket.
func NewCircleCIOrb ¶ added in v1.1.0
New returns a new Action for GitHub Actions.
type Actions ¶ added in v1.2.0
type Actions struct { Action Version string Atlas AtlasExec CloudClient func(string, string, *atlasexec.Version) CloudClient }
Actions holds the runtime for the actions to run. This helps to inject the runtime dependencies. Like the SCM client, Atlas client, etc.
func (*Actions) DeployRunContext ¶ added in v1.2.0
func (a *Actions) DeployRunContext() *atlasexec.DeployRunContext
DeployRunContext returns the run context for the `migrate/apply`, and `migrate/down` actions.
func (*Actions) GetArrayInput ¶ added in v1.3.0
GetArrayInput returns the array input with the given name. The input should be a string with new line separated values. Example: ```yaml
input: |- value1 value2
```
func (*Actions) GetAtlasURLInput ¶ added in v1.3.0
GetAtlasURLInput returns the atlas URL input with the given name. paramsName is the list of input names to be added as query parameters.
func (*Actions) GetBoolInput ¶ added in v1.2.0
GetBoolInput returns the boolean input with the given name. The input should be a string representation of boolean. (e.g. "true" or "false")
func (*Actions) GetDurationInput ¶ added in v1.2.0
GetDurationInput returns the duration input with the given name. The input should be a string representation of time.Duration. (e.g. "1s")
func (*Actions) GetRunContext ¶ added in v1.2.0
func (a *Actions) GetRunContext(_ context.Context, tc *TriggerContext) *atlasexec.RunContext
GetRunContext returns the run context for the action.
func (*Actions) GetURLInput ¶ added in v1.3.9
GetURLInput tries to parse the input as URL. In case of a parsing error, this function ensures the error does not leak any sensitive information.
func (*Actions) GetUin64Input ¶ added in v1.2.0
GetUin64Input returns the uint64 input with the given name. The input should be a string representation of uint64. (e.g. "123")
func (*Actions) GetVarsInput ¶ added in v1.2.0
GetVarsInput returns the vars input with the given name. The input should be a JSON string. Example: ```yaml
input: |- { "key1": "value1", "key2": "value2" }
```
func (*Actions) MigrateApply ¶ added in v1.2.0
MigrateApply runs the GitHub Action for "ariga/atlas-action/migrate/apply".
func (*Actions) MigrateDown ¶ added in v1.2.0
MigrateDown runs the GitHub Action for "ariga/atlas-action/migrate/down".
func (*Actions) MigrateLint ¶ added in v1.2.0
MigrateLint runs the GitHub Action for "ariga/atlas-action/migrate/lint"
func (*Actions) MigratePush ¶ added in v1.2.0
MigratePush runs the GitHub Action for "ariga/atlas-action/migrate/push"
func (*Actions) MigrateTest ¶ added in v1.2.0
MigrateTest runs the GitHub Action for "ariga/atlas-action/migrate/test"
func (*Actions) MonitorSchema ¶ added in v1.3.9
MonitorSchema runs the Action for "ariga/atlas-action/monitor/schema"
func (*Actions) RequiredInputs ¶ added in v1.3.0
RequiredInputs returns an error if any of the given inputs are missing.
func (*Actions) SchemaApply ¶ added in v1.3.0
SchemaApply runs the GitHub Action for "ariga/atlas-action/schema/apply"
func (*Actions) SchemaPlan ¶ added in v1.3.0
SchemaPlan runs the GitHub Action for "ariga/atlas-action/schema/plan"
func (*Actions) SchemaPlanApprove ¶ added in v1.3.0
SchemaPlanApprove runs the GitHub Action for "ariga/atlas-action/schema/plan/approve"
func (*Actions) SchemaPush ¶ added in v1.3.0
SchemaPush runs the GitHub Action for "ariga/atlas-action/schema/push"
func (*Actions) SchemaTest ¶ added in v1.2.0
SchemaTest runs the GitHub Action for "ariga/atlas-action/schema/test"
func (*Actions) WorkingDir ¶ added in v1.2.0
WorkingDir returns the working directory for the action.
type Actor ¶ added in v1.0.10
type Actor struct { Name string // Username of the actor. ID string // ID of the actor on the SCM. }
Actor holds the actor information.
type AtlasExec ¶ added in v1.2.0
type AtlasExec interface { // Version returns the version of the atlas binary. Version(ctx context.Context) (*atlasexec.Version, error) // Login runs the `login` command. Login(ctx context.Context, params *atlasexec.LoginParams) error // MigrateStatus runs the `migrate status` command. MigrateStatus(context.Context, *atlasexec.MigrateStatusParams) (*atlasexec.MigrateStatus, error) // MigrateApplySlice runs the `migrate apply` command and returns the successful runs. MigrateApplySlice(context.Context, *atlasexec.MigrateApplyParams) ([]*atlasexec.MigrateApply, error) // MigrateDown runs the `migrate down` command. MigrateDown(context.Context, *atlasexec.MigrateDownParams) (*atlasexec.MigrateDown, error) // MigrateLintError runs the `migrate lint` command and fails if there are lint errors. MigrateLintError(context.Context, *atlasexec.MigrateLintParams) error // MigratePush runs the `migrate push` command. MigratePush(context.Context, *atlasexec.MigratePushParams) (string, error) // MigrateTest runs the `migrate test` command. MigrateTest(context.Context, *atlasexec.MigrateTestParams) (string, error) // SchemaInspect runs the `schema inspect` command. SchemaInspect(ctx context.Context, params *atlasexec.SchemaInspectParams) (string, error) // SchemaPush runs the `schema push` command. SchemaPush(context.Context, *atlasexec.SchemaPushParams) (*atlasexec.SchemaPush, error) // SchemaTest runs the `schema test` command. SchemaTest(context.Context, *atlasexec.SchemaTestParams) (string, error) // SchemaPlan runs the `schema plan` command. SchemaPlan(context.Context, *atlasexec.SchemaPlanParams) (*atlasexec.SchemaPlan, error) // SchemaPlanList runs the `schema plan list` command. SchemaPlanList(context.Context, *atlasexec.SchemaPlanListParams) ([]atlasexec.SchemaPlanFile, error) // SchemaPlanLint runs the `schema plan lint` command. SchemaPlanLint(context.Context, *atlasexec.SchemaPlanLintParams) (*atlasexec.SchemaPlan, error) // SchemaPlanApprove runs the `schema plan approve` command. SchemaPlanApprove(context.Context, *atlasexec.SchemaPlanApproveParams) (*atlasexec.SchemaPlanApprove, error) // SchemaApplySlice runs the `schema apply` command. SchemaApplySlice(context.Context, *atlasexec.SchemaApplyParams) ([]*atlasexec.SchemaApply, error) }
AtlasExec is the interface for the atlas exec client.
type CloudClient ¶ added in v1.3.9
type CloudClient interface { // SnapshotHash returns the latest snapshot hash for a monitored schema. SnapshotHash(context.Context, *cloud.SnapshotHashInput) (string, error) // PushSnapshot pushes a new snapshot version of a monitored schema to the cloud. PushSnapshot(context.Context, *cloud.PushSnapshotInput) (string, error) }
CloudClient lets an action talk to Atlas Cloud.
type GitlabComment ¶ added in v1.3.5
type Logger ¶ added in v1.1.0
type Logger interface { // Infof logs an info message. Infof(string, ...interface{}) // Warningf logs a warning message. Warningf(string, ...interface{}) // Errorf logs an error message. Errorf(string, ...interface{}) // Fatalf logs a fatal error message and exits the action. Fatalf(string, ...interface{}) // WithFieldsMap returns a new Logger with the given fields. WithFieldsMap(map[string]string) Logger }
type Option ¶ added in v1.3.9
type Option func(*config)
func WithAction ¶ added in v1.3.9
WithAction sets the Action to use.
func WithAtlasPath ¶ added in v1.3.10
WithAtlasPath sets the path to the atlas binary.
func WithCloudClient ¶ added in v1.3.9
func WithCloudClient[T CloudClient](cc func(token, version, cliVersion string) T) Option
WithCloudClient specifies how to obtain a CloudClient given the name of the token input variable.
func WithGetenv ¶ added in v1.3.9
WithGetenv specifies how to obtain environment variables.
func WithRuntimeAction ¶ added in v1.3.10
func WithRuntimeAction() Option
WithRuntimeAction detects the action based on the environment.
func WithVersion ¶ added in v1.3.9
WithVersion specifies the version of the Actions.
type PullRequest ¶ added in v1.1.0
type PullRequest struct { Number int // Pull Request Number URL string // URL of the pull request. e.g "https://github.com/ariga/atlas-action/pull/1" Commit string // Latest commit SHA. Body string // Body (description) of the pull request. }
PullRequest holds the pull request information.
func (*PullRequest) AtlasDirectives ¶ added in v1.3.5
func (p *PullRequest) AtlasDirectives() (ds []string)
AtlasDirectives returns any directives that are present in the pull request body. For example:
/atlas:nolint destructive
type SCM ¶ added in v1.1.0
type SCM struct { Type atlasexec.SCMType // Type of the SCM, e.g. "GITHUB" / "GITLAB" / "BITBUCKET". APIURL string // APIURL is the base URL for the SCM API. }
SCM holds the source control management system information.
type SCMClient ¶ added in v1.3.5
type SCMClient interface { // ListPullRequestFiles returns a list of files changed in a pull request. ListPullRequestFiles(ctx context.Context, pr *PullRequest) ([]string, error) // UpsertSuggestion posts or updates a pull request suggestion. UpsertSuggestion(ctx context.Context, pr *PullRequest, s *Suggestion) error // UpsertComment posts or updates a pull request comment. UpsertComment(ctx context.Context, pr *PullRequest, id, comment string) error }
SCMClient contains methods for interacting with SCM platforms (GitHub, Gitlab etc...).
type Suggestion ¶ added in v1.2.0
type TriggerContext ¶ added in v1.1.0
type TriggerContext struct { SCM SCM // SCM is the source control management system. Repo string // Repo is the repository name. e.g. "ariga/atlas-action". RepoURL string // RepoURL is full URL of the repository. e.g. "https://github.com/ariga/atlas-action". Branch string // Branch name. Commit string // Commit SHA. PullRequest *PullRequest // PullRequest will be available if the event is "pull_request". Actor *Actor // Actor is the user who triggered the action. RerunCmd string // RerunCmd is the command to rerun the action. }
TriggerContext holds the context of the environment the action is running in.