Skip to content
Draft
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
27 changes: 15 additions & 12 deletions .dagger/modules/e2e/main.dang
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ type E2e {
.length > 0
}

let containsModulePath(mods: [{{path: String!}}!]!, want: String!): Boolean! {
mods
.filter { mod => mod.path == want }
.length > 0
let containsModulePath(paths: [String!]!, want: String!): Boolean! {
containsPath(paths, want)
}

"""
Expand Down Expand Up @@ -79,7 +77,8 @@ type E2e {
"module lookup unexpectedly snapped with findUp false: " + direct.path,
)

let allModulePaths = go(version: "1.25").modules(ws).{path}
let allModules = go(version: "1.25").modules(ws)
let allModulePaths = allModules.keys
assert(
containsModulePath(allModulePaths, "fixtures/go-module-cross-include-a"),
"unfiltered modules did not include expected fixture module",
Expand All @@ -92,10 +91,14 @@ type E2e {
containsModulePath(allModulePaths, "testdata/go-module-excluded"),
"unfiltered modules did not include skipped fixture module by default",
)
assert(
allModules.get(key: "testdata/go-module-with-testdata").path == "testdata/go-module-with-testdata",
"module collection get did not return the requested module",
)

let includedModulePaths = go(version: "1.25")
.modules(ws, include: ["fixtures/go-module-cross-include-a"])
.{path}
.keys
assert(
containsModulePath(includedModulePaths, "fixtures/go-module-cross-include-a"),
"modules include filter did not include matching module root",
Expand All @@ -107,7 +110,7 @@ type E2e {

let excludedModulePaths = go(version: "1.25")
.modules(ws, exclude: ["fixtures/go-module-cross-include-a"])
.{path}
.keys
assert(
containsModulePath(excludedModulePaths, "fixtures/go-module-cross-include-a") == false,
"modules exclude filter included excluded module root",
Expand All @@ -119,7 +122,7 @@ type E2e {
include: ["fixtures/go-module-cross-include-*"],
exclude: ["fixtures/go-module-cross-include-b"],
)
.{path}
.keys
assert(
containsModulePath(combinedModulePaths, "fixtures/go-module-cross-include-a"),
"modules combined filters did not include matching module root",
Expand All @@ -131,7 +134,7 @@ type E2e {

let contentMatchedModulePaths = go(version: "1.25")
.modules(ws, include: ["**/module-a-only.data"])
.{path}
.keys
assert(
containsModulePath(contentMatchedModulePaths, "fixtures/go-module-cross-include-a"),
"modules include filter did not match module directory contents",
Expand All @@ -143,7 +146,7 @@ type E2e {

let lintSkippedModulePaths = go(version: "1.25")
.modules(ws, includeSkipLint: false)
.{path}
.keys
assert(
containsModulePath(lintSkippedModulePaths, "testdata/go-module-excluded") == false,
"modules includeSkipLint false included lint-skipped module",
Expand All @@ -163,7 +166,7 @@ type E2e {

let testSkippedModulePaths = go(version: "1.25")
.modules(ws, includeSkipTest: false)
.{path}
.keys
assert(
containsModulePath(testSkippedModulePaths, "testdata/go-module-excluded") == false,
"modules includeSkipTest false included test-skipped module",
Expand All @@ -183,7 +186,7 @@ type E2e {

let generateSkippedModulePaths = go(version: "1.25")
.modules(ws, includeSkipGenerate: false)
.{path}
.keys
assert(
containsModulePath(generateSkippedModulePaths, "testdata/go-module-excluded") == false,
"modules includeSkipGenerate false included generate-skipped module",
Expand Down
67 changes: 61 additions & 6 deletions go.dang
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Go {
pub skipGenerateFilename: String! = ".dagger-skip-go-generate"

"""
Return every Go module discovered from workspace go.mod files.
Return Go modules discovered from workspace go.mod files.
Optional include/exclude patterns filter discovered module root directories.
"""
pub modules(
Expand All @@ -43,7 +43,7 @@ type Go {
includeSkipLint: Boolean! = true,
includeSkipTest: Boolean! = true,
includeSkipGenerate: Boolean! = true,
): [GoModule!]! {
): GoModules! {
let lintSkipMarkers = ws
.directory("/", include: ["**/" + skipLintFilename])
.glob("**/" + skipLintFilename)
Expand All @@ -54,7 +54,7 @@ type Go {
.directory("/", include: ["**/" + skipGenerateFilename])
.glob("**/" + skipGenerateFilename)

ws
let paths = ws
.directory("/", include: ["**/go.mod"])
.glob("**/go.mod")
.map { modPath =>
Expand All @@ -81,6 +81,19 @@ type Go {
(includeSkipTest or mod.skipTest(ws) == false) and
(includeSkipGenerate or mod.skipGenerate(ws) == false)
}
.map { mod => mod.path }

GoModules(
paths: paths,
version: version,
includeExtraFiles: includeExtraFiles,
skipLintFilename: skipLintFilename,
skipTestFilename: skipTestFilename,
skipGenerateFilename: skipGenerateFilename,
lintSkipMarkers: lintSkipMarkers,
testSkipMarkers: testSkipMarkers,
generateSkipMarkers: generateSkipMarkers,
)
}

let modulePathIncluded(
Expand Down Expand Up @@ -148,7 +161,9 @@ type Go {
Modules with the lint skip marker are skipped.
"""
pub lintAll(ws: Workspace!): Void @check {
let layers = modules(ws).reduce(directory) { layers, mod =>
let mods = modules(ws)
let layers = mods.paths.reduce(directory) { layers, path =>
let mod = mods.module(path)
layers.withDirectory(
mod.path,
directory.withFile("go.mod", mod.lintExec(ws).file("go.mod")),
Expand All @@ -167,7 +182,10 @@ type Go {
Modules with the test skip marker are skipped.
"""
pub testAll(ws: Workspace!): Void @check {
let mods = modules(ws).filter { mod => mod.skipTest(ws) == false }
let collection = modules(ws)
let mods = collection.paths.map { path => collection.module(path) }.filter { mod =>
mod.skipTest(ws) == false
}
let layers = mods.reduce(directory) { layers, mod =>
layers.withDirectory(
mod.path,
Expand All @@ -188,7 +206,8 @@ type Go {
are skipped.
"""
pub generateAll(ws: Workspace!): Changeset! @generate {
let mods = modules(ws).filter { mod =>
let collection = modules(ws)
let mods = collection.paths.map { path => collection.module(path) }.filter { mod =>
mod.skipGenerate(ws) == false and mod.hasGenerateDirectives(ws)
}

Expand All @@ -208,6 +227,42 @@ type Go {

}

"""
Go modules discovered in a workspace.
"""
type GoModules {
"""
Workspace-relative module root paths in discovery order.
"""
pub paths: [String!]! @keys

let version: String!
let includeExtraFiles: [String!]!
let skipLintFilename: String!
let skipTestFilename: String!
let skipGenerateFilename: String!
let lintSkipMarkers: [String!]!
let testSkipMarkers: [String!]!
let generateSkipMarkers: [String!]!

"""
Return the discovered Go module with the given workspace-relative root path.
"""
pub module(path: String!): GoModule! @get {
GoModule(
path: path,
version: version,
includeExtraFiles: includeExtraFiles,
skipLintFilename: skipLintFilename,
skipTestFilename: skipTestFilename,
skipGenerateFilename: skipGenerateFilename,
lintSkipMarkers: lintSkipMarkers,
testSkipMarkers: testSkipMarkers,
generateSkipMarkers: generateSkipMarkers,
)
}
}

"""
A Go module rooted at a workspace-relative path.
"""
Expand Down