|
| 1 | +actions: |
| 2 | + - id: go:build |
| 3 | + desc: Build the binary for the local platform |
| 4 | + type: build |
| 5 | + dockerfile: gobuild.Dockerfile |
| 6 | + opts: |
| 7 | + - name: bin_name |
| 8 | + desc: The name of the binary that also defines the build target as cmd/<bin_name> |
| 9 | + prompt: Please enter then name of the binary |
| 10 | + type: input |
| 11 | + required: true |
| 12 | + cmd: | |
| 13 | + -f {{.Dockerfile}} \ |
| 14 | + --build-arg BIN_NAME={{opt "bin_name"}} \ |
| 15 | + --build-arg NO_ARCHIVE=true \ |
| 16 | + --platform local \ |
| 17 | + --target export-bin \ |
| 18 | + --output type=local,dest=dist/ \ |
| 19 | + . |
| 20 | +
|
| 21 | + - id: go:build:all |
| 22 | + desc: Build for multiple platforms |
| 23 | + type: build |
| 24 | + dockerfile: gobuild.Dockerfile |
| 25 | + opts: |
| 26 | + - name: bin_name |
| 27 | + desc: The name of the binary that also defines the build target as cmd/<bin_name> |
| 28 | + prompt: Please enter then name of the binary |
| 29 | + type: input |
| 30 | + required: true |
| 31 | + - name: platforms |
| 32 | + desc: "Comma separated list of platforms to build for (ex: linux/amd64,linux/arm64)" |
| 33 | + prompt: "Please enter the comma separated list of platforms (ex: linux/amd64,linux/arm64)" |
| 34 | + type: input |
| 35 | + cmd: | |
| 36 | + -f {{.Dockerfile}} \ |
| 37 | + --build-arg BIN_NAME={{opt "bin_name"}} \ |
| 38 | + {{if opt "platforms"}}--platform {{opt "platforms"}}{{end}} \ |
| 39 | + --target export-bin \ |
| 40 | + --output type=local,dest=dist/,platform-split=false \ |
| 41 | + . |
| 42 | +
|
| 43 | + - id: go:lint |
| 44 | + desc: Run golangci-lint |
| 45 | + type: run |
| 46 | + shell: |
| 47 | + pwd: pwd |
| 48 | + gopath: go env GOPATH |
| 49 | + gocache: go env GOCACHE |
| 50 | + cmd: | |
| 51 | + --rm \ |
| 52 | + {{if .IsTTY}}-t{{end}} \ |
| 53 | + -v {{sh "pwd"}}:/app \ |
| 54 | + -v {{sh "gopath"}}/pkg:/go/pkg \ |
| 55 | + -v {{sh "gocache"}}:/cache/go \ |
| 56 | + -e GOFLAGS=-buildvcs=false \ |
| 57 | + -e GOCACHE=/cache/go \ |
| 58 | + -e GOLANGCI_LINT_CACHE=/cache/go \ |
| 59 | + -w /app \ |
| 60 | + golangci/golangci-lint:v1.61-alpine \ |
| 61 | + golangci-lint run --timeout 5m |
| 62 | +
|
| 63 | + - id: go:mocks |
| 64 | + desc: Generate mocks using vektra/mockery |
| 65 | + type: run |
| 66 | + shell: |
| 67 | + pwd: pwd |
| 68 | + gopath: go env GOPATH |
| 69 | + gocache: go env GOCACHE |
| 70 | + cmd: | |
| 71 | + --rm \ |
| 72 | + -v {{sh "pwd"}}:/app \ |
| 73 | + -v {{sh "gopath"}}/pkg:/go/pkg \ |
| 74 | + -v {{sh "gocache"}}:/cache/go \ |
| 75 | + -e GOCACHE=/cache/go \ |
| 76 | + -v {{sh "pwd"}}:/src \ |
| 77 | + -w /src \ |
| 78 | + vektra/mockery:v2.46 \ |
| 79 | + --keeptree -r --all |
| 80 | +
|
| 81 | + - id: go:fmt |
| 82 | + desc: Organize imports and format code using gofumpt |
| 83 | + type: run |
| 84 | + shell: |
| 85 | + pwd: pwd |
| 86 | + gopath: go env GOPATH |
| 87 | + gocache: go env GOCACHE |
| 88 | + cmd: | |
| 89 | + --rm \ |
| 90 | + -v {{sh "pwd"}}:/app \ |
| 91 | + -v {{sh "gopath"}}/pkg:/go/pkg \ |
| 92 | + -v {{sh "gocache"}}:/cache/go \ |
| 93 | + -e GOCACHE=/cache/go \ |
| 94 | + -v {{sh "pwd"}}:/src \ |
| 95 | + -w /src \ |
| 96 | + {{.Ref}} sh /tools/fmt.sh |
| 97 | +
|
| 98 | + - id: go:test |
| 99 | + desc: Run tests |
| 100 | + type: run |
| 101 | + shell: |
| 102 | + pwd: pwd |
| 103 | + gopath: go env GOPATH |
| 104 | + gocache: go env GOCACHE |
| 105 | + opts: |
| 106 | + - name: race |
| 107 | + desc: Check for race conditions |
| 108 | + no-prompt: true |
| 109 | + cmd: | |
| 110 | + {{$race := opt "race"}} \ |
| 111 | + --rm \ |
| 112 | + -v {{sh "pwd"}}:/app \ |
| 113 | + -v {{sh "gopath"}}/pkg:/go/pkg \ |
| 114 | + -v {{sh "gocache"}}:/cache/go \ |
| 115 | + -e GOCACHE=/cache/go \ |
| 116 | + {{if eq $race "true"}}-e CGO_ENABLED=1{{end}} \ |
| 117 | + -v {{sh "pwd"}}:/src \ |
| 118 | + -w /src \ |
| 119 | + {{.Ref}} \ |
| 120 | + go test {{if eq $race "true"}}-race{{end}} -shuffle=on ./... |
| 121 | +
|
| 122 | + - id: docker:build |
| 123 | + desc: Build a Docker image |
| 124 | + type: build |
| 125 | + opts: |
| 126 | + - name: platform |
| 127 | + desc: The platform to build for |
| 128 | + no-prompt: true |
| 129 | + - name: push |
| 130 | + type: confirm |
| 131 | + desc: Push the image after building |
| 132 | + no-prompt: true |
| 133 | + - name: target |
| 134 | + desc: The target to build |
| 135 | + no-prompt: true |
| 136 | + - name: image |
| 137 | + desc: The name of the image |
| 138 | + prompt: Please enter the reference of the image to build |
| 139 | + type: input |
| 140 | + required: true |
| 141 | + cmd: | |
| 142 | + {{$platform := opt "platform"}} \ |
| 143 | + {{$push := optBool "push"}} \ |
| 144 | + --attest type=sbom \ |
| 145 | + --attest type=provenance,mode=max \ |
| 146 | + --ssh default \ |
| 147 | + -f Dockerfile \ |
| 148 | + -t {{opt "image"}} \ |
| 149 | + {{if opt "target"}}--target {{opt "target"}}{{end}} \ |
| 150 | + {{if $platform}}--platform {{$platform}}{{end}} \ |
| 151 | + {{if $push}}--push{{end}} \ |
| 152 | + {{if not $push}}--output type=local,dest=dist/{{end}} \ |
| 153 | + . |
0 commit comments