Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
152 lines (125 loc) · 4.88 KB
/
Copy pathMakefile
File metadata and controls
152 lines (125 loc) · 4.88 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
APP_NAME := devopstools
GH_REPO ?= redacid/DevOpsTools
# GPG key that signs release tags; its public key is in .github/release-signers.asc for CI.
GPG_KEY ?= E4EBB456A31DF880
# Single source of truth for the version: package.json (change it with `make set-version`).
RELEASE_VERSION := $(shell node -p "require('./package.json').version")
DIST := dist
DEB := $(DIST)/$(APP_NAME)_$(RELEASE_VERSION)_amd64.deb
RPM := $(DIST)/$(APP_NAME)_$(RELEASE_VERSION)_x86_64.rpm
APPIMAGE := $(DIST)/$(APP_NAME)_$(RELEASE_VERSION)_x86_64.AppImage
CLOBBER := --clobber
CURRENT_DATE = $(shell date '+%Y_%m_%d_%H_%M_%S')
CONFIG_DIR := $(HOME)/.devopstools
# colors
GREEN = $(shell tput -Txterm setaf 2)
YELLOW = $(shell tput -Txterm setaf 3)
RESET = $(shell tput -Txterm sgr0)
GRAY = $(shell tput -Txterm setaf 6)
TARGET_MAX_CHAR_NUM = 30
all: help
## Install dependencies | Development
deps:
npm ci
## Run the app with hot reload
dev:
npm run dev
## Typecheck, lint and test
check:
npm run typecheck
npx eslint .
npm test
## Run unit tests
test:
npm test
## Build and run the Electron UI tests (Playwright)
test-e2e:
npm run test:e2e
## Regenerate docs/images (README and docs site) from the built app; needs network
screenshots:
npx electron-vite build
npx playwright test -c scripts/screenshots/playwright.config.ts
## Preview the documentation site (Zensical) at http://127.0.0.1:8000
docs:
python3 -m venv .venv-docs && .venv-docs/bin/pip install -q -r requirements-docs.txt
.venv-docs/bin/zensical serve
## Copy your ~/.devopstools/tasks.json into the repo | Tasks and settings
copy_my_tasks:
cp $(CONFIG_DIR)/tasks.json ./
## Back up ~/.devopstools/tasks.json with a timestamp
backup_tasks:
cp $(CONFIG_DIR)/tasks.json $(CONFIG_DIR)/tasks_$(CURRENT_DATE).json
## Back up ~/.devopstools/settings.json with a timestamp
backup_settings:
cp $(CONFIG_DIR)/settings.json $(CONFIG_DIR)/settings_$(CURRENT_DATE).json
## Create the release signing key pair (once); then set the RELEASE_SIGNING_KEY secret
signing-key:
node scripts/gen-signing-key.mjs
## Set the version in package.json, e.g. make set-version V=0.5.0 | Build and Publish
set-version:
@test -n "$(V)" || (echo "usage: make set-version V=x.y.z" && exit 1)
npm version --no-git-tag-version $(V)
## Sign a tag for the package.json version with GPG_KEY and push it; CI verifies, builds and publishes
release:
@test -z "$$(git status --porcelain)" || (echo "Working tree is not clean; commit first" && exit 1)
git tag -s -u $(GPG_KEY) -m "Release $(RELEASE_VERSION)" $(RELEASE_VERSION)
git verify-tag $(RELEASE_VERSION)
git push origin $(RELEASE_VERSION)
## Build, package and publish a GitHub release locally (without CI)
git-publish: clean-workspace package git-release git-upload-release
## Remove build output
clean-workspace:
rm -rf out $(DIST)
## Typecheck and bundle the app (no packages)
build:
npm run build
## Build deb, rpm and AppImage
package:
npm run build:linux
package-deb:
npx electron-vite build && npx electron-builder --linux deb
package-rpm:
npx electron-vite build && npx electron-builder --linux rpm
package-appimage:
npx electron-vite build && npx electron-builder --linux AppImage
## Install the built deb locally (upgrades an existing devopstools package)
install-deb: package-deb
sudo apt install -y ./$(DEB)
## Recreate the GitHub release for RELEASE_VERSION (deletes an existing one with the same tag)
git-release:
gh release delete $(RELEASE_VERSION) --cleanup-tag -y --repo $(GH_REPO) 2>/dev/null; \
git tag -d $(RELEASE_VERSION) 2>/dev/null; \
gh release create $(RELEASE_VERSION) --generate-notes --notes "$(RELEASE_VERSION)" --repo $(GH_REPO)
## Upload deb, rpm and AppImage to the GitHub release
git-upload-release:
gh release upload $(RELEASE_VERSION) $(DEB) $(RPM) $(APPIMAGE) --repo $(GH_REPO) $(CLOBBER)
.PHONY: all deps dev check test test-e2e screenshots docs signing-key copy_my_tasks backup_tasks backup_settings set-version release git-publish \
clean-workspace build package package-deb package-rpm package-appimage install-deb \
git-release git-upload-release help
## Shows help. | Help
help:
@echo ''
@echo 'Usage:'
@echo ''
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Version: ${GREEN}$(RELEASE_VERSION)${RESET} Repo: ${GREEN}$(GH_REPO)${RESET}'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z0-9\-_]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
if (index(lastLine, "|") != 0) { \
stage = substr(lastLine, index(lastLine, "|") + 1); \
printf "\n ${GRAY}%s: \n\n", stage; \
} \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
if (index(lastLine, "|") != 0) { \
helpMessage = substr(helpMessage, 0, index(helpMessage, "|")-1); \
} \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
@echo ''