Skip to content

Commit 2ee5745

Browse files
committed
add dang module
Signed-off-by: kpenfound <kyle@dagger.io>
1 parent b7cf6b3 commit 2ee5745

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

.toolchains/golang/dagger.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "golang",
3+
"engineVersion": "v0.19.6-251105123015-1e35751b9b80",
4+
"sdk": {
5+
"source": "github.com/vito/dang/dagger-sdk"
6+
}
7+
}

.toolchains/golang/main.dang

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
type Golang {
2+
"""
3+
The source directory for the project.
4+
"""
5+
pub source: Directory! @defaultPath(path: "/")
6+
7+
"""
8+
The Golang image to use
9+
"""
10+
pub golangImage: Container! = container().from("golang:1.24")
11+
12+
"""
13+
Build the project
14+
"""
15+
pub build(
16+
"""
17+
The package to build.
18+
"""
19+
package: String! = "."
20+
): Changeset! {
21+
base.withExec(["go", "build", package]).directory("/src").
22+
changes(source)
23+
}
24+
25+
"""
26+
Test the project
27+
"""
28+
pub test(
29+
"""
30+
The package to test.
31+
"""
32+
package: String! = "."
33+
): CheckStatus! {
34+
base.withExec(["go", "test", package]).directory("/src").
35+
sync
36+
let foo = CheckStatus.COMPLETED
37+
if foo != null {
38+
foo
39+
}
40+
}
41+
42+
"""
43+
Lint the project
44+
"""
45+
pub lint(
46+
"""
47+
Golangci-lint image to use
48+
"""
49+
image: String! = "golangci/golangci-lint:v2.1"
50+
): CheckStatus! {
51+
container().from(image).
52+
withWorkdir("/src").
53+
withDirectory("/src", source).
54+
withExec(["golangci-lint", "run", "-v", "--timeout", "10m"]).
55+
sync
56+
let foo = CheckStatus.COMPLETED
57+
if foo != null {
58+
foo
59+
}
60+
}
61+
62+
"""
63+
Lint the project and return fixes
64+
"""
65+
pub lintFix: Changeset! {
66+
container().from("golangci/golangci-lint:v2.1").
67+
withWorkdir("/src").
68+
withDirectory("/src", source).
69+
withExec(["golangci-lint", "run", "-v", "--timeout", "10m", "--fix"]).
70+
directory("/src").
71+
changes(source)
72+
}
73+
74+
let base: Container! {
75+
golangImage.
76+
withMountedCache("/go/pkg/mod", cacheVolume("go-mod")).
77+
withEnvVariable("GOMODCACHE", "/go/pkg/mod").
78+
withMountedCache("/go/build-cache", cacheVolume("go-build")).
79+
withEnvVariable("GOCACHE", "/go/build-cache").
80+
withDirectory("/src", source).
81+
withWorkdir("/src")
82+
}
83+
}

0 commit comments

Comments
 (0)