diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1769792..80ef84d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,16 @@ name: CI + on: [push, pull_request] + +env: + GO_VERSION: '1.21' + TASK_VERSION: 'v3.28' + jobs: bsd: runs-on: ${{ matrix.os.host }} strategy: + fail-fast: false matrix: os: - name: freebsd @@ -11,6 +18,11 @@ jobs: version: '14.1' host: ubuntu-latest + - name: netbsd + architecture: x86-64 + version: '10.0' + host: ubuntu-latest + - name: openbsd architecture: x86-64 version: '7.5' @@ -27,8 +39,26 @@ jobs: version: ${{ matrix.os.version }} shell: bash run: | - sudo .github/workflows/install-deps.sh - make test + case "$(uname)" in + FreeBSD) + sudo pkg install -y go + ;; + NetBSD) + sudo pkgin -y install go + + for bin in /usr/pkg/bin/go1*; do + src=$bin + done + sudo ln -s "$src" /usr/pkg/bin/go + ;; + OpenBSD) + sudo pkg_add -I go + ;; + esac + PATH=$(go env GOPATH)/bin:$PATH + + go install 'github.com/go-task/task/v3/cmd/task@${{ env.TASK_VERSION }}' + task linux: runs-on: ubuntu-latest @@ -36,13 +66,18 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Install dependencies + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Install Task run: | - sudo .github/workflows/install-deps.sh + go install github.com/go-task/task/v3/cmd/task@"$TASK_VERSION" - - name: Test + - name: Build and test run: | - make test + task mac: runs-on: macos-latest @@ -50,13 +85,18 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Install dependencies + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Install Task run: | - .github/workflows/install-deps.sh + go install github.com/go-task/task/v3/cmd/task@"$TASK_VERSION" - name: Build and test run: | - make test + task windows: runs-on: windows-latest @@ -67,6 +107,22 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Test + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Install Task run: | - .\test.ps1 + go install github.com/go-task/task/v3/cmd/task@$env:TASK_VERSION + + - name: Build and test + run: | + task + + - name: Upload Windows binary + uses: actions/upload-artifact@v4 + with: + name: memsparkline-windows-amd64 + path: | + memsparkline.exe diff --git a/.github/workflows/install-deps.sh b/.github/workflows/install-deps.sh deleted file mode 100755 index cb35a5f..0000000 --- a/.github/workflows/install-deps.sh +++ /dev/null @@ -1,27 +0,0 @@ -#! /bin/sh -set -e - -if [ "$(uname)" = Darwin ]; then - brew install go -fi - -if [ "$(uname)" = Linux ]; then - : -fi - -if [ "$(uname)" = FreeBSD ]; then - pkg install -y go -fi - -if [ "$(uname)" = NetBSD ]; then - pkgin -y install go - - for bin in /usr/pkg/bin/go1*; do - src=$bin - done - ln -s "$src" /usr/pkg/bin/go -fi - -if [ "$(uname)" = OpenBSD ]; then - pkg_add -I go -fi diff --git a/.gitignore b/.gitignore index 117d748..ef8f337 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /attic/ /dist/ +/.task/ *.bak *.exe diff --git a/Makefile b/Makefile deleted file mode 100644 index 3d12e7a..0000000 --- a/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -TEST_BINARIES := test/sleep - -.PHONY: all -all: memsparkline - -.PHONY: clean -clean: - -rm memsparkline $(TEST_BINARIES) - -memsparkline: main.go - CGO_ENABLED=0 go build - -.PHONY: release -release: - go run script/release.go - -.PHONY: test -test: memsparkline $(TEST_BINARIES) - go test - -test/sleep: test/sleep.go - go build -o $@ test/sleep.go diff --git a/README.md b/README.md index 3384de4..d485851 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ go install github.com/dbohdan/memsparkline@latest - Go 1.21 - OS supported by [gopsutil](https://github.com/shirou/gopsutil) -- POSIX Make for testing +- [Task](https://taskfile.dev/) (go-task) 3.28 ## Compatibility and limitations diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..75dfbdd --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,83 @@ +version: '3' + +vars: + ext: '{{if eq OS "windows"}}.exe{{end}}' + test_binaries: | + test/sleep + +env: + CGO_ENABLED: 0 + +tasks: + default: + deps: + - all + + all: + desc: 'Build and test everything' + deps: + - build + - test + + build: + desc: 'Build all components' + deps: + - build_binaries + + build_binaries: + desc: 'Build all necessary binaries' + deps: + - build_memsparkline + - build_test_binaries + + build_binary: + desc: 'Build a single Go binary' + internal: true + cmds: + - go build -o {{.out | shellQuote}}{{.ext}} {{.src | shellQuote}} + + build_memsparkline: + desc: 'Build the memsparkline binary' + cmds: + - task: build_binary + vars: + out: memsparkline + src: main.go + sources: + - main.go + generates: + - memsparkline + + build_test_binaries: + desc: 'Build all test binaries' + deps: + - build_test_sleep + + build_test_sleep: + cmds: + - task: build_binary + vars: + src: test/sleep.go + out: test/sleep + sources: + - test/sleep.go + generates: + - test/sleep + + clean: + desc: 'Clean up generated files and binaries' + cmds: + - rm -f memsparkline + - rm -f {{range .test_binaries | splitLines }}{{. | shellQuote}} {{end}} + + release: + desc: 'Prepare a release' + cmds: + - go run script/release.go + + test: + desc: 'Run tests' + deps: + - build_binaries + cmds: + - go test diff --git a/test.ps1 b/test.ps1 deleted file mode 100644 index 71e6479..0000000 --- a/test.ps1 +++ /dev/null @@ -1,25 +0,0 @@ -Set-StrictMode -Version Latest -$ErrorActionPreference = "Stop" - -$env:CGO_ENABLED = "0" - -$extension = "" -if (((Get-Variable 'IsWindows' -Scope 'Global' -ErrorAction 'Ignore') -and - $IsWindows) -or - $env:OS -eq "Windows_NT") { - $extension = ".exe" -} -$build = @{ - "memsparkline" = "main.go" - "test/sleep" = "test/sleep.go" -} - -foreach ($dest in $build.Keys) { - $executable = "$dest$extension" - $source = $build[$dest] - - Remove-Item -Force -ErrorAction Ignore $executable - go build -o $executable $source -} - -go test