ci: implemented go test
Signed-off-by: Sam Alba <samalba@users.noreply.github.com>
This commit is contained in:
parent
029a0d270f
commit
646a4d153d
@ -14,7 +14,7 @@ let CUEVersion = "0.4.2"
|
|||||||
// base image to build go binaries
|
// base image to build go binaries
|
||||||
goBuilder: _goBuilder.output
|
goBuilder: _goBuilder.output
|
||||||
_goBuilder: docker.#Build & {
|
_goBuilder: docker.#Build & {
|
||||||
_packages: ["bash", "git"]
|
_packages: ["bash", "git", "alpine-sdk"]
|
||||||
|
|
||||||
steps: [
|
steps: [
|
||||||
docker.#Pull & {
|
docker.#Pull & {
|
||||||
|
32
ci/main.cue
32
ci/main.cue
@ -33,7 +33,7 @@ dagger.#Plan & {
|
|||||||
}
|
}
|
||||||
|
|
||||||
outputs: directories: "go binaries": {
|
outputs: directories: "go binaries": {
|
||||||
contents: actions.build.export.directories["/build"]
|
contents: actions.goBuild.export.directories["/build"]
|
||||||
dest: "./build"
|
dest: "./build"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,24 +58,27 @@ dagger.#Plan & {
|
|||||||
|
|
||||||
_baseImages: #Images
|
_baseImages: #Images
|
||||||
|
|
||||||
build: bash.#Run & {
|
// Go build the dagger binary
|
||||||
|
// depends on goLint and goTest to complete successfully
|
||||||
|
goBuild: bash.#Run & {
|
||||||
_mountSourceCode
|
_mountSourceCode
|
||||||
_mountGoCache
|
_mountGoCache
|
||||||
|
|
||||||
input: _baseImages.goBuilder
|
input: _baseImages.goBuilder
|
||||||
|
|
||||||
env: {
|
env: {
|
||||||
GOOS: strings.ToLower(inputs.params.os)
|
GOOS: strings.ToLower(inputs.params.os)
|
||||||
GOARCH: strings.ToLower(inputs.params.arch)
|
GOARCH: strings.ToLower(inputs.params.arch)
|
||||||
// Makes sure the linter completes before starting the build
|
CGO_ENABLED: "0"
|
||||||
"__depends": "\(goLint.exit)"
|
// Makes sure the linter and unit tests complete before starting the build
|
||||||
|
"__depends_lint": "\(goLint.exit)"
|
||||||
|
"__depends_tests": "\(goTest.exit)"
|
||||||
}
|
}
|
||||||
|
|
||||||
script: contents: #"""
|
script: contents: #"""
|
||||||
mkdir -p /build
|
mkdir -p /build
|
||||||
git_revision=$(git rev-parse --short HEAD)
|
git_revision=$(git rev-parse --short HEAD)
|
||||||
CGO_ENABLED=0 \
|
go build -v -o /build/dagger \
|
||||||
go build -v -o /build/dagger \
|
|
||||||
-ldflags '-s -w -X go.dagger.io/dagger/version.Revision='${git_revision} \
|
-ldflags '-s -w -X go.dagger.io/dagger/version.Revision='${git_revision} \
|
||||||
./cmd/dagger/
|
./cmd/dagger/
|
||||||
"""#
|
"""#
|
||||||
@ -83,20 +86,29 @@ dagger.#Plan & {
|
|||||||
export: directories: "/build": _
|
export: directories: "/build": _
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Go unit tests
|
||||||
|
goTest: bash.#Run & {
|
||||||
|
_mountSourceCode
|
||||||
|
_mountGoCache
|
||||||
|
|
||||||
|
input: _baseImages.goBuilder
|
||||||
|
script: contents: "go test -race -v ./..."
|
||||||
|
}
|
||||||
|
|
||||||
|
// Go lint using golangci-lint
|
||||||
goLint: bash.#Run & {
|
goLint: bash.#Run & {
|
||||||
_mountSourceCode
|
_mountSourceCode
|
||||||
_mountGoCache
|
_mountGoCache
|
||||||
|
|
||||||
input: _baseImages.goLinter
|
input: _baseImages.goLinter
|
||||||
|
|
||||||
script: contents: "golangci-lint run -v --timeout 5m"
|
script: contents: "golangci-lint run -v --timeout 5m"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CUE lint
|
||||||
cueLint: bash.#Run & {
|
cueLint: bash.#Run & {
|
||||||
_mountSourceCode
|
_mountSourceCode
|
||||||
|
|
||||||
input: _baseImages.cue
|
input: _baseImages.cue
|
||||||
|
|
||||||
script: contents: #"""
|
script: contents: #"""
|
||||||
# Format the cue code
|
# Format the cue code
|
||||||
find . -name '*.cue' -not -path '*/cue.mod/*' -print | time xargs -n 1 -P 8 cue fmt -s
|
find . -name '*.cue' -not -path '*/cue.mod/*' -print | time xargs -n 1 -P 8 cue fmt -s
|
||||||
|
Reference in New Issue
Block a user