forked from dupuy/reliabot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
148 lines (128 loc) · 5.23 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
TARGETS := all build clean devtools major minor patch prerelease release \
tests uninstall uninstall-pipx update words
TOOLS := git-cliff poetry tox vale
TOOL_DIR := ${HOME}/.local/bin
.PHONY: $(TARGETS) $(TOOLS) $(addprefix has-,$(TOOLS))
echo=@echo ""
_:
@echo Available targets are:
$(echo) $(TARGETS)
$(echo) $(TOOLS)
$(echo)
$(echo) "- $(ALL)"
$(echo) "- $(BUILD)"
$(echo) "- $(CLEAN)"
$(echo) "- $(DEVTOOLS)"
$(echo) "- $(MAJOR)"
$(echo) "- $(MINOR)"
$(echo) "- $(PATCH)"
$(echo) "- $(PRERELEASE)"
$(echo) "- $(RELEASE)"
$(echo) "- $(TESTS)"
$(echo) "- $(TOX)"
$(echo) "- $(UNINSTALL)"
$(echo) "- $(UNINSTALL_PIPX)"
$(echo) "- $(UPDATE)"
$(echo) "- $(VALE)"
$(echo) "- $(WORDS)"
ALL= all - Run code tests and review word quality of docs, then build package
all: tests words
$(MAKE) build
BUILD= build - Build Python package
build:
poetry build -n
CLEAN= clean - Remove (generated) files ignored by Git
clean:
git clean -diX
DEVTOOLS= devtools - Install all development and documentation tools
devtools: $(TOOLS)
MAJOR= major - Generate a major version release branch/PR
MINOR= minor - Generate a minor version release branch/PR
PATCH= patch - Generate a patch version release branch/PR
PRERELEASE= prerelease - Generate a pre-release branch/PR
RELEASE= release - Generate a semantic version release branch/PR
PR_MAKE_TAG=sed -e 's/^/v/' -e 's/a/-alpha./' -e 's/b/-beta./' -e 's/rc/-rc./'
VERSION_TAG=poetry version --short | $(PR_MAKE_TAG)
MAJOR_VERSION=poetry version --short | sed -n -e '{s/\..*//p;q;}'
COMPARE=https://github.com/dupuy/reliabot/compare
major minor patch prerelease release: has-git-cliff has-poetry
git checkout main
@case $@ in \
release) \
VERSION=`git-cliff -c bump.toml --bumped-version | sed 's/-.*//'` \
;; \
*) VERSION=$@ ;; \
esac; poetry version "$${VERSION#v}"
@RELEASE="`$(VERSION_TAG)`" && \
CHANGELOG="docs/CHANGELOG-`$(MAJOR_VERSION)`.md" && \
CHANGELOG_TMP="docs/changelog-$$$$~" && \
LAST=`git describe | sed 's/-.*//'` && \
git checkout -b "release-$${RELEASE}"; mkdir -p docs && \
git-cliff --config=pyproject.toml --tag "$${RELEASE}" $${LAST}.. \
>"$${CHANGELOG_TMP}" && \
sed '/^# C/,/^releases/d' "$${CHANGELOG}" >>"$${CHANGELOG_TMP}" && \
echo "[$${RELEASE#v}]: $(COMPARE)/$${LAST}..$${RELEASE}" \
>>"$${CHANGELOG_TMP}" && \
mv "$${CHANGELOG_TMP}" "$${CHANGELOG}" && \
ln -sf "$${CHANGELOG}" CHANGELOG.md
git add docs/CHANGELOG-*.md
-pre-commit run mdformat
poetry lock
git add pyproject.toml CHANGELOG.md docs/CHANGELOG-*.md poetry.lock
TITLE="chore(release): reliabot `$(VERSION_TAG)`" && \
SKIP=codespell,markdown-link-check,vale git commit -m "$${TITLE}" && \
RELEASE="`git branch --show-current`" && \
git push --set-upstream origin "$${RELEASE}" && \
if which gh >/dev/null 2>&1; then \
gh pr create --fill-verbose --title="$${TITLE}"; \
else \
URL=`git config remote.origin.url` && \
BASE=`expr $${URL} : '.*github\.com.\(.*\)\.git'` && \
echo "PR: https://github.com/$${BASE}/compare/$${RELEASE}?expand=1"; \
fi
PIPX=${TOOL_DIR}/pipx
POETRY= poetry - Install poetry if necessary
$(addprefix has-,${TOOLS}):
@TOOL_NAME=$(subst has-,,$@); which $(subst has-,,$@) || { \
echo "'$${TOOL_NAME}' not found in \$$PATH"; \
printf "Install '$${TOOL_NAME}' with system (brew, choco, etc.)"; \
echo " or by running 'make $${TOOL_NAME}'."; exit 1; \
}
$(TOOLS): ${TOOL_DIR}/pipx
${TOOL_DIR}/pipx install --force $@
${TOOL_DIR}/pipx ensurepath
@# vale self-downloads on first install
@PATH=$(TOOL_DIR):$$PATH; \
case $@ in vale) vale sync || pipx uninstall $@;; esac
${TOOL_DIR}/pipx:
python3 -m pip install --upgrade --user pip
python3 -m pip install --upgrade --user certifi pipx
python3 -m pipx install --force pipx
yes | python3 -m pip uninstall pipx
${TOOL_DIR}/pipx ensurepath
TESTS= tests - Run full test suite
tests: has-tox
tox
TOX= tox - Install tox if necessary
UNINSTALL= uninstall - Uninstall tools and styles
uninstall:
if [ -x "$(PIPX)" ]; then \
for T in $(TOOLS); do \
pipx uninstall $$T; \
done; \
fi
git clean -i styles
UNINSTALL_PIPX= uninstall-pipx - Uninstall pipx and all tools it installed
uninstall-pipx:
rm -rf $(TOOL_DIR)
UPDATE= update - Update vale styles
update: has-vale
vale sync
VALE= vale - Install vale if necessary
VALE_PKGS = $(shell sed -n 's/Packages *=//p' .vale.ini | tr -d ,)
VALE_STYLES = $(addprefix styles/,$(VALE_PKGS))
WORDS= words - Check documentation words for style
words: has-vale $(VALE_STYLES)
vale ./*.md .github/ISSUE_TEMPLATE/*.md
$(addprefix %/,${PACKAGES}): %
${MAKE} sync