-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
225 lines (185 loc) · 6.08 KB
/
Makefile
File metadata and controls
225 lines (185 loc) · 6.08 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
#!make
# sometimes git_ref_name may be "" empty string
# such as during codespace prebuilds
git_ref_name ?= $(shell git rev-parse --abbrev-ref HEAD || echo latest)
# above git ref may not be valid docker tag
tag_from_git_ref_name := $(shell echo ${git_ref_name} | sed 's/[^a-zA-Z0-9]/-/g')
tag_from_git_sha ?= latest
can_push := false
# this can be conveniently overwritten for --print and metadata file
bake_args ?= --progress auto
bake_targets := builder developer rstudio runner
smoke_test_jobs := $(addprefix smoke-test-,${bake_targets})
include .env
all: all-outside-docker all-in-docker
all-outside-docker: superlint bake
make bake
make smoke-tests
make health-checks
make superlint
all-in-docker: rlint test check pkgdown test-installed
bake:
TAG_FROM_GIT_SHA=$(tag_from_git_sha) \
TAG_FROM_GIT_REF_NAME=$(tag_from_git_ref_name) \
CAN_PUSH=$(can_push) \
docker buildx bake \
--file docker-bake.hcl \
--file .env \
$(bake_args)
# when the list of buildtime dep pkgs changes,
# apt-get update needs to run again,
# to ensure that apt-get install emitted by pak work
sysdeps: DESCRIPTION
apt-get update
Rscript -e "pak::pak_update()"
Rscript -e \
"pak::local_system_requirements(execute = TRUE, sudo = FALSE, echo = TRUE)"
rdeps: DESCRIPTION
Rscript -e \
"remotes::install_deps(lib = Sys.getenv('R_LIBS_RUNTIME'), dependencies = TRUE)"
# hack is the easiest crossplatform way I could think of;
# sed -i won't play nice with macOS
# needs to run twice under some circumstances
roxygenise:
Rscript -e "roxygen2::roxygenise()"
Rscript -e "roxygen2::roxygenise()"
grep -v '^RoxygenNote:' DESCRIPTION > DESCRIPTION_clean
rm DESCRIPTION
mv DESCRIPTION_clean DESCRIPTION
# NAMESPACE file is derivative, so must be in sync with code
# must be on GitHub, b/c otherwise namespace can be broken
check-clean-namespace: roxygenise
git diff --exit-code NAMESPACE \
|| (echo "'NAMESPACE' is not in sync with the source. \
Try running 'make roxygenise' locally and commit."; \
exit 1)
check: roxygenise
Rscript \
-e "rcmdcheck::rcmdcheck(args = c('--no-manual', '--no-tests'), error_on = 'note' )"
pkgdown: roxygenise
Rscript -e "pkgdown::build_site(install = TRUE)"
show_pkgdown: pkgdown
Rscript -e "pkgdown::preview_site(preview = TRUE)"
test: roxygenise
Rscript -e "testthat::test_local(stop_on_warning = TRUE)"
test-installed: install
Rscript -e \
"testthat::test_local(stop_on_warning = TRUE, load_package = 'installed')"
test-installed-docker: bake
docker run -it -v .:/root/source ghcr.io/dataheld/crow/builder:latest make test-installed
install: roxygenise
Rscript \
-e "pak::local_install(dependencies = TRUE)"
smoke-tests: ${smoke_test_jobs}
# see https://stackoverflow.com/a/12110773/3403196
${smoke_test_jobs}: smoke-test-%:
TAG_FROM_GIT_REF_NAME=$(tag_from_git_ref_name) \
docker run \
--rm \
--entrypoint /bin/bash \
${REGISTRY_PREFIX}/${IMAGE_OWNER}/${IMAGE_NAME_ROOT}/$*:$(tag_from_git_ref_name) \
R --vanilla --quiet
health-checks: health-check-rstudio health-check-runner
health-check-rstudio:
TAG_FROM_GIT_REF_NAME=$(tag_from_git_ref_name) \
docker compose \
--file docker-compose.yml \
--env-file .env \
up \
--force-recreate \
--remove-orphans \
--detach \
rstudio
sleep 3
curl --fail http://localhost:8787 -o /dev/null || exit 1
health-check-runner:
TAG_FROM_GIT_REF_NAME=$(tag_from_git_ref_name) \
docker compose \
--file docker-compose.yml \
--env-file .env \
up \
--force-recreate \
--remove-orphans \
--detach \
runner
sleep 3
curl --fail http://localhost:3838 -o /dev/null || exit 1
bake-devcontainer: bake-developer bake-rstudio
# below 2 targets includes workaround b/c codespace prebuilds cannot access GHCR as per
# https://docs.github.com/en/codespaces/prebuilding-your-codespaces/managing-prebuilds#allowing-a-prebuild-to-access-external-resources
# w/o prebuilds, building takes too long, so we pull from GHCR instead
# this should be removed when GHCR prebuild access works
# there is no canonical way to know whether code is
# running inside the GHA worker for image creation
# GITHUB_ACTIONS etc. are not defined
# I found this env var by running printenv
# it may change and break this workflow
# can be removed once the whole workaround is obsolete
bake-developer:
ifdef GITHUB_CODESPACE_TOKEN
TAG_FROM_GIT_REF_NAME=$(tag_from_git_ref_name) \
docker compose pull developer
docker tag \
${REGISTRY_PREFIX}/${IMAGE_OWNER}/${IMAGE_NAME_ROOT}/developer:$(tag_from_git_ref_name) \
${REGISTRY_PREFIX}/${IMAGE_OWNER}/${IMAGE_NAME_ROOT}/developer:latest
else
TAG_FROM_GIT_SHA=$(tag_from_git_sha) \
TAG_FROM_GIT_REF_NAME=$(tag_from_git_ref_name) \
CAN_PUSH=$(can_push) \
docker buildx bake \
--file docker-bake.hcl \
--file .env \
developer
endif
bake-rstudio:
ifdef GITHUB_CODESPACE_TOKEN
TAG_FROM_GIT_REF_NAME=$(tag_from_git_ref_name) \
docker compose pull rstudio
docker tag \
${REGISTRY_PREFIX}/${IMAGE_OWNER}/${IMAGE_NAME_ROOT}/rstudio:$(tag_from_git_ref_name) \
${REGISTRY_PREFIX}/${IMAGE_OWNER}/${IMAGE_NAME_ROOT}/rstudio:latest
else
TAG_FROM_GIT_SHA=$(tag_from_git_sha) \
TAG_FROM_GIT_REF_NAME=$(tag_from_git_ref_name) \
CAN_PUSH=$(can_push) \
docker buildx bake \
--file docker-bake.hcl \
--file .env \
rstudio
endif
# this tests whether the devcontainer works using
# https://github.com/devcontainers/cli
devcontainer:
devcontainer up --workspace-folder .
superlint:
docker compose up super-linter
lint: actionlint dockerlint dotenv-lint eslint gitleaks jscpd markdownlint \
rlint sqllint yamllint
actionlint:
actionlint
dockerlint:
hadolint Dockerfile
dotenv-lint:
dotenv-linter
eslint:
npx eslint \
--ignore-path .gitignore \
--ext .json,js
gitleaks:
gitleaks detect
gitleaks protect
jscpd:
jscpd --silent .
markdownlint:
markdownlint --dot .
# rlint is *not* just static code analysis, because itruns eval, parse
# so it needs the project runtime (see Dockerfile)
rlint: roxygenise
Rscript -e "Sys.setenv("LINTR_ERROR_ON_LINT" = TRUE); devtools::load_all(); lintr::lint_package()"
sqllint: sqlfluff sql-lint
sqlfluff:
sqlfluff lint .
sql-lint:
sql-lint .
yamllint:
yamllint .