feat: add Makefile to build all locally
This commit is contained in:
24
.drone.yml
24
.drone.yml
@ -10,29 +10,13 @@ trigger:
|
||||
- refs/tags/v*
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
- name: release-build
|
||||
image: golang:1.26
|
||||
environment:
|
||||
CGO_ENABLED: "0"
|
||||
commands:
|
||||
- mkdir -p dist/linux-amd64 dist/darwin-arm64 dist/windows-amd64
|
||||
- GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w -X gitea.epss.net.cn/klesh/ss/internal/cli.Version=${DRONE_TAG}" -o dist/linux-amd64/ssm ./cmd/ssm
|
||||
- GOOS=darwin GOARCH=arm64 go build -trimpath -ldflags "-s -w -X gitea.epss.net.cn/klesh/ss/internal/cli.Version=${DRONE_TAG}" -o dist/darwin-arm64/ssm ./cmd/ssm
|
||||
- GOOS=windows GOARCH=amd64 go build -trimpath -ldflags "-s -w -X gitea.epss.net.cn/klesh/ss/internal/cli.Version=${DRONE_TAG}" -o dist/windows-amd64/ssm.exe ./cmd/ssm
|
||||
|
||||
- name: package
|
||||
image: golang:1.26
|
||||
commands:
|
||||
- apt-get update -qq && apt-get install -qq -y zip > /dev/null
|
||||
- cd dist
|
||||
- tar -C linux-amd64 -czf ssm-${DRONE_TAG}-linux-amd64.tar.gz ssm
|
||||
- tar -C darwin-arm64 -czf ssm-${DRONE_TAG}-darwin-arm64.tar.gz ssm
|
||||
- (cd windows-amd64 && zip -q ../ssm-${DRONE_TAG}-windows-amd64.zip ssm.exe)
|
||||
- sha256sum ssm-${DRONE_TAG}-linux-amd64.tar.gz ssm-${DRONE_TAG}-darwin-arm64.tar.gz ssm-${DRONE_TAG}-windows-amd64.zip > checksums.txt
|
||||
- rm -rf linux-amd64 darwin-arm64 windows-amd64
|
||||
- ls -la
|
||||
depends_on:
|
||||
- build
|
||||
- apt-get update -qq && apt-get install -qq -y make zip > /dev/null
|
||||
- make release VERSION=${DRONE_TAG}
|
||||
|
||||
- name: gitea-release
|
||||
image: plugins/gitea-release
|
||||
@ -46,4 +30,4 @@ steps:
|
||||
checksum:
|
||||
- sha256
|
||||
depends_on:
|
||||
- package
|
||||
- release-build
|
||||
|
||||
58
Makefile
Normal file
58
Makefile
Normal file
@ -0,0 +1,58 @@
|
||||
BINARY := ssm
|
||||
MODULE := gitea.epss.net.cn/klesh/ss
|
||||
VERSION ?= dev
|
||||
DIST := dist
|
||||
|
||||
LDFLAGS := -s -w -X $(MODULE)/internal/cli.Version=$(VERSION)
|
||||
|
||||
# os/arch pairs matching the 3 major platforms this project ships for.
|
||||
PLATFORMS := linux/amd64 darwin/arm64 windows/amd64
|
||||
|
||||
.DEFAULT_GOAL := build
|
||||
|
||||
.PHONY: build build-all test vet fmt clean release package help
|
||||
|
||||
build: ## Build the ssm binary for the current platform
|
||||
go build -trimpath -ldflags "$(LDFLAGS)" -o $(BINARY) ./cmd/$(BINARY)
|
||||
|
||||
build-all: clean ## Cross-compile ssm for linux/amd64, darwin/arm64, windows/amd64 into dist/<os>-<arch>/, unpackaged
|
||||
@for platform in $(PLATFORMS); do \
|
||||
os=$${platform%/*}; arch=$${platform#*/}; \
|
||||
ext=""; [ "$$os" = "windows" ] && ext=".exe"; \
|
||||
echo "==> building $$os/$$arch"; \
|
||||
mkdir -p $(DIST)/$$os-$$arch; \
|
||||
GOOS=$$os GOARCH=$$arch go build -trimpath -ldflags "$(LDFLAGS)" -o $(DIST)/$$os-$$arch/$(BINARY)$$ext ./cmd/$(BINARY) || exit 1; \
|
||||
done
|
||||
|
||||
test: ## Run the test suite
|
||||
go test ./...
|
||||
|
||||
vet: ## Run go vet
|
||||
go vet ./...
|
||||
|
||||
fmt: ## Check formatting (gofmt -l)
|
||||
gofmt -l .
|
||||
|
||||
clean: ## Remove build/release artifacts
|
||||
rm -rf $(DIST) $(BINARY) $(BINARY).exe
|
||||
|
||||
release: build-all ## Cross-compile for linux/amd64, darwin/arm64, windows/amd64 and package into dist/
|
||||
@$(MAKE) --no-print-directory package
|
||||
|
||||
package: ## Archive dist/<os>-<arch>/ directories into per-platform tar.gz/zip + checksums.txt
|
||||
@cd $(DIST) && \
|
||||
for platform in $(PLATFORMS); do \
|
||||
os=$${platform%/*}; arch=$${platform#*/}; \
|
||||
name=$(BINARY)-$(VERSION)-$$os-$$arch; \
|
||||
if [ "$$os" = "windows" ]; then \
|
||||
(cd $$os-$$arch && zip -q ../$$name.zip $(BINARY).exe); \
|
||||
else \
|
||||
tar -C $$os-$$arch -czf $$name.tar.gz $(BINARY); \
|
||||
fi; \
|
||||
rm -rf $$os-$$arch; \
|
||||
done; \
|
||||
sha256sum *.tar.gz *.zip > checksums.txt; \
|
||||
ls -la
|
||||
|
||||
help: ## Show this help
|
||||
@grep -E '^[a-zA-Z_-]+:.*## ' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*## "}; {printf " %-10s %s\n", $$1, $$2}'
|
||||
18
README.md
18
README.md
@ -17,7 +17,7 @@ A CLI for surfing the internet scientifically, written in Go.
|
||||
```bash
|
||||
git clone ssh://git@gitea.epss.net.cn:2223/klesh/ss.git
|
||||
cd ss
|
||||
go build -o ssm ./cmd/ssm
|
||||
make build
|
||||
```
|
||||
|
||||
This produces a single `ssm` (or `ssm.exe` on Windows) binary with no runtime dependencies — templates and hook scripts are embedded in the binary.
|
||||
@ -124,11 +124,21 @@ ssm service status [--name <name>]
|
||||
## Development
|
||||
|
||||
```bash
|
||||
go build ./...
|
||||
go vet ./...
|
||||
go test ./...
|
||||
make build # build ssm for the current platform
|
||||
make test # go test ./...
|
||||
make vet # go vet ./...
|
||||
make fmt # check formatting (gofmt -l)
|
||||
make help # list all targets
|
||||
```
|
||||
|
||||
### Releasing
|
||||
|
||||
```bash
|
||||
make release VERSION=v1.0.0
|
||||
```
|
||||
|
||||
Cross-compiles for linux/amd64, darwin/arm64, and windows/amd64, and packages each into `dist/` as a `.tar.gz`/`.zip` alongside a `checksums.txt`. Pushing a `vX.Y.Z` tag runs the same thing via `.drone.yml` and publishes the artifacts as a Gitea release.
|
||||
|
||||
## License
|
||||
|
||||
MIT License - see LICENSE file for details.
|
||||
|
||||
Reference in New Issue
Block a user