-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
167 lines (135 loc) · 6.82 KB
/
Makefile
File metadata and controls
167 lines (135 loc) · 6.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
PHP_VERSION = 8.4.16
GOOS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
GOARCH := $(shell uname -m)
ifeq ($(GOARCH), x86_64)
GOARCH=amd64
endif
ifeq ($(GOARCH), aarch64)
GOARCH=arm64
endif
FLAVOR ?= upsun
ifeq ($(GOOS), darwin)
GORELEASER_ID = $(FLAVOR)-macos
else
GORELEASER_ID = $(FLAVOR)
endif
# Use GORELEASER_CURRENT_TAG if set (from GitHub Actions), otherwise derive from git
ifeq ($(origin VERSION), undefined)
VERSION := $(or $(GORELEASER_CURRENT_TAG),$(shell git describe --tags --always 2>/dev/null || echo "0.0.0-dev"))
endif
# Tooling versions
GORELEASER_VERSION=v2.12.0
REPOGEN_VERSION=v1.0.4
# PHP binaries are downloaded from cli-php-builds releases.
# See: https://github.com/upsun/cli-php-builds
PHP_BUILDS_REPO = upsun/cli-php-builds
PHP_RELEASE_URL = https://github.com/$(PHP_BUILDS_REPO)/releases/download/php-$(PHP_VERSION)
# Build the legacy CLI phar from the legacy/ subdirectory.
# The self:build command handles composer --no-dev rebuild, Box installation, and cache warming.
internal/legacy/archives/platform.phar: legacy/vendor/autoload.php
mkdir -p internal/legacy/archives
cd legacy && php bin/platform self:build --no-interaction --output=../internal/legacy/archives/platform.phar
legacy/vendor/autoload.php:
cd legacy && composer install --no-interaction
# Download PHP binary for the current platform.
internal/legacy/archives/php_darwin_$(GOARCH):
mkdir -p internal/legacy/archives
curl -fSL "$(PHP_RELEASE_URL)/php-$(PHP_VERSION)-darwin-$(GOARCH)" -o $@
chmod +x $@
internal/legacy/archives/php_linux_$(GOARCH):
mkdir -p internal/legacy/archives
curl -fSL "$(PHP_RELEASE_URL)/php-$(PHP_VERSION)-linux-$(GOARCH)" -o $@
chmod +x $@
internal/legacy/archives/php_windows_amd64: internal/legacy/archives/php_windows.exe internal/legacy/archives/cacert.pem
internal/legacy/archives/php_windows.exe:
mkdir -p internal/legacy/archives
curl -fSL "$(PHP_RELEASE_URL)/php-$(PHP_VERSION)-windows-amd64.exe" -o $@
.PHONY: internal/legacy/archives/cacert.pem
internal/legacy/archives/cacert.pem:
mkdir -p internal/legacy/archives
curl -fSL https://curl.se/ca/cacert.pem -o internal/legacy/archives/cacert.pem
# Download all PHP binaries (for release builds).
.PHONY: download-php
download-php:
mkdir -p internal/legacy/archives
curl -fSL "$(PHP_RELEASE_URL)/php-$(PHP_VERSION)-linux-amd64" -o internal/legacy/archives/php_linux_amd64
curl -fSL "$(PHP_RELEASE_URL)/php-$(PHP_VERSION)-linux-arm64" -o internal/legacy/archives/php_linux_arm64
curl -fSL "$(PHP_RELEASE_URL)/php-$(PHP_VERSION)-darwin-amd64" -o internal/legacy/archives/php_darwin_amd64
curl -fSL "$(PHP_RELEASE_URL)/php-$(PHP_VERSION)-darwin-arm64" -o internal/legacy/archives/php_darwin_arm64
curl -fSL "$(PHP_RELEASE_URL)/php-$(PHP_VERSION)-windows-amd64.exe" -o internal/legacy/archives/php_windows.exe
curl -fSL https://curl.se/ca/cacert.pem -o internal/legacy/archives/cacert.pem
chmod +x internal/legacy/archives/php_linux_* internal/legacy/archives/php_darwin_*
php: internal/legacy/archives/php_$(GOOS)_$(GOARCH)
.PHONY: goreleaser
goreleaser:
command -v goreleaser >/dev/null || go install github.com/goreleaser/goreleaser/v2@$(GORELEASER_VERSION)
.PHONY: repogen
repogen:
command -v repogen >/dev/null || go install github.com/ralt/repogen/cmd/repogen@$(REPOGEN_VERSION)
.PHONY: single
single: goreleaser internal/legacy/archives/platform.phar php ## Build a single target release
PHP_VERSION=$(PHP_VERSION) goreleaser build --single-target --id=$(GORELEASER_ID) --snapshot --clean
.PHONY: snapshot
snapshot: goreleaser internal/legacy/archives/platform.phar php internal/legacy/archives/cacert.pem ## Build a snapshot release
ifndef RSA_SIGNING_KEY_FILE
$(error RSA_SIGNING_KEY_FILE is not set. Set it to the path of your RSA private key for APK signing, or use 'make snapshot-no-nfpm' to skip packaging.)
endif
ifndef GPG_SIGNING_KEY_FILE
$(error GPG_SIGNING_KEY_FILE is not set. Set it to the path of your GPG private key for RPM signing, or use 'make snapshot-no-nfpm' to skip packaging.)
endif
PHP_VERSION=$(PHP_VERSION) goreleaser release --snapshot --clean --skip=publish,announce
.PHONY: snapshot-no-nfpm
snapshot-no-nfpm: goreleaser internal/legacy/archives/platform.phar php ## Build a snapshot release without package signing
PHP_VERSION=$(PHP_VERSION) goreleaser release --snapshot --clean --skip=publish,announce,nfpm
.PHONY: clean-phar
clean-phar: ## Clean up the legacy CLI phar
rm -f internal/legacy/archives/platform.phar
rm -rf legacy/vendor
.PHONY: release
release: goreleaser clean-phar internal/legacy/archives/platform.phar php internal/legacy/archives/cacert.pem ## Create and publish a release
ifndef RSA_SIGNING_KEY_FILE
$(error RSA_SIGNING_KEY_FILE is not set. Set it to the path of your RSA private key for APK signing.)
endif
ifndef GPG_SIGNING_KEY_FILE
$(error GPG_SIGNING_KEY_FILE is not set. Set it to the path of your GPG private key for RPM signing.)
endif
PHP_VERSION=$(PHP_VERSION) goreleaser release --clean
@if echo "$(VERSION)" | grep -qv -- '-'; then \
VERSION=$(VERSION) bash cloudsmith.sh; \
else \
echo "Skipping Cloudsmith upload for pre-release version $(VERSION)"; \
fi
.PHONY: test
# "We encourage users of encoding/json to test their programs with GOEXPERIMENT=jsonv2 enabled" (https://tip.golang.org/doc/go1.25)
test: ## Run unit tests (excludes integration tests)
GOEXPERIMENT=jsonv2 go test -v -race -cover -count=1 $$(go list ./... | grep -v /integration-tests)
.PHONY: integration-test
integration-test: single ## Run integration tests (requires built CLI)
cd integration-tests && GOEXPERIMENT=jsonv2 go test -v -count=1 ./...
.PHONY: lint
lint: lint-gomod lint-golangci ## Run linters.
.PHONY: lint-gomod
lint-gomod:
go mod tidy -diff
.PHONY: lint-golangci
lint-golangci:
golangci-lint run --timeout=2m
.goreleaser.vendor.yaml: check-vendor ## Generate the goreleaser vendor config
cat .goreleaser.vendor.yaml.tpl | envsubst > .goreleaser.vendor.yaml
.PHONY: check-vendor
check-vendor: ## Check that the vendor CLI variables are set
ifndef VENDOR_NAME
$(error VENDOR_NAME is undefined)
endif
ifndef VENDOR_BINARY
$(error VENDOR_BINARY is undefined)
endif
.PHONY: vendor-release
vendor-release: check-vendor .goreleaser.vendor.yaml goreleaser clean-phar internal/legacy/archives/platform.phar php ## Release a vendor CLI
PHP_VERSION=$(PHP_VERSION) VENDOR_BINARY="$(VENDOR_BINARY)" VENDOR_NAME="$(VENDOR_NAME)" goreleaser release --clean --config=.goreleaser.vendor.yaml
.PHONY: vendor-snapshot
vendor-snapshot: check-vendor .goreleaser.vendor.yaml goreleaser internal/legacy/archives/platform.phar php ## Build a vendor CLI snapshot
PHP_VERSION=$(PHP_VERSION) VENDOR_BINARY="$(VENDOR_BINARY)" VENDOR_NAME="$(VENDOR_NAME)" goreleaser build --snapshot --clean --config=.goreleaser.vendor.yaml
.PHONY: goreleaser-check
goreleaser-check: goreleaser ## Check the goreleaser configs
PHP_VERSION=$(PHP_VERSION) goreleaser check --config=.goreleaser.yaml