Skip to content

Commit

Permalink
build(task): replace Make and PowerShell with Task
Browse files Browse the repository at this point in the history
It will be good to have a single cross-platform build file.
We currently have two, `Makefile` and `test.ps1`.
They are complex enough
we should avoid maintaining both at the same time.
  • Loading branch information
dbohdan committed Dec 3, 2024
1 parent 4485e67 commit 6bca549
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 106 deletions.
50 changes: 39 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,40 @@ 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)
doas pkg_add -I go
;;
esac
go install github.com/go-task/task/v3/cmd/task@latest
task
linux:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo .github/workflows/install-deps.sh
- name: Set up Task
uses: arduino/setup-task@v2
with:
version: 3.x

- name: Test
- name: Build and test
run: |
make test
task
mac:
runs-on: macos-latest
Expand All @@ -57,11 +75,16 @@ jobs:

- name: Install dependencies
run: |
.github/workflows/install-deps.sh
brew install go
- name: Set up Task
uses: arduino/setup-task@v2
with:
version: 3.x

- name: Build and test
run: |
make test
task
windows:
runs-on: windows-latest
Expand All @@ -72,9 +95,14 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Test
- name: Set up Task
uses: arduino/setup-task@v2
with:
version: 3.x

- name: Build and test
run: |
.\test.ps1
task
- name: Upload Windows binary
uses: actions/upload-artifact@v4
Expand Down
27 changes: 0 additions & 27 deletions .github/workflows/install-deps.sh

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/attic/
/dist/
/.task/

*.bak
*.exe
Expand Down
36 changes: 0 additions & 36 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ go install github.com/dbohdan/recur/v2@latest
## Build requirements

- Go 1.19
- POSIX Make for testing
- [Task](https://taskfile.dev/) (go-task)

Note that up-to-date code is in the directory [`v2/`](v2/)
according to the [Go convention](https://go.dev/blog/v2-go-modules).
Expand Down
2 changes: 1 addition & 1 deletion README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ go install github.com/dbohdan/recur/v2@latest
## Build requirements

- Go 1.19
- POSIX Make for testing
- [Task](https://taskfile.dev/) (go-task)

Note that up-to-date code is in the directory [`v2/`](v2/)
according to the [Go convention](https://go.dev/blog/v2-go-modules).
Expand Down
143 changes: 143 additions & 0 deletions taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
version: '3'

vars:
dist_dir: dist/
subdir: v2
test_binaries:
- test/env
- test/exit99
- test/hello
- test/sleep

env:
CGO_ENABLED: 0

tasks:
default:
deps:
- all

all:
desc: 'Build and test everything'
deps:
- build_readme
- test

build:
desc: 'Build all components'
deps:
- build_readme
- build_binaries

build_binaries:
desc: 'Build all necessary binaries'
deps:
- build_recur
- build_test_binaries

build_binary:
desc: 'Build a single Go binary'
internal: true
cmds:
- go build -o {{.out | q}} {{.src | q}}

build_readme:
desc: 'Generate README.md from template'
deps:
- build_recur
dir: '{{.subdir}}'
cmds:
- go run ../script/render_template.go < ../README.template.md > ../README.md
status:
- README.template.md
- '{{.subdir}}/main.go'
generates:
- README.md

build_recur:
desc: 'Build the recur binary'
cmds:
- task: build_binary
vars:
out: '{{.subdir | q}}/recur'
src: ./{{.subdir | q}}/main.go
sources:
- '{{.subdir}}/main.go'
generates:
- '{{.subdir}}/recur'

build_test_binaries:
desc: 'Build all test binaries'
deps:
- build_test_env
- build_test_exit99
- build_test_hello
- build_test_sleep

build_test_env:
cmds:
- task: build_binary
vars:
src: test/env.go
out: test/env
sources:
- test/env.go
generates:
- test/env

build_test_exit99:
cmds:
- task: build_binary
vars:
src: test/exit99.go
out: test/exit99
sources:
- test/exit99.go
generates:
- test/exit99

build_test_hello:
cmds:
- task: build_binary
vars:
src: test/hello.go
out: test/hello
sources:
- test/hello.go
generates:
- test/hello

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 README.md
- rm -f {{.subdir | q}}/recur
- rm -f {{range .test_binaries}}{{. | q}} {{end}}

release:
desc: 'Prepare a release'
dir: '{{.subdir}}'
cmds:
- go run ../script/release.go
- mkdir -p ../{{.dist_dir | q}}
- mv dist/* ../{{.dist_dir | q}}
- rmdir dist/

test:
desc: 'Run tests'
deps:
- build_binaries
dir: '{{.subdir}}'
cmds:
- go test
30 changes: 0 additions & 30 deletions test.ps1

This file was deleted.

0 comments on commit 6bca549

Please sign in to comment.