-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMakefile
56 lines (48 loc) · 1.85 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
MAKEFLAGS += --silent
SHELL = /usr/bin/env bash
_IMAGE_NAME = duolingo/pre-commit-hooks
# Bumps this project's version number. Example: make release V=1.0.3
.PHONY: release
release: test
# Validate
[[ "$$(whoami)" = art ]] # Currently only @artnc can push to Docker Hub etc.
[[ -n "${V}" ]] # New version number was provided
[[ -z "$$(git status --porcelain)" ]] # Master is clean
# Update source files and commit
echo 'Creating release commit...'
git grep --cached -z -l '' | xargs -0 sed -E -i '' -e \
"s@( rev: | entry: $(_IMAGE_NAME):)$$(git tag | tail -1)@\1${V}@g"
git add -A
git commit -m "Release ${V}" -n
# Tag
echo 'Creating release tag...'
git tag "${V}"
echo 'Done! Now you should `git push`, `git push --tags`, create a new'
echo 'GitHub release for this tag, and run `make push` to update Docker Hub'
# Pushes to Docker Hub. Should be run when creating a GitHub release. We don't
# use Docker Hub's autobuild feature anymore because it only supports amd64 :/
# https://github.com/docker/roadmap/issues/109
.PHONY: push
push: test
grep -qF 'docker.io/' "$${HOME}/.docker/config.json" || docker login
docker buildx inspect | grep -q docker-container || docker buildx create --use
# https://stackoverflow.com/a/69987949
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx build --push --platform linux/amd64,linux/arm64 \
-t "$(_IMAGE_NAME):$$(git tag | tail -1)" \
-t "$(_IMAGE_NAME):latest" \
.
# Opens a shell in the container for debugging
.PHONY: shell
shell:
docker run --rm -it "$$(docker build --network=host -q .)" sh
# Runs tests
.PHONY: test
test:
docker run --rm -v "$${PWD}/test:/test" "$$(docker build --network=host -q .)" sh -c \
'cd /tmp \
&& cp -r /test/before actual \
&& cp -r /test/after expected \
&& /entry actual/* \
&& diff -r expected actual \
&& echo "All tests passed!"'