Skip to content

Commit c67e73e

Browse files
committed
Makefile: update to work with modern make versions
Apparently the environment variable setting from commit da2a969 (Makefile: add a few new targets to streamline my release workflow, 2019-10-21) does not work with newer make versions, which re-evaluate the environment variables recursively any time someone sneezes and make thinks the sneeze might affect the value of the variable. Restructure in a way to ensure the environment variables are set only once. Signed-off-by: Elijah Newren <[email protected]>
1 parent 0f1c9d8 commit c67e73e

File tree

1 file changed

+60
-57
lines changed

1 file changed

+60
-57
lines changed

Makefile

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -49,84 +49,87 @@ install: snag_docs #fixup_locale
4949
# don't work for you, I don't care. These tasks modify branches and upload
5050
# releases and whatnot, and presume a directory layout I have locally.
5151
#
52-
update_docs: export GIT_WORK_TREE=$(shell mktemp -d)
53-
update_docs: export GIT_INDEX_FILE=$(shell mktemp)
54-
update_docs: export COMMIT=$(shell git rev-parse HEAD)
5552
update_docs:
56-
# Sanity check; we'll build docs in a clone of a git repo
57-
test -d ../git
58-
# Sanity check; docs == origin/docs
59-
test -z "$(git rev-parse docs origin/docs | uniq -u)"
60-
# Avoid spurious errors by forcing index to be well formatted, if empty
61-
git read-tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 # empty tree
62-
# Symlink git-filter-repo.txt documentation into git and build it
63-
ln -sf ../../git-filter-repo/Documentation/git-filter-repo.txt ../git/Documentation/
64-
make -C ../git/Documentation -j4 man html
65-
# Take the built documentation and lay it out nicely
66-
mkdir $$GIT_WORK_TREE/html
67-
mkdir $$GIT_WORK_TREE/man1
68-
cp -a ../git/Documentation/*.html $$GIT_WORK_TREE/html/
69-
cp -a ../git/Documentation/git-filter-repo.1 $$GIT_WORK_TREE/man1/
70-
dos2unix $$GIT_WORK_TREE/html/*
71-
# Add new version of the documentation as a commit, if it differs
72-
git --work-tree $$GIT_WORK_TREE add .
53+
# Set environment variables once
54+
export GIT_WORK_TREE=$(shell mktemp -d) \
55+
export GIT_INDEX_FILE=$(shell mktemp) \
56+
COMMIT=$(shell git rev-parse HEAD) \
57+
&& \
58+
# Sanity check; we'll build docs in a clone of a git repo \
59+
test -d ../git && \
60+
# Sanity check; docs == origin/docs \
61+
test -z "$(git rev-parse docs origin/docs | uniq -u)" && \
62+
# Avoid spurious errors by forcing index to be well formatted, if empty \
63+
git read-tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 && # empty tree \
64+
# Symlink git-filter-repo.txt documentation into git and build it \
65+
ln -sf ../../git-filter-repo/Documentation/git-filter-repo.txt ../git/Documentation/ && \
66+
make -C ../git/Documentation -j4 man html && \
67+
# Take the built documentation and lay it out nicely \
68+
mkdir $$GIT_WORK_TREE/html && \
69+
mkdir $$GIT_WORK_TREE/man1 && \
70+
cp -a ../git/Documentation/*.html $$GIT_WORK_TREE/html/ && \
71+
cp -a ../git/Documentation/git-filter-repo.1 $$GIT_WORK_TREE/man1/ && \
72+
dos2unix $$GIT_WORK_TREE/html/* && \
73+
# Add new version of the documentation as a commit, if it differs \
74+
git --work-tree $$GIT_WORK_TREE add . && \
7375
git diff --quiet docs || git write-tree \
7476
| xargs git commit-tree -p docs -m "Update docs to $$COMMIT" \
75-
| xargs git update-ref refs/heads/docs
76-
# Remove temporary files
77-
rm -rf $$GIT_WORK_TREE
78-
rm $$GIT_INDEX_FILE
79-
# Push the new documentation upstream
80-
git push origin docs
81-
# Notify of completion
82-
@echo
83-
@echo === filter-repo docs branch updated ===
77+
| xargs git update-ref refs/heads/docs && \
78+
# Remove temporary files \
79+
rm -rf $$GIT_WORK_TREE && \
80+
rm $$GIT_INDEX_FILE && \
81+
# Push the new documentation upstream \
82+
git push origin docs && \
83+
# Notify of completion \
84+
echo && \
85+
echo === filter-repo docs branch updated ===
8486

8587
# Call like this:
8688
# make GITHUB_COM_TOKEN=$KEY TAGNAME=v2.23.0 release
8789
release: github_release pypi_release
8890

8991
# Call like this:
9092
# make GITHUB_COM_TOKEN=$KEY TAGNAME=v2.23.0 github_release
91-
github_release: export FILEBASE=git-filter-repo-$(shell echo $(TAGNAME) | tail -c +2)
92-
github_release: export TMP_INDEX_FILE=$(shell mktemp)
93-
github_release: export COMMIT=$(shell git rev-parse HEAD)
9493
github_release: update_docs
95-
test -n "$(GITHUB_COM_TOKEN)"
96-
test -n "$(TAGNAME)"
97-
test -n "$$COMMIT"
98-
# Make sure we don't have any staged or unstaged changes
99-
git diff --quiet --staged HEAD && git diff --quiet HEAD
100-
# Make sure 'jq' is installed
101-
type -p jq
102-
# Tag the release, push it to GitHub
103-
git tag -a -m "filter-repo $(TAGNAME)" $(TAGNAME) $$COMMIT
104-
git push origin $(TAGNAME)
105-
# Create the tarball
106-
GIT_INDEX_FILE=$$TMP_INDEX_FILE git read-tree $$COMMIT
94+
FILEBASE=git-filter-repo-$(shell echo $(TAGNAME) | tail -c +2) \
95+
TMP_INDEX_FILE=$(shell mktemp) \
96+
COMMIT=$(shell git rev-parse HEAD) \
97+
&& \
98+
test -n "$(GITHUB_COM_TOKEN)" && \
99+
test -n "$(TAGNAME)" && \
100+
test -n "$$COMMIT" && \
101+
# Make sure we don't have any staged or unstaged changes \
102+
git diff --quiet --staged HEAD && git diff --quiet HEAD && \
103+
# Make sure 'jq' is installed \
104+
type -p jq && \
105+
# Tag the release, push it to GitHub \
106+
git tag -a -m "filter-repo $(TAGNAME)" $(TAGNAME) $$COMMIT && \
107+
git push origin $(TAGNAME) && \
108+
# Create the tarball \
109+
GIT_INDEX_FILE=$$TMP_INDEX_FILE git read-tree $$COMMIT && \
107110
git ls-tree -r docs | grep filter-repo \
108111
| sed -e 's%\t%\tDocumentation/%' \
109-
| GIT_INDEX_FILE=$$TMP_INDEX_FILE git update-index --index-info
112+
| GIT_INDEX_FILE=$$TMP_INDEX_FILE git update-index --index-info && \
110113
GIT_INDEX_FILE=$$TMP_INDEX_FILE git write-tree \
111-
| xargs git archive --prefix=$(FILEBASE)/ \
112-
| xz -c >$(FILEBASE).tar.xz
113-
rm $$TMP_INDEX_FILE
114-
# Make GitHub mark our new tag as an official release
114+
| xargs git archive --prefix=$$FILEBASE/ \
115+
| xz -c >$$FILEBASE.tar.xz && \
116+
rm $$TMP_INDEX_FILE && \
117+
# Make GitHub mark our new tag as an official release \
115118
curl -s -H "Authorization: token $(GITHUB_COM_TOKEN)" -X POST \
116119
https://api.github.com/repos/newren/git-filter-repo/releases \
117120
--data "{ \
118121
\"tag_name\": \"$(TAGNAME)\", \
119122
\"target_commitish\": \"$$COMMIT\", \
120123
\"name\": \"$(TAGNAME)\", \
121124
\"body\": \"filter-repo $(TAGNAME)\" \
122-
}" | jq -r .id >asset_id
123-
# Upload our tarball
124-
cat asset_id | xargs -I ASSET_ID curl -s -H "Authorization: token $(GITHUB_COM_TOKEN)" -H "Content-Type: application/octet-stream" --data-binary @$(FILEBASE).tar.xz https://uploads.github.com/repos/newren/git-filter-repo/releases/ASSET_ID/assets?name=$(FILEBASE).tar.xz
125-
# Remove temporary file(s)
126-
rm asset_id
127-
# Notify of completion
128-
@echo
129-
@echo === filter-repo $(TAGNAME) created and uploaded to GitHub ===
125+
}" | jq -r .id >asset_id && \
126+
# Upload our tarball \
127+
cat asset_id | xargs -I ASSET_ID curl -s -H "Authorization: token $(GITHUB_COM_TOKEN)" -H "Content-Type: application/octet-stream" --data-binary @$$FILEBASE.tar.xz https://uploads.github.com/repos/newren/git-filter-repo/releases/ASSET_ID/assets?name=$$FILEBASE.tar.xz && \
128+
# Remove temporary file(s) \
129+
rm asset_id && \
130+
# Notify of completion \
131+
echo && \
132+
echo === filter-repo $(TAGNAME) created and uploaded to GitHub ===
130133

131134
pypi_release: # Has an implicit dependency on github_release because...
132135
# Upload to PyPI, automatically picking tag created by github_release

0 commit comments

Comments
 (0)