-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
111 lines (93 loc) · 3.07 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
#!/bin/make -f
# -*- makefile -*-
# SPDX-License-Identifier: MPL-2.0
#{
# Copyright 2020-present Philippe Coval and other contributors
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/
#}
default: help all
project ?= generic-sensors-webthings
addon_name ?= generic-sensors-adapter
addons_url ?= https://github.com/WebThingsIO/addon-list
addons_dir ?= tmp/addon-list
addons_json ?= ${addons_dir}/addons/${addon_name}.json
addons_review_org ?= ${USER}
addons_review_branch ?= sandbox/${USER}/review/master
addons_review_url ?= ssh://github.com/${addons_review_org}/addon-list
addons_review_http_url ?= ${addons_url}/compare/master...${addons_review_org}:${addons_review_branch}?expand=1
lint: node_modules
npm run $@
help:
@echo "## Usage:"
@echo "# make lint"
@echo "# make rule/version"
@echo "# make rule/version/X.Y.Z # To update manifest"
@echo "# make rule/release/X.Y.Z # To update addon-list"
node_modules: package.json
npm install
rule/version: node_modules
@echo "# NODE_PATH=$${NODE_PATH}"
node --version
npm --version
npm version
rule/version/%: manifest.json
-npm version
-git describe --tags
sed -e "s|\(\"version\":\) .*|\1 \"${@F}\"|g" -i $<
-git commit -sm "build: Update version to ${@F}" $<
npm version patch
rule/addons/push: ${addons_json}
jq < "$<" > /dev/null
cd ${<D} \
&& git --no-pager diff \
&& git commit -am "${addon_name}: ${message}"
@echo "# About to push to ${addons_review_url}"
@echo "# Stop now with ctrl+c"
sleep 5
cd ${addons_dir} \
&& git push ${addons_review_url} -f HEAD:${addons_review_branch}
@echo "# Request merge at"
@echo "# ${addons_review_http_url}"
rule/release/%: ${addons_json} # rule/version/%
sed -e "s|/v[^/]*/|/v${@F}/|g" -i $<
sed -e "s|\(.*\"version\": \)\"\(.*\)\"\(.*\)|\1\"${@F}\"\3|g" -i $<
sed -e "s|\(.*/${addon_name}-\)\([0-9.]*\)\(-.*\)|\1${@F}\3|g" -i $<
${MAKE} rule/checksum/update
-git diff
${<D}/../tools/check-list.py ${addon_name}
${MAKE} rule/addons/push message="Update to ${@F}"
${addons_json}:
mkdir -p "${addons_dir}"
git clone ${addons_url} "${addons_dir}"
jq < "$@"
tmp/urls.lst: ${addons_json}
jq '.packages[].url' < "$<" | xargs -n1 echo > $@
tmp/checksums.lst: tmp/urls.lst Makefile
cat $< | while read url ; do \
curl -L -s -I "$${url}" | grep -r 'HTTP/1.1 {200,302}' > /dev/null \
&& curl -L -s "$${url}" | sha256sum - ; \
done \
| cut -d' ' -f1 | tee [email protected]
mv [email protected] $@
rule/checksum/update: ${addons_json} tmp/checksums.lst
cp -av "$<" "$<.tmp"
i=0; \
cat tmp/checksums.lst | while read sum ; do \
jq '.packages['$${i}'].checksum |= "'$${sum}'"' < $<.tmp > $<.out.tmp ; \
mv "$<.out.tmp" "$<.tmp" ; \
i=$$(expr 1 + $${i}) ; \
done
jq < "$<.tmp" > /dev/null
mv "$<.tmp" "$<"
rule/wait:
@printf "# Scanning: "
@while true ; do \
${MAKE} rule/urls | grep 'HTTP/1.1 200' && exit 0 \
|| printf "."; \
sleep 1; \
done
rule/checksum/push: rule/wait rule/checksum/update
${MAKE} rule/addons/push message="Update checksums from URLs"