atlasaction

package
v1.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	StatePending  = "PENDING_USER"
	StateApproved = "APPROVED"
	StateAborted  = "ABORTED"
	StateApplied  = "APPLIED"
)
View Source
const EOF = "\n"

Line separator for logging.

Variables

This section is empty.

Functions

func NewGHAction added in v1.1.0

func NewGHAction(getenv func(string) string, w io.Writer) *ghAction

NewGHAction returns a new Action for GitHub Actions.

func RenderTemplate added in v1.3.0

func RenderTemplate(name string, data any) (string, error)

RenderTemplate renders the given template with the data.

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 NewCircleCIOrb added in v1.1.0

func NewCircleCIOrb(getenv func(string) string, w io.Writer) Action

New returns a new Action for GitHub Actions.

func NewGitlabCI added in v1.3.5

func NewGitlabCI(getenv func(string) string, w io.Writer) Action

NewGitlabCI returns a new Action for Gitlab CI.

type Actions added in v1.2.0

type Actions struct {
	Action
	Version string
	Atlas   AtlasExec
}

Actions holds the runtime for the actions to run. This helps to inject the runtime dependencies. Like the SCM client, Atlas client, etc.

func New added in v1.3.0

func New(getenv func(string) string, w io.Writer) (*Actions, error)

New creates a new Actions based on the environment.

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

func (a *Actions) GetArrayInput(name string) []string

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

func (a *Actions) GetAtlasURLInput(name string) string

GetAtlasURLInput returns the atlas URL input with the given name.

func (*Actions) GetBoolInput added in v1.2.0

func (a *Actions) GetBoolInput(name string) bool

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

func (a *Actions) GetDurationInput(name string) time.Duration

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) GetUin64Input added in v1.2.0

func (a *Actions) GetUin64Input(name string) uint64

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

func (a *Actions) GetVarsInput(name string) atlasexec.VarArgs

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

func (a *Actions) MigrateApply(ctx context.Context) error

MigrateApply runs the GitHub Action for "ariga/atlas-action/migrate/apply".

func (*Actions) MigrateDown added in v1.2.0

func (a *Actions) MigrateDown(ctx context.Context) (err error)

MigrateDown runs the GitHub Action for "ariga/atlas-action/migrate/down".

func (*Actions) MigrateLint added in v1.2.0

func (a *Actions) MigrateLint(ctx context.Context) error

MigrateLint runs the GitHub Action for "ariga/atlas-action/migrate/lint"

func (*Actions) MigratePush added in v1.2.0

func (a *Actions) MigratePush(ctx context.Context) error

MigratePush runs the GitHub Action for "ariga/atlas-action/migrate/push"

func (*Actions) MigrateTest added in v1.2.0

func (a *Actions) MigrateTest(ctx context.Context) error

MigrateTest runs the GitHub Action for "ariga/atlas-action/migrate/test"

func (*Actions) RequiredInputs added in v1.3.0

func (a *Actions) RequiredInputs(input ...string) error

RequiredInputs returns an error if any of the given inputs are missing.

func (*Actions) Run added in v1.3.0

func (a *Actions) Run(ctx context.Context, act string) error

Run runs the action based on the command name.

func (*Actions) SchemaApply added in v1.3.0

func (a *Actions) SchemaApply(ctx context.Context) error

SchemaApply runs the GitHub Action for "ariga/atlas-action/schema/apply"

func (*Actions) SchemaPlan added in v1.3.0

func (a *Actions) SchemaPlan(ctx context.Context) error

SchemaPlan runs the GitHub Action for "ariga/atlas-action/schema/plan"

func (*Actions) SchemaPlanApprove added in v1.3.0

func (a *Actions) SchemaPlanApprove(ctx context.Context) error

SchemaPlanApprove runs the GitHub Action for "ariga/atlas-action/schema/plan/approve"

func (*Actions) SchemaPush added in v1.3.0

func (a *Actions) SchemaPush(ctx context.Context) error

SchemaPush runs the GitHub Action for "ariga/atlas-action/schema/push"

func (*Actions) SchemaTest added in v1.2.0

func (a *Actions) SchemaTest(ctx context.Context) error

SchemaTest runs the GitHub Action for "ariga/atlas-action/schema/test"

func (*Actions) WorkingDir added in v1.2.0

func (a *Actions) WorkingDir() string

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 {
	// 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)
	// 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 GitlabComment added in v1.3.5

type GitlabComment struct {
	ID     int    `json:"id"`
	Body   string `json:"body"`
	System bool   `json:"system"`
}

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 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 Suggestion struct {
	ID        string // Unique identifier for the suggestion.
	Path      string // File path.
	StartLine int    // Start line numbers for the suggestion.
	Line      int    // End line number for the suggestion.
	Comment   string // Comment body.
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL