github.com/pix4d/terravalet@v0.8.1-0.20240131132849-abcd6a79eeeb/Taskfile.yml (about) 1 # Install `task` from https://taskfile.dev 2 # Run `task --list` to start. 3 4 version: '3' 5 6 vars: 7 GOTESTSUM: 8 sh: "echo $(which gotestsum 2> /dev/null)" 9 TESTRUNNER: "{{if .GOTESTSUM}}{{base .GOTESTSUM}} --{{else}}go test{{end}}" 10 # 11 GOLANGCI_VERSION: v1.55.2 12 GOTESTSUM_VERSION: v1.11.0 13 GOLINES_VERSION: v0.12.2 14 15 tasks: 16 17 install:deps: 18 desc: Install tool dependencies. 19 cmds: 20 - go install github.com/golangci/golangci-lint/cmd/golangci-lint@{{.GOLANGCI_VERSION}} 21 - go install gotest.tools/gotestsum@{{.GOTESTSUM_VERSION}} 22 - go install github.com/segmentio/golines@{{.GOLINES_VERSION}} 23 - go install github.com/github-release/github-release@latest 24 25 lint: 26 desc: Lint the code. 27 cmds: 28 - golangci-lint run ./... 29 30 lint:linelength: 31 desc: Enforce max line length. Use the tool output only as a hint, sometimes it makes wrong decisions. 32 cmds: 33 - golines --max-len=99 --write-output . 34 35 test: 36 desc: Run all the tests (unit + integration). Use this target to get total coverage. 37 cmds: 38 - "{{.TESTRUNNER}} -count=1 -coverprofile=coverage.out ./..." 39 40 browser: 41 desc: "Show code coverage in browser (usage: task test:<subtarget> browser)" 42 cmds: 43 - go tool cover -html=coverage.out 44 45 build: 46 desc: Build the terravalet executable. 47 cmds: 48 - go build -o bin/terravalet -v -ldflags="{{.LDFLAGS}}" . 49 vars: &build-vars 50 FULL_VERSION: 51 sh: git describe --tags --long --dirty --always 52 LDFLAGS: -w -s -X main.fullVersion={{.FULL_VERSION}} 53 54 # 55 # usage: RELEASE_TAG=v0.1.0 gopass env gh/terravalet task release 56 # 57 release: 58 desc: Build a release and upload to GitHub as draft. You need to transition 59 from draft to published in the web UI. 60 preconditions: 61 - sh: test -n "$RELEASE_TAG" 62 msg: "error: missing environment variable RELEASE_TAG" 63 - sh: test -z $(git status --porcelain) 64 msg: "error: git dirty" 65 - sh: test -z $(git status --branch --porcelain | grep ahead) 66 msg: "error: git local branch ahead" 67 cmds: 68 # - task: unit-test 69 # We create the (local) git tag now, after having ran the unit tests and 70 # before building the executables, so that we can embed this information 71 # in the binaries. 72 # To recover: delete local tag: git tag --delete tagname 73 - git tag --annotate {{.RELEASE_TAG}} -m 'Release {{.RELEASE_TAG}}' 74 - task: release-linux 75 - task: release-darwin-amd 76 - task: release-darwin-arm 77 # - task: system-test 78 - task: test 79 # We create the release as a draft (that is: not visible to the public). 80 # The act of "publishing" the release is left to a human from the web UI. 81 - > 82 github-release release 83 --tag {{.RELEASE_TAG}} 84 --draft 85 --description 86 "See the [CHANGELOG](https://github.com/$GITHUB_USER/$GITHUB_REPO/blob/{{.RELEASE_TAG}}/CHANGELOG.md)" 87 88 # 89 # Since 2024, if we upload immeditately after having created the draft release, 90 # we get: 91 # 92 # error: could not find the release corresponding to tag vX.Y.Z 93 # 94 # to avoid this, we sleep a moment :-/ 95 - sleep 2 96 97 # Upload the artifacts. 98 - > 99 github-release upload 100 --tag {{.RELEASE_TAG}} 101 --name terravalet-linux-amd64.zip 102 --file bin/linux/terravalet-linux-amd64.zip 103 - > 104 github-release upload 105 --tag {{.RELEASE_TAG}} 106 --name terravalet-darwin-amd64.zip 107 --file bin/darwin/terravalet-darwin-amd64.zip 108 - > 109 github-release upload 110 --tag {{.RELEASE_TAG}} 111 --name terravalet-darwin-arm64.zip 112 --file bin/darwin/terravalet-darwin-arm64.zip 113 # Push the tag. 114 - cmd: git push origin {{.RELEASE_TAG}} 115 # Create a draft release. 116 - cmd: | 117 echo "Draft release $RELEASE_TAG created successfully." 118 echo "Remember to publish it in the GitHub web UI https://github.com/$GITHUB_USER/$GITHUB_REPO/releases" 119 silent: true 120 env: 121 GITHUB_USER: pix4d 122 GITHUB_REPO: terravalet 123 # GITHUB_TOKEN expected to be set securely via `gopass` or equivalent 124 release-linux: 125 cmds: 126 - go build -o bin/$GOOS/terravalet -v -ldflags="{{.LDFLAGS}}" . 127 - cd bin/$GOOS && zip terravalet-$GOOS-$GOARCH.zip terravalet 128 env: 129 CGO_ENABLED: 0 130 GOOS: linux 131 GOARCH: amd64 132 vars: *build-vars 133 release-darwin-amd: 134 cmds: 135 - go build -o bin/$GOOS/terravalet -v -ldflags="{{.LDFLAGS}}" . 136 - cd bin/$GOOS && zip terravalet-$GOOS-$GOARCH.zip terravalet 137 env: 138 CGO_ENABLED: 0 139 GOOS: darwin 140 GOARCH: amd64 141 vars: *build-vars 142 release-darwin-arm: 143 cmds: 144 - go build -o bin/$GOOS/terravalet -v -ldflags="{{.LDFLAGS}}" . 145 - cd bin/$GOOS && zip terravalet-$GOOS-$GOARCH.zip terravalet 146 env: 147 CGO_ENABLED: 0 148 GOOS: darwin 149 GOARCH: arm64 150 vars: *build-vars