-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
293 lines (247 loc) · 8.47 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/usr/bin/make
ifneq (,$(wildcard ./.env))
include .env
export $(shell sed 's/=.*//' .env)
endif
PORT=8080
SHELL=/bin/bash
HOST="localhost"
.ONESHELL:
all: help
.PHONY: help
help:
@echo -e "\tMakefile for Tide"
@echo ''
@echo " usage: $0 [COMMAND]"
@echo ''
@echo "The available commands are:"
@echo ''
@echo " help - Print this help text and exit."
@echo " configure - Configure the project folder."
@echo " lint - Check the code format."
@echo " fix-lint - Fix the code format."
@echo " test - Run the Flutter unit and widget tests."
@echo " update-goldens - Create or update golden files."
@echo " docker-update-goldens - Create or update golden files from a Linux Docker container (to update the Linux golden images)."
@echo " doc - Generate the documentation."
@echo " rmdoc - Remove the documentation."
@echo " update-launcher - Update the icon launcher."
@echo " build-release-android - Build a release version for Android. It is currently not supported in this Makefile."
@echo " fix-packages-version - Replace the 'any' packages version in 'pubspec.yaml' to their actual installed version based on 'pubspec.lock'."
@echo ''
# Print to stdout the configuration file if found, else and print error message to stderr and exit with code 1
.PHONY: get-config-file
get-config-file:
@set -euo pipefail
if [[ -f tide.yaml ]]; then
echo "tide.yaml"
elif [[ -f tide.yml ]]; then
echo "tide.yml"
else
echo "No tide.yaml found at the root of the project." 1>&2
exit 1
fi
.PHONY: configure
configure:
@flutter channel beta
flutter upgrade
flutter pub get
flutter packages pub run build_runner build
echo "\nFlutter has now the web feature enable. Please check the following tutorial to ensure it works: https://flutter.dev/docs/get-started/web"
.PHONY: clean
clean:
flutter clean
rm -rf coverage
rm -f .coverage
.PHONY: lint
lint:
@set -euo pipefail
echo "Checking Dart files format..."
flutter format --output none --set-exit-if-changed .
.PHONY: fix-lint
fix-lint:
flutter format --fix .
.PHONY: test
test:
@set -euo pipefail
flutter test --coverage --reporter expanded --dart-define=FLUTTER_TEST=true
.PHONY: docker-test
docker-test:
@set -euo pipefail
# Bash array containing all volumes as arguments
extra_volumes=()
set +e
config_file=$$($(MAKE) --quiet --no-print-directory get-config-file 2> /dev/null)
set -e
if [[ -n $$config_file ]]; then
extra_volumes+=("-v" "$$(realpath "$$config_file"):/usr/local/apache2/htdocs/assets/tide.yaml:ro")
fi
docker run \
-it \
--rm \
--name=tide-tests \
--hostname="tide-tests" \
-v "/etc/timezone:/etc/timezone:ro" \
-v "/etc/localtime:/etc/localtime:ro" \
"$${extra_volumes[@]}" \
-e TZ \
--restart=no \
--security-opt="no-new-privileges=true" \
--cap-drop=all \
cynnexis/tide:sdk test --coverage --concurrency=1 --reporter expanded --dart-define=FLUTTER_TEST=true
.PHONY: update-goldens
update-goldens:
@set -euo pipefail
flutter test --update-goldens --dart-define=FLUTTER_TEST=true
.PHONY: docker-update-goldens
docker-update-goldens:
@set -euo pipefail
# Build SDK Docker image
time ./docker/build.bash --only=sdk
# Bash array containing all volumes as arguments
extra_volumes=()
set +e
config_file=$$($(MAKE) --quiet --no-print-directory get-config-file 2> /dev/null)
set -e
if [[ -n $$config_file ]]; then
extra_volumes+=("-v" "$$(realpath "$$config_file"):/root/tide/tide.yaml:ro")
fi
PS4=' $$ '
set -x
# Launch tests
docker run \
-it \
--rm \
--name=tide-update-golden \
--hostname="tide-update-golden" \
-v "/etc/timezone:/etc/timezone:ro" \
-v "/etc/localtime:/etc/localtime:ro" \
-v "$(pwd)/test/golden-images/:/root/tide/test/golden-images/" \
"$${extra_volumes[@]}" \
-e TZ \
--restart=no \
--security-opt="no-new-privileges=true" \
--cap-drop=all \
cynnexis/tide:sdk test --update-goldens --dart-define=FLUTTER_TEST=true
{ set +x; } 2> /dev/null
.PHONY: test-integration
test-integration:
@set -euo pipefail
flutter test --coverage --reporter expanded --dart-define=FLUTTER_TEST=true integration_test/tide_test.dart
.PHONY: test-integration-web
test-integration-web:
@set -euo pipefail
echo "To run the integrations tests on web, you need to have the ChromeDriver. Please see https://docs.flutter.dev/cookbook/testing/integration/introduction#5b-web" 1>&2
flutter drive \
--driver=test_driver/integration_test.dart \
--target=integration_test/tide_test.dart \
--dart-define=FLUTTER_TEST=true \
-d web-server
.PHONY: doc
doc:
@PS4='$$ '
set -euxo pipefail
flutter pub global run dartdoc .
{ set +x; } 2> /dev/null
.PHONY: rmdoc
rmdoc:
rm -rf doc/api
.PHONY: update-launcher
update-launcher:
flutter pub run flutter_launcher_icons:main
build/app/outputs/bundle/release/app-release.aab:
@if [[ ! -f "android/key.properties" ]]; then
echo "Couldn't find \"android/key.properties\". Make sure that you can generate an Android signed app bundle. Please see https://flutter.dev/docs/deployment/android" > /dev/stderr
fi
# Create a directory to store debug symbols after obfuscation (see https://flutter.dev/docs/deployment/obfuscate)
mkdir -p build/debug
flutter build appbundle --obfuscate --split-debug-info=build/debug
echo "Use 'flutter install' to install the generated application bundle on your Android phone."
.PHONY: build-release-and
build-release-and: build/app/outputs/bundle/release/app-release.aab
.PHONY: build-docker
build-docker:
@set -euo pipefail
time ./docker/build.bash
.PHONY: build-docker-action
build-docker-action:
@set -euo pipefail
cd .github/actions/tide-configuration-file
time docker build -t cynnexis/tide:action .
cd ../../../
.PHONY: docker-serve
docker-serve:
@set -euo pipefail
# Bash array containing all volumes as arguments
extra_volumes=()
set +e
config_file=$$($(MAKE) --quiet --no-print-directory get-config-file 2> /dev/null)
set -e
if [[ -n $$config_file ]]; then
extra_volumes+=("-v" "$$(realpath "$$config_file"):/usr/local/apache2/htdocs/assets/tide.yaml:ro")
fi
PS4=' $$ '
set -x
docker run -d \
--name=tide-web \
--hostname="tide-web" \
--publish 80:80 \
-v "/etc/timezone:/etc/timezone:ro" \
-v "/etc/localtime:/etc/localtime:ro" \
"$${extra_volumes[@]}" \
-e TZ \
"--restart=no" \
--health-cmd="{ \
{ curl -skL http://localhost/ | grep -Ee '^\s*<title>Tide</title>\$$'; } && \
{ curl -skIL http://localhost/ | grep -Ee '^\s*HTTP/1.1 200(\s+OK)?'; } \
} || exit 1" \
--health-interval=1m \
--health-timeout=5s \
--health-start-period=10s \
--health-retries=3 \
--security-opt="no-new-privileges=true" \
--cap-drop=all \
--cap-add=NET_BIND_SERVICE \
"cynnexis/tide:web"
{ set +x; } 2> /dev/null
.PHONY: fix-packages-version
fix-packages-version:
@set -euo pipefail
# List all type of dependencies
dependency_types=('dependencies' 'dev_dependencies')
for dependency_type in "$${dependency_types[@]}"; do
# List all dependencies from the pubspec.yaml file
dependencies=$$(yq --no-colors --no-doc eval ".\"$$dependency_type\" | keys" pubspec.y[a]ml | awk '{print $$2;}')
while read -r dependency; do
# Treat only dependencies that have "any" as version
if [[ $$(yq --no-colors --no-doc eval ".\"$$dependency_type\".\"$$dependency\"" pubspec.y[a]ml 2> /dev/null) == "any" ]]; then
# Get the version from pubspec.lock
version=$$(yq --no-colors --no-doc eval ".packages.\"$$dependency\".version" pubspec.lock 2> /dev/null)
# If the fetched version is valid, put it in the pubspec.yaml
if [[ -n $$version && $$version != "null" ]]; then
echo "$$dependency: $$version"
sed -iEe "s@^\(\s\+\)$${dependency}:\s*any\$$@\1$${dependency}: $$version@g" pubspec.y[a]ml
else
echo "Warning: no version found for \"$${dependency}\" from the group \"$${dependency_type}\"" 1>&2
fi
fi
done <<< "$$dependencies"
done
.PHONY: version
version:
@set -euo pipefail
if command -v yq &> /dev/null; then
VERSION=$$(yq eval -MN --unwrapScalar '.version' pubspec.yaml)
else
VERSION="$$(grep 'version:' pubspec.yaml | head -1 | awk '{print $$2}')"
fi
if [[ -d .git/ ]]; then
if command -v "git" &> /dev/null; then
if [[ "$$(git rev-parse --abbrev-ref HEAD)" != "main" ]]; then
VERSION="$$VERSION - rev $$(git rev-parse HEAD)"
fi
else
VERSION="$$VERSION - rev $$(cat ".git/$$(grep "ref:" .git/HEAD | head -1 | awk '{print $$2}')")"
fi
fi
echo "tide version $$VERSION"