This repository was archived by the owner on Jan 1, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathrun
More file actions
executable file
·244 lines (190 loc) · 5.02 KB
/
run
File metadata and controls
executable file
·244 lines (190 loc) · 5.02 KB
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
#!/usr/bin/env bash
set -o errexit
set -o pipefail
DC="${DC:-exec}"
# Disable tty allocation for Docker Compose when none is available, such as
# in CI or when you pipe something into the run script. 0 = stdin, 1 = stdout.
TTY="${TTY:-}"
if ! [ -t 0 ] || ! [ -t 1 ]; then
TTY="-T"
fi
# -----------------------------------------------------------------------------
# Helper functions start with _ and aren't listed in this script's help menu.
# -----------------------------------------------------------------------------
_dc() {
# shellcheck disable=SC2086
docker compose "${DC}" ${TTY} "${@}"
}
_dc_run() {
DC="run" _dc --no-deps --rm "${@}"
}
# -----------------------------------------------------------------------------
cmd() {
# Run any command you want in the web container
_dc web "${@}"
}
iex() {
# Connect to an IEx session
cmd iex -S mix
}
secret() {
# Generate a random secret that can be used for secret keys and more
mix phx.gen.secret
}
lint:dockerfile() {
# Lint Dockerfile
docker container run --rm -i \
-v "${PWD}/.hadolint.yaml:/.config/hadolint.yaml" \
hadolint/hadolint hadolint "${@}" - <Dockerfile
}
lint:shell() {
# Lint shell scripts
local cmd=(shellcheck)
if ! command -v shellcheck >/dev/null 2>&1; then
local cmd=(docker container run --rm -i -v "${PWD}:/mnt" koalaman/shellcheck:stable)
fi
find . -type f \
! -path "./.git/*" \
! -path "./assets/*" \
! -path "./priv/static/*" \
-exec grep --quiet '^#!.*sh' {} \; -exec "${cmd[@]}" {} +
}
lint() {
# Lint Elixir code
mix credo
}
format:shell() {
# Format shell scripts
local cmd=(shfmt)
if ! command -v shfmt >/dev/null 2>&1; then
local cmd=(docker container run --rm -i -v "${PWD}:/mnt" -u "$(id -u):$(id -g)" -w /mnt mvdan/shfmt:v3)
fi
local maybe_write=("--write")
for arg in "${@}"; do
if [ "${arg}" == "-d" ] || [ "${arg}" == "--diff" ]; then
unset "maybe_write[0]"
fi
done
"${cmd[@]}" "${maybe_write[@]}" "${@}" .
}
format:check() {
# Check to see if there's an unformatted code
format --check-formatted
}
format() {
# Run the mix formatter
mix format
}
quality() {
# Perform all code quality commands together
lint:dockerfile
lint:shell
lint
format:shell
format
}
test() {
# Run test suite
_dc -e "MIX_ENV=test" web mix test "${@}"
}
test:coverage() {
# Get test coverage
_dc -e "MIX_ENV=test" web mix coveralls "${@}"
}
test:coverage:details() {
# Get test coverage details
_dc -e "MIX_ENV=test" web mix coveralls.detail "${@}"
}
shell() {
# Start a shell session in the web container
cmd bash "${@}"
}
psql() {
# Connect to PostgreSQL
# shellcheck disable=SC1091
. .env
_dc postgres psql -U "${POSTGRES_USER}" "${@}"
}
deps:install() {
local no_build="${1:-}"
[ -z "${no_build}" ] && docker compose down && docker compose build
_dc_run js yarn install
_dc_run web mix deps.get
}
mix() {
cmd mix "${@}"
}
mix:outdated() {
# List any installed packages that are outdated
_dc_run web mix hex.outdated
}
yarn() {
_dc js yarn "${@}"
}
yarn:outdated() {
# List any installed packages that are outdated
_dc_run js yarn outdated
}
yarn:build:js() {
# Build JS assets, this is meant to be run from within the assets container
mkdir -p ../priv/static/js
node esbuild.config.mjs
}
yarn:build:css() {
# Build CSS assets, this is meant to be run from within the assets container
local args=()
if [ "${NODE_ENV:-}" == "production" ]; then
args=(--minify)
else
args=(--watch)
fi
mkdir -p ../priv/static/css
tailwindcss -i css/app.css -o ../priv/static/css/app.css "${args[@]}"
}
prod:migrate() {
# Run database migrations in production
cmd bin/hello eval "Hello.Release.migrate"
}
prod:remote() {
# Connect an IEx session to your production system
cmd bin/hello remote
}
clean() {
# Remove cache and other machine generates files
rm -rf priv/static/*.* priv/static/js priv/static/css priv/static/images priv/static/fonts
touch priv/static/.keep
}
ci:install-deps() {
# Install Continuous Integration (CI) dependencies
sudo apt-get install -y curl
sudo curl \
-L https://raw.githubusercontent.com/nickjj/wait-until/v0.2.0/wait-until \
-o /usr/local/bin/wait-until && sudo chmod +x /usr/local/bin/wait-until
}
ci:test() {
# Execute Continuous Integration (CI) pipeline
lint:dockerfile "${@}"
lint:shell
format:shell --diff
cp --no-clobber .env.example .env
docker compose build
docker compose up -d
# shellcheck disable=SC1091
. .env
wait-until "docker compose exec -T \
-e PGPASSWORD=${POSTGRES_PASSWORD} postgres \
psql -U ${POSTGRES_USER} ${POSTGRES_USER} -c 'SELECT 1'"
docker compose logs
lint
format:check
mix ecto.setup
test "${@}"
}
help() {
printf "%s <task> [args]\n\nTasks:\n" "${0}"
compgen -A function | grep -v "^_" | cat -n
printf "\nExtended help:\n Each task has comments for general usage\n"
}
# This idea is heavily inspired by: https://github.com/adriancooney/Taskfile
TIMEFORMAT=$'\nTask completed in %3lR'
time "${@:-help}"