Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refresh buildsystem #27

Merged
merged 11 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- run: go version
- run: make clean ; go generate ./... ; go build -o build/ ./cmd/...
- run: go test -race -cover -covermode=atomic -coverprofile=coverage.out ./...
- run: ./build/pathctl -version
- uses: codecov/codecov-action@v3
with:
file: ./coverage.out
verbose: true
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- run: go version
- run: go mod tidy
- run: go generate ./...
- run: go build -o ./build/ ./cmd/...
- run: ./build/pathctl -version
- run: go test -v -race -cover -covermode=atomic -coverprofile=coverage.out ./...
- uses: codecov/codecov-action@v3
with:
file: ./coverage.out
verbose: true
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ jobs:
with:
distribution: goreleaser
version: latest
args: release --clean
args: build --clean --snapshot
env:
GITHUB_TOKEN: ${{ secrets.GORELEASER_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ generate-stamp
.DS_Store

.envrc
version.txt
31 changes: 14 additions & 17 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
project_name: unixtools
before:
hooks:
- make clean
- go generate ./...
- cat ./version/version.txt
- go mod tidy
- go generate ./...

gomod:
proxy: true
Expand All @@ -28,10 +25,10 @@ builds:
- freebsd

- main: ./cmd/mcd
hooks:
pre: go generate ./...
id: "mcd"
binary: mcd
hooks:
pre: go generate ./...
env:
- CGO_ENABLED=0
goos:
Expand All @@ -54,10 +51,10 @@ builds:
- freebsd

- main: ./cmd/popbak
hooks:
pre: go generate ./...
id: "popbak"
binary: popbak
hooks:
pre: go generate ./...
env:
- CGO_ENABLED=0
goos:
Expand All @@ -67,10 +64,10 @@ builds:
- freebsd

- main: ./cmd/portup
hooks:
pre: go generate ./...
id: "portup"
binary: portup
hooks:
pre: go generate ./...
env:
- CGO_ENABLED=0
goos:
Expand All @@ -80,10 +77,10 @@ builds:
- freebsd

- main: ./cmd/pushbak
hooks:
pre: go generate ./...
id: "pushbak"
binary: pushbak
hooks:
pre: go generate ./...
env:
- CGO_ENABLED=0
goos:
Expand All @@ -93,10 +90,10 @@ builds:
- freebsd

- main: ./cmd/refiles
hooks:
pre: go generate ./...
id: "refiles"
binary: refiles
hooks:
pre: go generate ./...
env:
- CGO_ENABLED=0
goos:
Expand All @@ -106,9 +103,9 @@ builds:
- freebsd

- main: ./cmd/seq
id: "seq"
hooks:
pre: go generate ./...
id: "seq"
binary: seq
env:
- CGO_ENABLED=0
Expand All @@ -122,8 +119,8 @@ archives:
- format: tar.gz
wrap_in_directory: true
format_overrides:
- goos: windows
format: zip
- goos: windows
format: zip
checksum:
name_template: 'checksums.txt'
snapshot:
Expand Down
29 changes: 12 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ ifdef verbose
VERBOSE = -v
endif

all: generate build check
all: version.txt build check

BUILD_TARGETS := build install

build: generate
build: version.txt
build: BUILD_ARGS=-o $(BUILDDIR)/

$(BUILD_TARGETS): $(BUILDDIR)/
Expand All @@ -46,19 +46,14 @@ $(BUILDDIR)/:

check: $(COVERAGE_REPORT_FILENAME)

$(COVERAGE_REPORT_FILENAME): generate
$(COVERAGE_REPORT_FILENAME): version.txt
go test $(VERBOSE) -mod=readonly -race -cover -covermode=atomic -coverprofile=$@ ./...

go.sum: go.mod
deps:
echo "Ensure dependencies have not been modified ..." >&2
go mod verify
go mod tidy
touch $@

generate: generate-stamp
generate-stamp: go.sum
go generate ./...
touch $@
go mod tidy

distclean: clean
rm -rf dist/
Expand All @@ -68,28 +63,28 @@ clean:
rm -rf $(BUILDDIR)
rm -f \
$(COVERAGE_REPORT_FILENAME) \
generate-stamp version-stamp
version.txt

version-stamp: generate
cp internal/version/version.txt $@
version.txt: deps
cp -f version/version.txt version.txt

list:
@echo $(BINS) | tr ' ' '\n'

macos-codesign: build
codesign --verbose -s $(CODESIGN_IDENTITY) --options=runtime $(BUILDDIR)/*

unixtools.pkg: version-stamp macos-codesign
unixtools.pkg: version.txt macos-codesign
pkgbuild --identifier io.asscrypto.unixtools \
--install-location ./Library/ --root $(BUILDDIR) $@

unixtools.dmg: version-stamp macos-codesign
VERSION=$(shell cat version-stamp); \
unixtools.dmg: version.txt macos-codesign
VERSION=$(shell cat version.txt); \
mkdir -p dist/unixtools-$${VERSION}/bin ; \
cp -a $(BUILDDIR)/* dist/unixtools-$${VERSION}/bin/ ; \
chmod 0755 dist/unixtools-$${VERSION}/bin/* ; \
create-dmg --volname unixtools --codesign $(CODESIGN_IDENTITY) \
--sandbox-safe --no-internet-enable \
$@ dist/unixtools-$${VERSION}

.PHONY: all clean check distclean build list macos-codesign generate
.PHONY: all clean check distclean build list macos-codesign deps
3 changes: 2 additions & 1 deletion cmd/elvoke/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"al.essio.dev/pkg/tools/version"
"crypto/sha256"
"flag"
"fmt"
Expand All @@ -12,6 +11,8 @@ import (
"path/filepath"
"strings"
"time"

"al.essio.dev/pkg/tools/internal/version"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion cmd/mcd/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package main

import (
"al.essio.dev/pkg/tools/version"
"flag"
"fmt"
"log"
"os"

"al.essio.dev/pkg/tools/internal/version"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion cmd/pathctl/main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package main

import (
"al.essio.dev/pkg/tools/version"
"flag"
"fmt"
"log"
"os"
"strings"

"al.essio.dev/pkg/tools/internal/version"
"al.essio.dev/pkg/tools/pathlist"
)

Expand Down
3 changes: 2 additions & 1 deletion cmd/portup/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package main

import (
"al.essio.dev/pkg/tools/version"
"flag"
"fmt"
"io"
"log"
"os"
"os/exec"
"strings"

"al.essio.dev/pkg/tools/internal/version"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion cmd/seq/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"al.essio.dev/pkg/tools/version"
"flag"
"fmt"
"log"
Expand All @@ -10,6 +9,7 @@ import (
"strings"

"al.essio.dev/pkg/tools/internal/seq"
"al.essio.dev/pkg/tools/internal/version"
)

var (
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion version/version.go → internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
)

//go:generate sh generate_version.sh
//go:embed *version.txt
//go:embed version.txt

Check failure on line 11 in internal/version/version.go

View workflow job for this annotation

GitHub Actions / lint

pattern version.txt: no matching files found (typecheck)

Check failure on line 11 in internal/version/version.go

View workflow job for this annotation

GitHub Actions / lint

pattern version.txt: no matching files found (typecheck)

Check failure on line 11 in internal/version/version.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

pattern version.txt: no matching files found

Check failure on line 11 in internal/version/version.go

View workflow job for this annotation

GitHub Actions / lint

pattern version.txt: no matching files found (typecheck)
var version string

func Short() string {
Expand Down
4 changes: 2 additions & 2 deletions pathlist/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func Test_DirList_Append(t *testing.T) {
d.Prepend("/bin///")
require.Equal(t, "/var:/bin", d.String())

//require.Equal(t, 2, d.Append("/var"), ("/usr/local/bin", "/opt/local/bin"))
//require.Equal(t, "/var:/bin:/usr/local/bin:/opt/local/bin", d.String())
// require.Equal(t, 2, d.Append("/var"), ("/usr/local/bin", "/opt/local/bin"))
// require.Equal(t, "/var:/bin:/usr/local/bin:/opt/local/bin", d.String())
Comment on lines +37 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commented-out test assertions have been uncommented but are still incomplete and incorrect. The require.Equal function is missing its first argument, which should be the testing context (t). Additionally, the expected and actual values seem to be swapped, and the syntax is incorrect.

- // require.Equal(t, 2, d.Append("/var"), ("/usr/local/bin", "/opt/local/bin"))
- // require.Equal(t, "/var:/bin:/usr/local/bin:/opt/local/bin", d.String())
+ require.Equal(t, 2, d.Append("/usr/local/bin", "/opt/local/bin"))
+ require.Equal(t, "/var:/bin:/usr/local/bin:/opt/local/bin", d.String())

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// require.Equal(t, 2, d.Append("/var"), ("/usr/local/bin", "/opt/local/bin"))
// require.Equal(t, "/var:/bin:/usr/local/bin:/opt/local/bin", d.String())
require.Equal(t, 2, d.Append("/usr/local/bin", "/opt/local/bin"))
require.Equal(t, "/var:/bin:/usr/local/bin:/opt/local/bin", d.String())

}

func Test_DirList_Prepend(t *testing.T) {
Expand Down
Loading