-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
168 lines (126 loc) · 6.58 KB
/
Makefile
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
168
# This Makefile has been written according to guidelines at
# https://tech.davis-hansson.com/p/make/
# Use ">" instead of "\t" for blocks to avoid surprising whitespace issues
ifeq ($(origin .RECIPEPREFIX), undefined)
$(error "This Make does not support .RECIPEPREFIX. Please use GNU Make 4.0 or later. If you've installed an up-to-date Make with homebrew, you maye need to invoke 'gmake' instead of 'make'.")
endif
.RECIPEPREFIX = >
# Make sure we use actual bash instead of zsh or sh
SHELL := bash
# Enforce bash "strict mode"
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
.SHELLFLAGS := -euo pipefail -c
# Use one shell session per rule instead of one shell session per line
.ONESHELL:
# Indicate this Makefile is portable
.POSIX:
# Delete the target of a Make rule if the rule fails
.DELETE_ON_ERROR:
# Warn on undefined variables
MAKEFLAGS += --warn-undefined-variables
# Disable all the magical-but-unreadable bits of Make
MAKEFLAGS += --no-builtin-rules
# Wrap npx so it only uses local dependencies
NPX := npx --no-install
###############################################################################
## Constants
###############################################################################
VERSION ?= $(shell jq -r .version package.json)
BUILDKITE_VERSION := $(shell VERSION=$(VERSION) scripts/get-buildkite-version)
ACTION_VERSION := $(shell VERSION=$(VERSION) scripts/get-action-version)
###############################################################################
## Files
###############################################################################
SRC_FILES := $(shell find src -name '*.ts')
DIST_CJS_FILES := $(subst .ts,.js, $(subst src,dist/cjs,$(SRC_FILES)))
DIST_ESM_FILES := $(subst .ts,.js, $(subst src,dist/esm,$(SRC_FILES)))
DIST_TYPES_FILES := $(subst .ts,.d.ts, $(subst src,dist/types,$(SRC_FILES)))
EXES := dist/pkg/crr-$(VERSION)-linux dist/pkg/crr-$(VERSION)-macos dist/pkg/crr-$(VERSION)-windows.exe dist/ncc/index.js
EXE_SHAS := $(addsuffix .sha1, $(EXES))
ACTION_SRC_FILES := $(shell find integrations/action/src -name '*.ts')
ACTION_BUILD_FILES := $(subst .ts,.js, $(subst src,build,$(ACTION_SRC_FILES)))
ACTION_SHORT := dist/index.js README.md
ACTION_ALL := $(addprefix integrations/action/, $(ACTION_SHORT)) $(ACTION_BUILD_FILES)
BUILDKITE_ALL_SHORT := bin/crr-linux bin/crr-macos bin/crr-windows.exe README.md
BUILDKITE_ALL := $(addprefix integrations/check-run-reporter-buildkite-plugin/, $(BUILDKITE_ALL_SHORT))
###############################################################################
## Default Target
###############################################################################
all: $(EXES) $(EXE_SHAS) $(DIST_CJS_FILES) $(DIST_ESM_FILES) $(DIST_TYPES_FILES) README.md $(ACTION_ALL) $(BUILDKITE_ALL)
clean:
> $(NPX) rimraf dist integrations/*/dist integrations/check-run-reporter-buildkite-plugin/bin
> sed -i.bak -e "s#$(BUILDKITE_VERSION)#0.0.0#g" integrations/check-run-reporter-buildkite-plugin/README.md
> $(NPX) rimraf integrations/check-run-reporter-buildkite-plugin/README.md.bak
> sed -i.bak -e "s#$(ACTION_VERSION)#0.0.0#g" integrations/action/README.md
> $(NPX) rimraf integrations/action/README.md.bak
> $(NPX) rimraf .action_version .buildkite_version
.PHONY: clean
###############################################################################
## Helpers
###############################################################################
# Print any Makefile variable
# Usage: make print-USER
print-% : ; @echo $* = $($*)
.PHONY: print-%
###############################################################################
## Rules
###############################################################################
$(DIST_CJS_FILES) &: $(SRC_FILES)
> $(NPX) rimraf dist/cjs
> BUILD_TARGET=cjs $(NPX) babel --source-maps --extensions '.js,.ts,.tsx' -d dist/cjs src
$(DIST_ESM_FILES) &: $(SRC_FILES)
> $(NPX) rimraf dist/esm
> BUILD_TARGET=esm $(NPX) babel --source-maps --extensions '.js,.ts,.tsx' -d dist/esm src
$(DIST_TYPES_FILES) &: $(SRC_FILES)
> $(NPX) rimraf dist/types
> $(NPX) tsc --emitDeclarationOnly
> $(NPX) rimraf dist/types/integrations
%.sha1: %
> sha1sum $< > $@
###############################################################################
## Targets
###############################################################################
dist/ncc/index.js: $(SRC_FILES)
> $(NPX) ncc build ./src/cli.ts --source-map --out dist/ncc
# Vercel has abandoned pkg, so we're stuck with bundling node18 likely until
# node22 goes lts with native support for single executable applications
dist/pkg/crr-$(VERSION)-linux: dist/ncc/index.js
> $(NPX) pkg . --target node18-linux --output $@
# Vercel has abandoned pkg, so we're stuck with bundling node18 likely until
# node22 goes lts with native support for single executable applications
dist/pkg/crr-$(VERSION)-macos: dist/ncc/index.js
> $(NPX) pkg . --target node18-macos --output $@
# Vercel has abandoned pkg, so we're stuck with bundling node18 likely until
# node22 goes lts with native support for single executable applications
dist/pkg/crr-$(VERSION)-windows.exe: dist/ncc/index.js
> $(NPX) pkg . --target node18-windows --output $@
README.md:
> $(NPX) markdown-toc -i --bullets='-' --maxdepth=3 README.md
> $(NPX) prettier --write README.md
.PHONY: README.md
.buildkite_version:
> echo $(BUILDKITE_VERSION) > .buildkite_version
integrations/check-run-reporter-buildkite-plugin/bin/crr-%: dist/pkg/crr-$(VERSION)-%
> mkdir -p $(@D)
> cp $< $@
integrations/check-run-reporter-buildkite-plugin/README.md: .buildkite_version
> sed -i.bak -e "s#0.0.0#$(BUILDKITE_VERSION)#g" $@
> rm [email protected]
###############################################################################
## Action Rules
###############################################################################
$(ACTION_BUILD_FILES) &: $(ACTION_SRC_FILES)
> $(NPX) rimraf integrations/actions/build
> $(NPX) -w integrations/action babel --source-maps --extensions '.js,.ts' -d build src
###############################################################################
## Action Targets
###############################################################################
# for reasons I can't entirely explain, the `require.main === module` check
# doesn't work if ncc is allowed to do the compilation.
integrations/action/dist/index.js: $(ACTION_BUILD_FILES) $(DIST_CJS_FILES)
> $(NPX) -w integrations/action ncc build build/index.js --source-map
.action_version:
> echo $(ACTION_VERSION) > .action_version
integrations/action/README.md: .action_version
> sed -i.bak -e "s#0.0.0#$(ACTION_VERSION)#g" $@
> rm [email protected]