Skip to content

Commit fea9961

Browse files
authored
Merge pull request #122 from markusressel/feature/justfile
Feature/justfile
2 parents e38a552 + f0b8766 commit fea9961

3 files changed

Lines changed: 175 additions & 89 deletions

File tree

.github/workflows/go.yml

Lines changed: 111 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ on:
99
branches: [ main ]
1010

1111
jobs:
12-
generate:
13-
name: Generate cross-platform builds
12+
test:
13+
name: Test
1414
runs-on: ubuntu-latest
15-
permissions:
16-
contents: write
17-
1815
container:
1916
image: ixsystems/zfs:latest
2017
steps:
@@ -31,62 +28,129 @@ jobs:
3128
with:
3229
go-version: '^1.23'
3330

34-
- name: Run golangci-lint
35-
uses: golangci/golangci-lint-action@v9.2.1
36-
if: false
37-
env:
38-
GOFLAGS: "-buildvcs=false"
39-
with:
40-
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
41-
version: latest
42-
43-
# Optional: working directory, useful for monorepos
44-
# working-directory: somedir
31+
- uses: extractions/setup-just@v2
4532

46-
# Optional: golangci-lint command line arguments.
47-
# args: --exclude-use-default
48-
# --issues-exit-code=0
33+
- name: Test
34+
run: just test
35+
36+
build:
37+
name: Build linux/${{ matrix.goarch }}
38+
runs-on: ${{ matrix.runner }}
39+
needs: test
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
include:
44+
- goarch: amd64
45+
runner: ubuntu-latest
46+
native: true
47+
just_target: build
48+
49+
- goarch: arm64
50+
runner: ubuntu-24.04-arm
51+
native: true
52+
just_target: build
53+
54+
- goarch: ppc64le
55+
runner: ubuntu-24.04
56+
native: false
57+
just_target: build-cross
58+
cc: powerpc64le-linux-gnu-gcc
59+
dpkg_arch: ppc64el
60+
cross_pkg: crossbuild-essential-ppc64el
61+
zfs_pkg: libzfslinux-dev:ppc64el
62+
63+
- goarch: s390x
64+
runner: ubuntu-24.04
65+
native: false
66+
just_target: build-cross
67+
cc: s390x-linux-gnu-gcc
68+
dpkg_arch: s390x
69+
cross_pkg: crossbuild-essential-s390x
70+
zfs_pkg: libzfslinux-dev:s390x
71+
72+
- goarch: riscv64
73+
runner: ubuntu-24.04
74+
native: false
75+
just_target: build-cross
76+
cc: riscv64-linux-gnu-gcc
77+
dpkg_arch: riscv64
78+
cross_pkg: crossbuild-essential-riscv64
79+
zfs_pkg: libzfslinux-dev:riscv64
4980

50-
# Optional: show only new issues if it's a pull request. The default value is `false`.
51-
# only-new-issues: true
81+
steps:
82+
- name: Install libzfslinux-dev (native)
83+
if: matrix.native
84+
run: |
85+
sudo apt-get update
86+
sudo apt-get install -y libzfslinux-dev
5287
53-
# Optional: if set to true then the all caching functionality will be complete disabled,
54-
# takes precedence over all other caching options.
55-
skip-cache: true
88+
- name: Set up multiarch and cross-compilation toolchain
89+
if: ${{ !matrix.native }}
90+
run: |
91+
sudo dpkg --add-architecture ${{ matrix.dpkg_arch }}
92+
# Replace the runner's ubuntu.sources with one pinned to amd64 only.
93+
sudo tee /etc/apt/sources.list.d/ubuntu.sources > /dev/null << 'EOF'
94+
Types: deb
95+
URIs: http://azure.archive.ubuntu.com/ubuntu
96+
Suites: noble noble-updates noble-backports noble-security
97+
Components: main restricted universe multiverse
98+
Architectures: amd64
99+
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
100+
EOF
101+
# Add ports.ubuntu.com for the foreign arch
102+
printf 'Types: deb\nURIs: http://ports.ubuntu.com/ubuntu-ports\nSuites: noble noble-updates noble-security\nComponents: main restricted universe multiverse\nArchitectures: %s\nSigned-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg\n' "${{ matrix.dpkg_arch }}" | sudo tee /etc/apt/sources.list.d/ports-${{ matrix.dpkg_arch }}.sources
103+
sudo apt-get update
104+
sudo apt-get install -y ${{ matrix.cross_pkg }} ${{ matrix.zfs_pkg }}
56105
57-
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
58-
# skip-build-cache: true
106+
- name: Checkout the repository
107+
uses: actions/checkout@v6
59108

60-
- name: Test
61-
run: make test
109+
- uses: actions/setup-go@v6
110+
with:
111+
go-version: '^1.23'
62112

63-
- name: Build
64-
run: make build
113+
- uses: extractions/setup-just@v2
65114

66-
- name: Generate build files
67-
run: |
68-
GOOS="linux"
69-
GOARCH="amd64"
70-
GOFLAGS="-buildmode=exe"
71-
NAME="zfs-file-history-${GOOS}-${GOARCH}"
72-
OUTPUT_BIN="dist/${NAME}"
73-
make build GOOS="${GOOS}" OARCH="${GOARCH}" GOFLAGS="${GOFLAGS}" OUTPUT_BIN="${OUTPUT_BIN}"
74-
75-
- name: Generate build files
115+
- name: Generate build files (${{ matrix.goarch }})
116+
env:
117+
CC: ${{ matrix.cc }}
118+
GOOS: linux
119+
GOARCH: ${{ matrix.goarch }}
76120
run: |
77-
GOOS="linux"
78-
GOARCH="arm64"
79-
GOFLAGS="-buildmode=exe"
80-
NAME="zfs-file-history-${GOOS}-${GOARCH}"
81-
OUTPUT_BIN="dist/${NAME}"
82-
make build GOOS="${GOOS}" OARCH="${GOARCH}" GOFLAGS="${GOFLAGS}" OUTPUT_BIN="${OUTPUT_BIN}"
121+
OUTPUT_BIN="dist/zfs-file-history-linux-${{ matrix.goarch }}"
122+
just OUTPUT_BIN="${OUTPUT_BIN}" ${{ matrix.just_target }}
123+
file "${OUTPUT_BIN}"
124+
125+
- name: Upload artifacts
126+
uses: actions/upload-artifact@v4
127+
with:
128+
name: zfs-file-history-linux-${{ matrix.goarch }}
129+
path: dist/zfs-file-history-linux-${{ matrix.goarch }}
130+
131+
release:
132+
name: Release
133+
runs-on: ubuntu-latest
134+
permissions:
135+
contents: write
136+
needs: build
137+
if: startsWith(github.ref, 'refs/tags/')
138+
139+
steps:
140+
- name: Download all artifacts
141+
uses: actions/download-artifact@v4
142+
with:
143+
path: dist/
144+
merge-multiple: true
83145

84146
- name: Release
85147
uses: softprops/action-gh-release@v3
86-
if: startsWith(github.ref, 'refs/tags/')
87148
with:
88149
files: |
89150
dist/zfs-file-history-linux-amd64
90151
dist/zfs-file-history-linux-arm64
152+
dist/zfs-file-history-linux-ppc64le
153+
dist/zfs-file-history-linux-s390x
154+
dist/zfs-file-history-linux-riscv64
91155
env:
92156
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Justfile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
GO_FLAGS := ""
2+
NAME := "zfs-file-history"
3+
OUTPUT_BIN := "bin/" + NAME
4+
PACKAGE := "github.com/markusressel/" + NAME
5+
GIT_REV := `git rev-parse --short HEAD`
6+
DATE := `date -u +"%Y-%m-%dT%H:%M:%SZ"`
7+
VERSION := "0.8.0"
8+
9+
# Run all tests
10+
test:
11+
go clean --testcache
12+
go test -v ./...
13+
14+
# Run all tests with coverage and show summary
15+
coverage:
16+
go test -coverprofile=coverage.out ./...
17+
go tool cover -func=coverage.out
18+
19+
# Run all tests with coverage and open HTML report
20+
coverage-html:
21+
go test -coverprofile=coverage.out ./...
22+
go tool cover -html=coverage.out
23+
24+
# Builds the CLI
25+
build:
26+
@go build {{GO_FLAGS}} \
27+
-ldflags "-w -s \
28+
-X {{NAME}}/cmd/global.Version={{VERSION}} \
29+
-X {{PACKAGE}}/cmd/global.Version={{VERSION}} \
30+
-X {{NAME}}/cmd/global.Commit={{GIT_REV}} \
31+
-X {{PACKAGE}}/cmd/global.Commit={{GIT_REV}} \
32+
-X {{NAME}}/cmd/global.Date={{DATE}} \
33+
-X {{PACKAGE}}/cmd/global.Date={{DATE}}" \
34+
-a -tags netgo -o {{OUTPUT_BIN}} main.go
35+
36+
# Builds the CLI for cross-compilation (ensures CGO is enabled)
37+
build-cross:
38+
CGO_ENABLED=1 just build
39+
40+
# Build and run the CLI
41+
run: build
42+
./{{OUTPUT_BIN}}
43+
44+
# Deploy to custom bin directory
45+
deploy-custom: clean build
46+
cp ./{{OUTPUT_BIN}} ~/.custom/bin/
47+
48+
# Deploy to /usr/local/bin
49+
deploy: clean build
50+
sudo cp ./{{OUTPUT_BIN}} /usr/local/bin/
51+
sudo chmod ug+x /usr/local/bin/{{NAME}}
52+
53+
# Clean build artifacts
54+
clean:
55+
go clean
56+
rm -f {{OUTPUT_BIN}}

Makefile

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,10 @@
1-
GO_FLAGS ?=
2-
NAME := zfs-file-history
3-
OUTPUT_BIN ?= bin/${NAME}
4-
PACKAGE := github.com/markusressel/$(NAME)
5-
GIT_REV ?= $(shell git rev-parse --short HEAD)
6-
SOURCE_DATE_EPOCH ?= $(shell date +%s)
7-
DATE ?= $(shell date -u -d @${SOURCE_DATE_EPOCH} +"%Y-%m-%dT%H:%M:%SZ")
8-
VERSION ?= 0.8.0
1+
# This Makefile is a proxy for the Justfile.
2+
# It allows you to run `make <target>` which will be forwarded to `just <target>`.
93

10-
test: ## Run all tests
11-
@go clean --testcache && go test -v ./...
4+
.PHONY: default
5+
default:
6+
@just --list
127

13-
coverage: ## Run all tests with coverage and show summary
14-
@go test -coverprofile=coverage.out ./...
15-
@go tool cover -func=coverage.out
16-
17-
coverage-html: ## Run all tests with coverage and open HTML report
18-
@go test -coverprofile=coverage.out ./...
19-
@go tool cover -html=coverage.out
20-
21-
build: ## Builds the CLI
22-
@go build ${GO_FLAGS} \
23-
-ldflags "-w -s \
24-
-X ${NAME}/cmd/global.Version=${VERSION} \
25-
-X ${PACKAGE}/cmd/global.Version=${VERSION} \
26-
-X ${NAME}/cmd/global.Commit=${GIT_REV} \
27-
-X ${PACKAGE}/cmd/global.Commit=${GIT_REV} \
28-
-X ${NAME}/cmd/global.Date=${DATE} \
29-
-X ${PACKAGE}/cmd/global.Date=${DATE}" \
30-
-a -tags netgo -o ${OUTPUT_BIN} main.go
31-
32-
run: build
33-
./${OUTPUT_BIN}
34-
35-
deploy-custom: clean build
36-
cp ./${OUTPUT_BIN} ~/.custom/bin/
37-
38-
deploy: clean build
39-
sudo cp ./${OUTPUT_BIN} /usr/local/bin/
40-
sudo chmod ug+x /usr/local/bin/${NAME}
41-
42-
clean:
43-
go clean
44-
rm -f ${OUTPUT_BIN}
8+
.PHONY: %
9+
%:
10+
@just $@

0 commit comments

Comments
 (0)