Skip to content

Commit

Permalink
migrate/lint: support tag input (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
giautm authored Nov 12, 2024
1 parent dbd0cdb commit 18efec4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ All inputs are optional as they may be specified in the Atlas configuration file
* `dir` - The URL of the migration directory to lint. For example: `file://migrations`.
Read more about [Atlas URLs](https://atlasgo.io/concepts/url).
* `dir-name` - The name (slug) of the project in Atlas Cloud.
* `tag` - The tag of migrations to used as base for linting. By default, the `latest` tag is used.
* `dev-url` - The URL of the dev-database to use for analysis. For example: `mysql://root:pass@localhost:3306/dev`.
Read more about [dev-databases](https://atlasgo.io/concepts/dev-database).
* `config` - The path to the Atlas configuration file. By default, Atlas will look for a file
Expand Down
17 changes: 14 additions & 3 deletions atlasaction/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func (a *Actions) MigrateLint(ctx context.Context) error {
DirURL: a.GetInput("dir"),
ConfigURL: a.GetInput("config"),
Env: a.GetInput("env"),
Base: "atlas://" + dirName,
Base: a.GetAtlasURLInput("dir-name", "tag"),
Context: a.GetRunContext(ctx, tc),
Vars: a.GetVarsInput("vars"),
Web: true,
Expand Down Expand Up @@ -795,12 +795,23 @@ func (a *Actions) GetDurationInput(name string) time.Duration {
}

// GetAtlasURLInput returns the atlas URL input with the given name.
func (a *Actions) GetAtlasURLInput(name string) string {
// paramsName is the list of input names to be added as query parameters.
func (a *Actions) GetAtlasURLInput(name string, paramsName ...string) string {
v := a.GetInput(name)
if v == "" {
return ""
}
return (&url.URL{Scheme: "atlas", Path: v}).String()
u := (&url.URL{Scheme: "atlas", Path: v})
if len(paramsName) > 0 {
q := u.Query()
for _, p := range paramsName {
if v := a.GetInput(p); v != "" {
q.Set(p, v)
}
}
u.RawQuery = q.Encode()
}
return u.String()
}

// GetVarsInput returns the vars input with the given name.
Expand Down
23 changes: 23 additions & 0 deletions atlasaction/testdata/github/migrate-lint.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Mock the atlas command outputs
mock-atlas $WORK/migrate-lint
# Setup the action input variables
env INPUT_CONFIG=file://testdata/config/atlas.hcl
env INPUT_ENV=test
env INPUT_DIR-NAME=pupisu
env INPUT_TAG=staging
env INPUT_VARS='{"var1":"value1","var2":"value2"}'
env INPUT_DIR=file://testdata/migrations
env INPUT_DEV_URL=sqlite://file?mode=memory
env INPUT_RUN=example

atlas-action migrate/lint
output output.txt

-- migrate-lint/1/args --
migrate lint -w --context {"path":"file://testdata/migrations","scmType":"GITHUB"} --env test --config file://testdata/config/atlas.hcl --dir file://testdata/migrations --base atlas://pupisu?tag=staging --var var1=value1 --var var2=value2 --format {{ json . }}
-- migrate-lint/1/stdout --
{"URL":"https://migration-lint-report-url"}
-- output.txt --
report-url<<_GitHubActionsFileCommandDelimeter_
https://migration-lint-report-url
_GitHubActionsFileCommandDelimeter_
4 changes: 4 additions & 0 deletions migrate/lint/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ inputs:
dir-name:
description: The name (slug) of the project in Atlas Cloud.
required: true
tag:
description: |
The tag of migrations to used as base for linting. By default, the `latest` tag is used.
required: false
outputs:
url:
description: |
Expand Down

0 comments on commit 18efec4

Please sign in to comment.