Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

atlasaction: added summary to migrate-lint #79

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion atlasaction/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,17 @@ func MigrateLint(ctx context.Context, client *atlasexec.Client, act *githubactio
Web: true,
Writer: &resp,
})
act.SetOutput("report-url", strings.TrimSpace(resp.String()))
url := strings.TrimSpace(resp.String())
act.SetOutput("report-url", url)
status := "success"
if err != nil {
status = "error"
}
icon := fmt.Sprintf(`<img src="https://release.ariga.io/images/assets/%v.svg"/>`, status)
summary := fmt.Sprintf(`# Atlas Lint Report
<div>Analyzed <strong>%v</strong> %v </div><br>
<strong>Lint report <a href=%q>available here</a></strong>`, act.GetInput("dir-name"), icon, url)
act.AddStepSummary(summary)
return err
}

Expand Down
43 changes: 42 additions & 1 deletion atlasaction/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,44 @@ func TestMigrateLint(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "https://migration-lint-report-url", out["report-url"])
})
t.Run("lint summary - lint error", func(t *testing.T) {
tt := newT(t)
tt.setupConfigWithLogin(t, srv.URL, token)
tt.setInput("dev-url", "sqlite://file?mode=memory")
tt.setInput("dir", "file://testdata/migrations_destructive")
tt.setInput("dir-name", "test-dir-slug")
err := MigrateLint(context.Background(), tt.cli, tt.act)
require.ErrorContains(t, err, "https://migration-lint-report-url")
c, err := os.ReadFile(tt.env["GITHUB_STEP_SUMMARY"])
require.NoError(t, err)
lines := strings.Split(string(c), "\n")
expectedLines := []string{
`# Atlas Lint Report`,
`<div>Analyzed <strong>test-dir-slug</strong> <img src="https://release.ariga.io/images/assets/error.svg"/> </div><br>`,
`<strong>Lint report <a href="https://migration-lint-report-url">available here</a></strong>`,
"",
}
require.EqualValues(t, expectedLines, lines)
})
t.Run("lint summary - lint error", func(t *testing.T) {
tt := newT(t)
tt.setupConfigWithLogin(t, srv.URL, token)
tt.setInput("dev-url", "sqlite://file?mode=memory")
tt.setInput("dir", "file://testdata/migrations")
tt.setInput("dir-name", "test-dir-slug")
err := MigrateLint(context.Background(), tt.cli, tt.act)
require.NoError(t, err)
c, err := os.ReadFile(tt.env["GITHUB_STEP_SUMMARY"])
require.NoError(t, err)
lines := strings.Split(string(c), "\n")
expectedLines := []string{
`# Atlas Lint Report`,
`<div>Analyzed <strong>test-dir-slug</strong> <img src="https://release.ariga.io/images/assets/success.svg"/> </div><br>`,
`<strong>Lint report <a href="https://migration-lint-report-url">available here</a></strong>`,
"",
}
require.EqualValues(t, expectedLines, lines)
})
}

func generateHCL(t *testing.T, url, token string) string {
Expand Down Expand Up @@ -460,10 +498,13 @@ type test struct {
func newT(t *testing.T) *test {
outputFile, err := os.CreateTemp("", "")
require.NoError(t, err)
summaryFile, err := os.CreateTemp("", "")
require.NoError(t, err)
tt := &test{
db: sqlitedb(t),
env: map[string]string{
"GITHUB_OUTPUT": outputFile.Name(),
"GITHUB_OUTPUT": outputFile.Name(),
"GITHUB_STEP_SUMMARY": summaryFile.Name(),
},
}
tt.act = githubactions.New(
Expand Down
Loading