Repository navigation
Expand file tree
/
Copy pathcommon.mk
More file actions
188 lines (174 loc) · 4.91 KB
/
Copy pathcommon.mk
File metadata and controls
188 lines (174 loc) · 4.91 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
.SHELLFLAGS += -x -e
SHELL = /bin/bash
PWD = $(shell pwd)
UID = $(shell id -u)
GID = $(shell id -g)
VERSION = 0.72.0
VERSION_HASH = $(shell git rev-parse HEAD)
VERSION_TAG = $(shell git tag --points-at HEAD)
ifeq ($(CI),true)
ifeq ($(AK_IS_RELEASE),true)
VERSION_PKG = ${VERSION}
else
VERSION_PKG = ${VERSION}+ak-${shell git rev-parse HEAD | head -c 8}-$(GITHUB_RUN_ID)
endif
else
VERSION_PKG = ${VERSION}
endif
VERSION_TS = $(shell date +%s)
# Ubuntu release the e2e test machine is built from. The full set under test is
# enumerated in .github/workflows/test.yml's e2e matrix.
UBUNTU_VERSION ?= 24.04
export AK_E2E_UBUNTU_VERSION := $(UBUNTU_VERSION)
PLATFORM := $(shell bash -c "uname -o | tr '[:upper:]' '[:lower:]'")
ifeq ($(OS),Windows_NT)
ARCH := $(PROCESSOR_ARCHITEW6432)
else ifeq ($(PLATFORM),gnu/linux)
ARCH := $(shell dpkg-architecture -q DEB_BUILD_ARCH)
else
ARCH := $(shell uname -p)
endif
TOP = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
PROTO_DIR := "${TOP}/protobuf"
RUST_BUILD_FLAGS ?=
DOCKER_BUILDER_IMAGE ?= authentik/ak-builder
CARGO_CRATE_DIR := $(subst $(TOP),,$(CURDIR))
ifneq ($(LOCAL_WORKSPACE),)
CONTAINER_TOP := ${LOCAL_WORKSPACE}
else
CONTAINER_TOP := ${TOP}
endif
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
SED_INPLACE = /usr/bin/sed -i ''
else
SED_INPLACE = sed -i
endif
define cargo_build_local
RUSTFLAGS="$(RUST_BUILD_FLAGS)" \
AK_VERSION=${VERSION} \
AK_BUILDHASH=${VERSION_HASH} \
AK_TAG=${VERSION_TAG} \
cargo build \
--target-dir $(TOP)cache/shared \
--verbose \
--release $(2)
endef
ifeq ($(PLATFORM),gnu/linux)
define cargo_build
docker run --rm \
-i \
--volume "$(CONTAINER_TOP):/workspace" \
--workdir "/workspace/$(CARGO_CRATE_DIR)" \
--env RUSTFLAGS="$(RUST_BUILD_FLAGS)" \
--env AK_VERSION="${VERSION}" \
--env AK_BUILDHASH="${VERSION_HASH}" \
--env AK_TAG="${VERSION_TAG}" \
$(DOCKER_BUILDER_IMAGE) \
cargo build \
--target-dir /workspace/cache/shared \
--verbose \
--release
endef
else
define cargo_build
RUSTFLAGS="$(RUST_BUILD_FLAGS)" \
AK_VERSION=${VERSION} \
AK_BUILDHASH=${VERSION_HASH} \
AK_TAG=${VERSION_TAG} \
cargo build \
--target-dir $(TOP)cache/shared \
--verbose \
--release $(2)
endef
endif
define cargo_test
mkdir -p "${TOP}/cache"
RUSTFLAGS="$(RUST_BUILD_FLAGS)" \
cargo llvm-cov \
--no-report \
--ignore-filename-regex generated \
nextest -p $(1) \
--no-tests pass \
--no-fail-fast \
--test-threads 1
RUSTFLAGS="$(RUST_BUILD_FLAGS)" \
cargo llvm-cov report \
--codecov \
--ignore-filename-regex generated \
--output-path "${TOP}/cache/llvm-cov-target.json"
RUSTFLAGS="$(RUST_BUILD_FLAGS)" \
cargo llvm-cov report \
--html \
--ignore-filename-regex generated \
--output-dir "${TOP}/cache/llvm-cov-html/"
endef
define rs_e2e_coverage_convert
mkdir -p "${PWD}/cache"
PROFRAW_FILES=$$(find "${PWD}/ak-platform-e2e/coverage/rs" -name '*.profraw' 2>/dev/null | tr '\n' ' '); \
if [ -z "$$PROFRAW_FILES" ]; then \
echo "No Rust profraw files found in ak-platform-e2e/coverage/rs, creating empty coverage file"; \
touch "${PWD}/cache/rs-e2e-coverage.lcov"; \
else \
HOST=$$(rustc -vV 2>/dev/null | awk '/^host:/{print $$2}'); \
TOOLCHAIN=$$(rustup show active-toolchain 2>/dev/null | awk '{print $$1}'); \
LLVM_DIR=$$(rustup show home 2>/dev/null)/toolchains/$$TOOLCHAIN/lib/rustlib/$$HOST/bin; \
$$LLVM_DIR/llvm-profdata merge -sparse $$PROFRAW_FILES \
-o "${PWD}/cache/rs-e2e-merged.profdata"; \
OBJECTS=""; \
for bin in "${PWD}/bin/cli/ak" "${PWD}/bin/agent/ak-agent" "${PWD}/bin/sysd/ak-sysd" \
"${PWD}/bin/nss/libnss_authentik.so" "${PWD}/bin/pam/libpam_authentik.so"; do \
if [ -f "$$bin" ]; then OBJECTS="$$OBJECTS -object $$bin"; fi; \
done; \
if [ -z "$$OBJECTS" ]; then \
echo "No instrumented Rust binaries found in bin/, creating empty coverage file"; \
touch "${PWD}/cache/rs-e2e-coverage.lcov"; \
else \
$$LLVM_DIR/llvm-cov export \
-format=lcov \
-instr-profile="${PWD}/cache/rs-e2e-merged.profdata" \
$$OBJECTS \
-ignore-filename-regex='generated|\.cargo' \
> "${PWD}/cache/rs-e2e-coverage.lcov"; \
fi; \
fi
endef
TME := docker exec authentik-platform_devcontainer-test-machine-1
define lint_shellcheck
find $(1) -type f -name '*.sh' -exec "shellcheck" "--format=gcc" {} \;
endef
define sentry_upload_symbols
npx @sentry/cli debug-files upload \
--auth-token ${SENTRY_AUTH_TOKEN} \
--include-sources \
--org authentik-security-inc \
--project platform \
$(1)
endef
define sign_binary
smctl keypair ls
smctl sign \
--keypair-alias=key_1504090127 \
--simple \
--verbose \
--input $(1)
endef
define nfpm_package
VERSION_PKG=${VERSION_PKG} ARCH=${ARCH} \
nfpm \
package \
-p deb \
-t ${TOP}/bin/$(2) \
-f $(1)
VERSION_PKG=${VERSION_PKG} ARCH=${ARCH} \
nfpm \
package \
-p rpm \
-t ${TOP}/bin/$(2) \
-f $(1)
endef
define _target_template
.PHONY: $(1)/%
$(1)/%:
"$(MAKE)" -C "${TOP}/$(1)" $$*
endef