diff --git a/Taskfile.yaml b/Taskfile.yaml new file mode 100644 index 0000000000000000000000000000000000000000..fc443e6cc98910546cd1d1846b962b21f64c529c --- /dev/null +++ b/Taskfile.yaml @@ -0,0 +1,167 @@ +# SPDX-FileCopyrightText: Amolith +# +# SPDX-License-Identifier: CC0-1.0 + +version: "3" + +vars: + VERSION: + sh: git describe --tags --always 2>/dev/null || echo "v0.0.0" + GOOS: + sh: go env GOOS + GOARCH: + sh: go env GOARCH + +env: + CGO_ENABLED: 0 + +tasks: + default: + desc: Run all checks + cmds: + - task: fmt + - task: lint:fix + - task: staticcheck + - task: test + - task: vuln + - task: reuse + + fmt: + cmds: + - go install mvdan.cc/gofumpt@latest + - gofumpt -l -w . + + lint: + cmds: + - golangci-lint run + + lint:fix: + cmds: + - golangci-lint run --fix + + staticcheck: + cmds: + - go install honnef.co/go/tools/cmd/staticcheck@latest + - staticcheck ./... + + test: + cmds: + - go test -v ./... + + vuln: + cmds: + - go install golang.org/x/vuln/cmd/govulncheck@latest + - govulncheck ./... + + reuse: + desc: Lint licenses and copyright headers + cmds: + - reuse lint + + build: + cmds: + - go build -o lune -ldflags "-s -w -X main.version={{.VERSION}}" + generates: + - lune + + install: + cmds: + - go install -ldflags "-s -w -X main.version={{.VERSION}}" + + run: + cmds: + - go run -ldflags "-s -w -X main.version={{.VERSION}}" . {{.CLI_ARGS}} + + pack: + desc: Pack lune with UPX + cmds: + - upx --best -qo lune.min lune + - mv lune.min lune + sources: + - lune + + clean: + desc: Remove build artifacts + cmds: + - rm -rf lune + + clean-all: + desc: Remove build artifacts and config.toml + cmds: + - rm -rf lune config.toml + + release: + desc: Interactive release workflow + vars: + BUMP: + sh: gum choose "major" "minor" "patch" "prerelease" + CURRENT_VERSION: + sh: git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0" + IS_CURRENT_PRERELEASE: + sh: | + current="{{.CURRENT_VERSION}}" + if echo "$current" | grep -qE '\-[a-zA-Z]+\.[0-9]+$'; then + echo "yes" + else + echo "no" + fi + IS_PRERELEASE: + sh: | + if [ "{{.BUMP}}" = "prerelease" ]; then + echo "yes" + else + gum confirm "Create pre-release?" && echo "yes" || echo "no" + fi + PRERELEASE_SUFFIX: + sh: | + if [ "{{.BUMP}}" = "prerelease" ] && [ "{{.IS_CURRENT_PRERELEASE}}" = "yes" ]; then + # Extract suffix from current version (e.g., v1.2.3-beta.0 -> beta) + echo "{{.CURRENT_VERSION}}" | sed -E 's/.*-([a-zA-Z]+)\.[0-9]+$/\1/' + elif [ "{{.IS_PRERELEASE}}" = "yes" ]; then + gum input --placeholder "Enter pre-release suffix (e.g., beta, rc)" + fi + BASE_NEXT: + sh: | + if [ "{{.BUMP}}" = "prerelease" ] && [ "{{.IS_CURRENT_PRERELEASE}}" = "yes" ]; then + # Extract base version from current prerelease (e.g., v1.2.3-beta.0 -> v1.2.3) + echo "{{.CURRENT_VERSION}}" | sed -E 's/-[a-zA-Z]+\.[0-9]+$//' + else + svu {{.BUMP}} + fi + SUFFIX_VERSION: + sh: | + if [ "{{.IS_PRERELEASE}}" = "yes" ] && [ -n "{{.PRERELEASE_SUFFIX}}" ]; then + if [ "{{.BUMP}}" = "prerelease" ] && [ "{{.IS_CURRENT_PRERELEASE}}" = "yes" ]; then + # Increment the current prerelease number + current_num=$(echo "{{.CURRENT_VERSION}}" | sed -E 's/.*-[a-zA-Z]+\.([0-9]+)$/\1/') + echo $((current_num + 1)) + else + # Find existing tags with this suffix and get the highest version number + highest=$(git tag -l "{{.BASE_NEXT}}-{{.PRERELEASE_SUFFIX}}.*" | \ + sed 's/.*-{{.PRERELEASE_SUFFIX}}\.//' | \ + sort -n | tail -1) + if [ -n "$highest" ]; then + echo $((highest + 1)) + else + echo 0 + fi + fi + fi + NEXT: + sh: | + if [ "{{.IS_PRERELEASE}}" = "yes" ] && [ -n "{{.PRERELEASE_SUFFIX}}" ]; then + echo "{{.BASE_NEXT}}-{{.PRERELEASE_SUFFIX}}.{{.SUFFIX_VERSION}}" + else + echo "{{.BASE_NEXT}}" + fi + prompt: "Release {{.NEXT}}?" + preconditions: + - sh: '[ $(git symbolic-ref --short HEAD) = "main" ] || [ $(git symbolic-ref --short HEAD) = "dev" ]' + msg: Not on main or dev branch + - sh: "[ $(git status --porcelain=2 | wc -l) = 0 ]" + msg: "Git is dirty" + cmds: + - llm-tag {{.NEXT}} + - git push soft {{.NEXT}} + - go list -m git.secluded.site/lune@{{.NEXT}} > /dev/null + - echo "Released {{.NEXT}} and notified module proxy"