diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 04fc03e..49b40fa 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -1,23 +1,24 @@ name: CI on: + workflow_call: pull_request: push: branches: - main - tags: - - v* concurrency: - group: ${{ github.ref }} + group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true -permissions: read-all +permissions: {} jobs: test: name: Test runs-on: ${{ matrix.os }} + permissions: + contents: read strategy: matrix: os: @@ -40,6 +41,8 @@ jobs: cov: name: CodeCov runs-on: ubuntu-latest + permissions: + contents: read steps: - name: Checkout Code @@ -57,10 +60,13 @@ jobs: uses: codecov/codecov-action@v4 with: files: ./coverage.out + token: ${{ secrets.CODECOV_TOKEN }} lint: name: Lint runs-on: ubuntu-latest + permissions: + contents: read steps: - name: Checkout Code @@ -78,39 +84,3 @@ jobs: uses: golangci/golangci-lint-action@v6 with: version: latest - - release: - name: Release - runs-on: ubuntu-latest - permissions: - contents: write - - needs: - - test - - cov - - lint - - if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') - - steps: - - name: Checkout Code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Fetch Existing Tags - run: git fetch --force --tags - - - name: Parse Release Version - id: version - run: | - VERSION=${GITHUB_REF#refs/tags/v} - echo "version=$VERSION" >> $GITHUB_OUTPUT - - - name: Publish Draft Release - uses: release-drafter/release-drafter@v6 - with: - version: ${{ steps.version.outputs.version }} - publish: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..654c5b2 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,49 @@ +name: Release + +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + +permissions: {} + +jobs: + ci: + name: CI + uses: FollowTheProcess/msg/.github/workflows/CI.yml@main + secrets: inherit + permissions: + contents: read + + release: + name: Release + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: read + + needs: + - ci + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Fetch Existing Tags + run: git fetch --force --tags + + - name: Parse Release Version + id: version + run: | + VERSION=${GITHUB_REF#refs/tags/v} + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Publish Draft Release + uses: release-drafter/release-drafter@v6 + with: + version: ${{ steps.version.outputs.version }} + publish: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/LICENSE b/LICENSE index 6d3afb7..308431c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ MIT License -Copyright (c) 2023, Tom Fleet +Copyright (c) 2024, Tom Fleet Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile deleted file mode 100644 index 24a2f31..0000000 --- a/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -.PHONY: help tidy fmt test lint cover clean check sloc -.DEFAULT_GOAL := help - -COVERAGE_DATA := coverage.out -COVERAGE_HTML := coverage.html - -help: ## Show the list of available tasks - @echo "Available Tasks:\n" - @grep -E '^[a-zA-Z_0-9%-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%-10s %s\n", $$1, $$2}' - -tidy: ## Tidy dependencies in go.mod - go mod tidy - -fmt: ## Run go fmt on all source files - go fmt ./... - -test: ## Run the test suite - go test -race ./... - -lint: ## Run the linters and auto-fix if possible - golangci-lint run --fix - -cover: ## Calculate test coverage and render the html - go test -race -cover -covermode atomic -coverprofile $(COVERAGE_DATA) ./... - go tool cover -html $(COVERAGE_DATA) -o $(COVERAGE_HTML) - open $(COVERAGE_HTML) - -clean: ## Remove build artifacts and other clutter - go clean ./... - rm -rf $(COVERAGE_DATA) $(COVERAGE_HTML) - -check: test lint ## Run tests and linting in one go - -sloc: ## Print lines of code (for fun) - find . -name "*.go" | xargs wc -l | sort -nr diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..e6f0fce --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,66 @@ +# https://taskfile.dev + +version: "3" + +vars: + COV_DATA: coverage.out + +tasks: + default: + desc: List all available tasks + silent: true + cmd: task --list + + tidy: + desc: Tidy dependencies in go.mod and go.sum + cmd: go mod tidy + + fmt: + desc: Run go fmt on all source files + cmd: go fmt ./... + + test: + desc: Run the test suite + cmd: go test -race ./... {{ .CLI_ARGS }} + + bench: + desc: Run all project benchmarks + cmd: go test ./... -run None -benchmem -bench . {{ .CLI_ARGS }} + + lint: + desc: Run the linters and auto-fix if possible + cmd: golangci-lint run --fix + preconditions: + - sh: command -v golangci-lint + msg: golangci-lint not installed, see https://golangci-lint.run/usage/install/#local-installation + + doc: + desc: Render the pkg docs locally + cmd: pkgsite -open + preconditions: + - sh: command -v pkgsite + msg: pkgsite not installed, run go install golang.org/x/pkgsite/cmd/pkgsite@latest + + cov: + desc: Calculate test coverage and render the html + generates: + - "{{ .COV_DATA }}" + cmds: + - go test -race -cover -covermode atomic -coverprofile {{ .COV_DATA }} ./... + - go tool cover -html {{ .COV_DATA }} + + check: + desc: Run tests and linting in one + cmds: + - task: test + - task: lint + + sloc: + desc: Print lines of code + cmd: fd . -e go | xargs wc -l | sort -nr | head + + clean: + desc: Remove build artifacts and other clutter + cmds: + - go clean ./... + - rm -rf {{ .COV_DATA }} diff --git a/go.mod b/go.mod index ffa1cc7..0859351 100644 --- a/go.mod +++ b/go.mod @@ -7,5 +7,5 @@ require github.com/fatih/color v1.17.0 require ( github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - golang.org/x/sys v0.18.0 // indirect + golang.org/x/sys v0.22.0 // indirect ) diff --git a/go.sum b/go.sum index 4ddf511..95c2873 100644 --- a/go.sum +++ b/go.sum @@ -7,5 +7,5 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=