-
Notifications
You must be signed in to change notification settings - Fork 246
/
justfile
294 lines (247 loc) · 9.43 KB
/
justfile
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
293
294
# vim: set tabstop=4 shiftwidth=4 expandtab:
[private]
default:
just --list
[private]
fmt:
just --fmt --check --unstable
[private]
brew:
@which brew >/dev/null \
|| (echo {{ _MAGENTA }}🍺 Installing Homebrew...{{ _RESET }} \
&& NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" \
&& echo {{ _REDB }}{{ _WHITE }} 👆 You must follow NEXT STEPS above before continuing 👆 {{ _RESET }})
[private]
brew-linux-shell:
@echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"'
[private]
just: brew
@[ -f $(brew--prefix)/bin/just ] \
|| brew install just
[private]
just0:
curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | sudo bash -s -- --to /usr/local/bin
[private]
imagemagick: brew
@[ -d $(brew --prefix)/opt/imagemagick ] \
|| brew install imagemagick
# Create .envrc.secrets with credentials from 1Password
[group('team')]
envrc-secrets:
op inject --in-file envrc.secrets.op --out-file .envrc.secrets
[private]
gpg: brew
@[ -d $(brew --prefix)/opt/gpg ] \
|| brew install gpg
[private]
icu4c: brew
@[ -d "$(brew --prefix icu4c)/lib/pkgconfig" ] \
|| brew install icu4c pkg-config
# https://tldp.org/LDP/abs/html/exitcodes.html
[private]
asdf:
@which asdf >/dev/null \
|| (brew install asdf \
&& echo {{ _REDB }}{{ _WHITE }} 👆 You must follow CAVEATS above before continuing 👆 {{ _RESET }})
[private]
asdf-shell: brew
@echo "source $(brew --prefix)/opt/asdf/libexec/asdf.sh"
# Install all system dependencies
[group('contributor')]
install: asdf brew imagemagick gpg icu4c
@awk '{ system("asdf plugin-add " $1) }' < .tool-versions
@PKG_CONFIG_PATH="$(brew --prefix icu4c)/lib/pkgconfig:$PKG_CONFIG_PATH" asdf install
export ELIXIR_ERL_OPTIONS := if os() == "linux" { "+fnu" } else { "" }
# Add Oban Pro hex repository
[group('team')]
add-oban-pro-hex-repo:
[ -n "$OBAN_LICENSE_KEY" ] \
&& [ -n "$OBAN_KEY_FINGERPRINT" ] \
&& mix hex.repo add oban https://getoban.pro/repo --fetch-public-key $OBAN_KEY_FINGERPRINT --auth-key $OBAN_LICENSE_KEY
# Get app dependencies
[group('contributor')]
deps: add-oban-pro-hex-repo
mix local.hex --force
mix deps.get --only dev
mix deps.get --only test
[private]
pg_ctl:
@which pg_ctl >/dev/null \
|| (echo "{{ _REDB }}{{ _WHITE }}Postgres is not installed.{{ _RESET }} To fix this, run: {{ _GREENB }}just install{{ _RESET }}" && exit 127)
# Start Postgres server
[group('contributor')]
postgres-up: pg_ctl
@(pg_ctl status | grep -q "is running") || pg_ctl start
# Stop Postgres server
[group('contributor')]
postgres-down: pg_ctl
@(pg_ctl status | grep -q "no server running") || pg_ctl stop
[private]
postgres-db db:
@(psql --list --quiet --tuples-only | grep -q {{ db }}) \
|| createdb {{ db }}
# Delete & replace changelog_dev with a prod db dump
[confirm("This DELETEs and REPLACEs changelog_dev with the prod db dump. Are you sure that you want to continue?")]
[group('team')]
restore-dev-db-from-prod format="c": changelog_dev
@echo "\n{{ _MAGENTA }}🛬 Dumping prod db...{{ _RESET }}"
[ -f $DB_PROD_DBNAME.{{ format }}.sql ] \
|| time PGSSLMODE=require PGPASSWORD=$(op read op://changelog/neon/password) pg_dump \
--format={{ format }} --verbose \
--host=$DB_PROD_HOST \
--username=$DB_PROD_USERNAME \
--dbname=$DB_PROD_DBNAME > $DB_PROD_DBNAME.{{ format }}.sql
@echo "\n{{ _MAGENTA }}🛫 Recreating {{ _CHANGELOG_DEV_DB }} from prod dump...{{ _RESET }}"
dropdb {{ _CHANGELOG_DEV_DB }}
createdb {{ _CHANGELOG_DEV_DB }}
time pg_restore \
--format=c --verbose \
--dbname={{ _CHANGELOG_DEV_DB }} \
--exit-on-error \
--no-owner \
--no-privileges < $DB_PROD_DBNAME.{{ format }}.sql
@echo "\n{{ _MAGENTA }}⚡️ Warm up the query planner...{{ _RESET }} https://www.postgresql.org/docs/current/sql-analyze.html"
time psql --dbname={{ _CHANGELOG_DEV_DB }} --command "ANALYZE VERBOSE;"
[private]
neon *ARGS: npm
@which neonctl >/dev/null \
|| (echo {{ _MAGENTA }}🧪 Installing neonctl...{{ _RESET }} \
&& npm install -g neonctl && echo {{ _MAGENTA }}neonctl{{ _RESET }} && neonctl --version)
{{ if ARGS != "" { "neonctl " + ARGS } else { "neonctl" } }}
[private]
npm:
@which npm >/dev/null \
|| (echo "{{ _REDB }}{{ _WHITE }}NPM is not installed.{{ _RESET }} To fix this, run: {{ _GREENB }}just install{{ _RESET }}" && exit 127)
_NEON_DB_BRANCH := env_var("USER") + "-" + datetime("%Y-%m-%d")
# Create a new branch off the prod db
[group('team')]
neon-create-branch:
@echo "\n{{ _MAGENTA }}🔒 Checking Neon auth...{{ _RESET }}"
just neon projects get $NEON_PROJECT_ID || just neon auth
@echo "\n{{ _MAGENTA }}🌲 Creating Neon prod db branch...{{ _RESET }}"
just neon branches get --project-id=$NEON_PROJECT_ID {{ _NEON_DB_BRANCH }} \
|| just neon branches create --project-id=$NEON_PROJECT_ID --name={{ _NEON_DB_BRANCH }}
@echo "\n{{ _MAGENTA }}⚡️ Warm up the query planner...{{ _RESET }} https://www.postgresql.org/docs/current/sql-analyze.html"
time psql "$(just neon-branch-connection-string {{ _NEON_DB_BRANCH }})" --command "ANALYZE VERBOSE;"
@echo "\n{{ _MAGENTA }}💡 To use this Neon db branch in with your local dev app, run: {{ _RESET }}{{ _GREENB }}just dev-with-neon-branch {{ _NEON_DB_BRANCH }}{{ _RESET }}"
# Show $branch connection details
[group('team')]
neon-branch-connection branch *ARGS:
@just neon connection-string {{ branch }} --project-id=$NEON_PROJECT_ID \
--role-name=$DB_PROD_USERNAME --database-name=$DB_PROD_DBNAME --extended --output=yaml {{ ARGS }}
[private]
neon-branch-connection-string branch:
@just neon-branch-connection {{ branch }} \
| awk '/connection_string:/ { print $2 }'
# List prod db branches
[group('team')]
neon-branches: (neon "branches list --project-id=$NEON_PROJECT_ID")
[private]
neon-connection-convert-to-env:
#!/usr/bin/env bash
awk '
/^host:/ {gsub(/^host: /, ""); print "export DB_HOST=" $0}
/^role:/ {gsub(/^role: /, ""); print "export DB_USER=" $0}
/^password:/ {gsub(/^password: /, ""); print "export DB_PASS=" $0}
/^database:/ {gsub(/^database: /, ""); print "export DB_NAME=" $0}
'
[private]
changelog_test: postgres-up (postgres-db "changelog_test")
# Run app tests
[group('contributor')]
test: changelog_test
mix test
_CHANGELOG_DEV_DB := env_var("CHANGELOG_DEV_DB")
[private]
changelog_dev: postgres-up (postgres-db _CHANGELOG_DEV_DB)
mix ecto.setup
[private]
yarn:
@which yarn >/dev/null \
|| (echo "{{ _REDB }}{{ _WHITE }}Yarn is not installed.{{ _RESET }} To fix this, run: {{ _GREENB }}just install{{ _RESET }}" && exit 127)
[private]
assets: yarn
cd assets && yarn install
# Run app in dev mode
[group('contributor')]
dev: changelog_dev assets
mix phx.server
# Run app in dev mode with $branch
[group('team')]
dev-with-neon-branch branch: assets
#!/usr/bin/env bash
eval "$(just neon-branch-connection {{ branch }} \
| just neon-connection-convert-to-env)"
mix phx.server
# Setup everything needed for your first contribution
[group('contributor')]
contribute: install
#!/usr/bin/env bash
eval "$(just asdf-shell)"
just deps
just test
just dev
[private]
actions-runner:
docker run --interactive --tty \
--volume=changelog-linuxbrew:/home/linuxbrew/.linuxbrew \
--volume=changelog-asdf:/home/runner/.asdf \
--volume=.:/home/runner/work --workdir=/home/runner/work \
--env=HOST=$(hostname) --publish=4000:4000 \
--pull=always ghcr.io/actions/actions-runner
[linux]
[private]
do-it:
#!/usr/bin/env bash
sudo apt update
DEBIAN_FRONTEND=noninteractive sudo apt install -y build-essential curl git libncurses5-dev libssl-dev inotify-tools
just brew
eval "$(just brew-linux-shell)"
just asdf
eval "$(just asdf-shell)"
just contribute
# Tag Kaizen $version with $episode & $discussion at $commit (recording date)
[group('team')]
tag-kaizen version episode discussion commit:
git tag --force --sign \
--message="Recorded as 🎧 <https://changelog.com/friends/{{ episode }}>" \
--message="Discussed in https://github.com/thechangelog/changelog.com/discussions/{{ discussion }}" \
kaizen.{{ version }} {{ commit }}
git push --force origin kaizen.{{ version }}
# https://linux.101hacks.com/ps1-examples/prompt-color-using-tput/
_BOLD := "$(tput bold)"
_RESET := "$(tput sgr0)"
_BLACK := "$(tput bold)$(tput setaf 0)"
_RED := "$(tput bold)$(tput setaf 1)"
_GREEN := "$(tput bold)$(tput setaf 2)"
_YELLOW := "$(tput bold)$(tput setaf 3)"
_BLUE := "$(tput bold)$(tput setaf 4)"
_MAGENTA := "$(tput bold)$(tput setaf 5)"
_CYAN := "$(tput bold)$(tput setaf 6)"
_WHITE := "$(tput bold)$(tput setaf 7)"
_BLACKB := "$(tput bold)$(tput setab 0)"
_REDB := "$(tput setab 1)$(tput setaf 0)"
_GREENB := "$(tput setab 2)$(tput setaf 0)"
_YELLOWB := "$(tput setab 3)$(tput setaf 0)"
_BLUEB := "$(tput setab 4)$(tput setaf 0)"
_MAGENTAB := "$(tput setab 5)$(tput setaf 0)"
_CYANB := "$(tput setab 6)$(tput setaf 0)"
_WHITEB := "$(tput setab 7)$(tput setaf 0)"
# just actions-runner
# DEBIAN_FRONTEND=noninteractive sudo apt install -y curl
# eval $(grep j_ust.systems justfile)
# cd ../
# sudo chown -fR runner:runner work ~/.asdf
# cd work
# just do-it
#
# du -skh _build
# 72M
#
# du -skh deps
# 41M
#
# du -skh /home/linuxbrew/.linuxbrew
# 1.5G
# du -skh ~/.asdf
# 728M