forked from martinthomson/i-d-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
id.mk
105 lines (92 loc) · 3.44 KB
/
id.mk
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
## Identify drafts, types and versions
drafts := $(sort $(basename $(wildcard $(foreach pattern,? *-[-a-z]? *-?[a-z] *[a-z0-9]??,$(foreach ext,xml org md,draft-$(pattern).$(ext))))))
ifeq (0,$(words $(drafts)))
drafts := $(sort $(basename $(wildcard rfc[0-9]*.xml)))
endif
ifeq (0,$(words $(drafts)))
$(warning No file named draft-*.md or draft-*.xml or draft-*.org)
$(error Create a draft file before running make)
endif
draft_types := $(foreach draft,$(drafts),\
$(suffix $(firstword $(wildcard $(draft).md $(draft).org $(draft).xml))))
drafts_source := $(join $(drafts),$(draft_types))
drafts_tags := $(shell git tag --sort=refname 2>/dev/null | grep '^draft-')
f_prev_tag = $(lastword $(subst -, ,$(lastword $(filter $(draft)-%,$(drafts_tags)))))
f_next_tag = $(if $(f_prev_tag),$(shell printf "%.2d" $$(( 1$(f_prev_tag) - 99)) ),00)
drafts_next := $(foreach draft,$(drafts),$(draft)-$(f_next_tag))
drafts_prev := $(foreach draft,$(drafts),$(draft)-$(f_prev_tag))
drafts_with_prev := $(foreach draft,$(drafts),$(if $(f_prev_tag),$(draft)))
drafts_txt := $(addsuffix .txt,$(drafts))
drafts_raw := $(addsuffix .raw.txt,$(drafts))
drafts_html := $(addsuffix .html,$(drafts))
drafts_xml := $(addsuffix .xml,$(drafts))
drafts_next_txt := $(addsuffix .txt,$(drafts_next))
drafts_next_xml := $(addsuffix .xml,$(drafts_next))
drafts_prev_txt := $(addsuffix .txt,$(drafts_prev))
last_modified = $$(stat $$([ $$(uname -s) = Darwin ] && echo -f '%m' || echo -c '%Y') $(1))
file_size = $$(stat $$([ $$(uname -s) = Darwin ] && echo -f '%z' || echo -c '%s') $(1))
last_commit = $$(git rev-list -n 1 --timestamp $(1) -- $(2) | sed -e 's/ .*//')
# CI config
CI ?= false
ifneq (,$(GITHUB_REPOSITORY))
CI_USER ?= $(word 1,$(subst /, ,$(GITHUB_REPOSITORY))
CI_REPO ?= $(word 2,$(subst /, ,$(GITHUB_REPOSITORY)))
else
CI_USER ?= $(word 1,$(subst /, ,$(TRAVIS_REPO_SLUG)))$(CIRCLE_PROJECT_USERNAME)
CI_REPO ?= $(word 2,$(subst /, ,$(TRAVIS_REPO_SLUG)))$(CIRCLE_PROJECT_REPONAME)
ifneq (,$(CI_USER))
ifneq (,$(CI_REPO))
CI_REPO_FULL = $(CI_USER)/$(CI_REPO)
endif
endif
endif
# CI_IS_PR being true disables some options.
ifdef CI_PULL_REQUESTS
# Circle makes this easy
CI_IS_PR = true
else
ifdef GITHUB_BASE_REF
CI_IS_PR = true
else
ifdef TRAVIS_PULL_REQUEST
ifeq (false,$(TRAVIS_PULL_REQUEST))
# If $TRAVIS_PULL_REQUEST is the word 'false', it's a branch build.
CI_IS_PR = false
else
CI_IS_PR = true
endif
else
CI_IS_PR = false
endif
endif
endif
CI_ARTIFACTS := $(CIRCLE_ARTIFACTS)
ifeq (,$(shell git config --global --get user.name))
CI_AUTHOR = -c user.name="ID Bot"
endif
ifeq (,$(shell git config --global --get user.email))
CI_AUTHOR += -c user.email="[email protected]"
endif
# Github guesses
GIT_REMOTE ?= origin
export GIT_REMOTE
ifeq (,$(CI_REPO_FULL))
GITHUB_REPO_FULL := $(shell git ls-remote --get-url $(GIT_REMOTE) 2>/dev/null |\
sed -e 's/^.*github\.com.//;s/\.git$$//')
GITHUB_USER := $(word 1,$(subst /, ,$(GITHUB_REPO_FULL)))
GITHUB_REPO := $(word 2,$(subst /, ,$(GITHUB_REPO_FULL)))
else
GITHUB_REPO_FULL := $(CI_REPO_FULL)
GITHUB_USER := $(CI_USER)
GITHUB_REPO := $(CI_REPO)
endif
# GITHUB_PUSH_TOKEN is used for pushes.
ifneq (,$(and $(GITHUB_ACTOR),$(GITHUB_TOKEN)))
GITHUB_PUSH_TOKEN ?= $(GITHUB_ACTOR):$(GITHUB_TOKEN)
else
GITHUB_PUSH_TOKEN ?= $(GH_TOKEN)
endif
# GITHUB_API_TOKEN is used in the GitHub API.
GITHUB_API_TOKEN ?= $(or $(GITHUB_TOKEN),$(GH_TOKEN))
DEFAULT_BRANCH ?= $(shell $(LIBDIR)/default-branch.py $(GITHUB_USER) $(GITHUB_REPO) $(GITHUB_API_TOKEN))
export DEFAULT_BRANCH