From 478b05a826d7cffda02b58a02921c311d8a59238 Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" <12751435+giautm@users.noreply.github.com> Date: Tue, 23 Dec 2025 18:55:03 +0700 Subject: [PATCH] atlasaction: extended `runs` output with `pending_files` (#448) --- VERSION.txt | 2 +- atlasaction/action.go | 14 +++++++---- .../testdata/github/migrate-apply.txtar | 2 +- .../testdata/gitlab/migrate-apply.txtar | 23 +++++++++++++++++++ 4 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 atlasaction/testdata/gitlab/migrate-apply.txtar diff --git a/VERSION.txt b/VERSION.txt index dd64e523..1a489c78 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -v1.13.4 +v1.13.5 diff --git a/atlasaction/action.go b/atlasaction/action.go index a6f2da69..e8c85ee4 100644 --- a/atlasaction/action.go +++ b/atlasaction/action.go @@ -423,10 +423,11 @@ func (a *Actions) MigrateApply(ctx context.Context) error { return nil } type runOutput struct { - Current string `json:"current"` - Target string `json:"target"` - AppliedCount int `json:"applied_count"` - PendingCount int `json:"pending_count"` + Current string `json:"current"` + Target string `json:"target"` + AppliedCount int `json:"applied_count"` + PendingCount int `json:"pending_count"` + PendingFiles []string `json:"pending_files,omitempty"` } var runsOutput []runOutput for _, run := range runs { @@ -442,11 +443,16 @@ func (a *Actions) MigrateApply(ctx context.Context) error { a.SetOutput("target", run.Target) a.SetOutput("applied_count", strconv.Itoa(len(run.Applied))) a.SetOutput("pending_count", strconv.Itoa(len(run.Pending))) + pendingFiles := make([]string, len(run.Pending)) + for i, p := range run.Pending { + pendingFiles[i] = p.Name + } runsOutput = append(runsOutput, runOutput{ Current: run.Current, Target: run.Target, AppliedCount: len(run.Applied), PendingCount: len(run.Pending), + PendingFiles: pendingFiles, }) } if b, err := json.Marshal(runsOutput); err != nil { diff --git a/atlasaction/testdata/github/migrate-apply.txtar b/atlasaction/testdata/github/migrate-apply.txtar index 8086c1df..8fda9d73 100644 --- a/atlasaction/testdata/github/migrate-apply.txtar +++ b/atlasaction/testdata/github/migrate-apply.txtar @@ -27,5 +27,5 @@ pending_count<<_GitHubActionsFileCommandDelimeter_ 2 _GitHubActionsFileCommandDelimeter_ runs<<_GitHubActionsFileCommandDelimeter_ -[{"current":"","target":"20250812113110","applied_count":2,"pending_count":2}] +[{"current":"","target":"20250812113110","applied_count":2,"pending_count":2,"pending_files":["20250812113056.sql","20250812113110.sql"]}] _GitHubActionsFileCommandDelimeter_ diff --git a/atlasaction/testdata/gitlab/migrate-apply.txtar b/atlasaction/testdata/gitlab/migrate-apply.txtar new file mode 100644 index 00000000..9d2fdc90 --- /dev/null +++ b/atlasaction/testdata/gitlab/migrate-apply.txtar @@ -0,0 +1,23 @@ +# Mock the atlas command outputs +env ATLAS_PATH=$MOCK_ATLAS TEST_BATCH=./migrate-apply +# Setup the action input variables +env ATLAS_INPUT_DIR=file://migrations +env ATLAS_INPUT_URL=sqlite://./a.db?cache=shared&_fk=1 +env ATLAS_INPUT_TO-VERSION=20250812113110 + + +atlas-action --action=migrate/apply +stdout '"atlas migrate apply" completed successfully, applied to version "20250812113110"' +output .env.expected-output + +-- migrate-apply/1/args -- +migrate apply --format {{ json . }} --context {"triggerType":"GITLAB","triggerVersion":"testscript"} --url sqlite://./a.db?cache=shared&_fk=1 --dir file://migrations +-- migrate-apply/1/stdout -- +{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":".","Path":"/a.db","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"cache=shared\u0026_fk=1","Fragment":"","RawFragment":"","Schema":"main"},"Dir":"file://migrations","Pending":[{"Name":"20250812113056.sql","Version":"20250812113056"},{"Name":"20250812113110.sql","Version":"20250812113110"}],"Applied":[{"Name":"20250812113056.sql","Version":"20250812113056","Start":"2025-08-12T18:33:33.639168+07:00","End":"2025-08-12T18:33:33.640468+07:00","Applied":["CREATE TABLE t1(a int);"]},{"Name":"20250812113110.sql","Version":"20250812113110","Start":"2025-08-12T18:33:33.640468+07:00","End":"2025-08-12T18:33:33.641098+07:00","Applied":["CREATE TABLE t2(b int);"]}],"Target":"20250812113110","Start":"2025-08-12T18:33:33.635359+07:00","End":"2025-08-12T18:33:33.641098+07:00","Message":"Migrated to version 20250812113110 from (2 migrations in total)"} + +-- .env.expected-output -- +ATLAS_OUTPUT_MIGRATE_APPLY_CURRENT="" +ATLAS_OUTPUT_MIGRATE_APPLY_TARGET="20250812113110" +ATLAS_OUTPUT_MIGRATE_APPLY_APPLIED_COUNT="2" +ATLAS_OUTPUT_MIGRATE_APPLY_PENDING_COUNT="2" +ATLAS_OUTPUT_MIGRATE_APPLY_RUNS="[{\"current\":\"\",\"target\":\"20250812113110\",\"applied_count\":2,\"pending_count\":2,\"pending_files\":[\"20250812113056.sql\",\"20250812113110.sql\"]}]"