-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Improved Makefile for more robust CI pipelines and development
- Loading branch information
1 parent
6d37b6c
commit 8ad96a0
Showing
3 changed files
with
88 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,84 @@ | ||
# Build the library with the specified tool chain. Default is x86_64-unknown-linux-gnu | ||
.PHONY: build | ||
build: | ||
cargo build $(ARGS) --release | ||
TOOL_CHAIN = | ||
ifndef TOOL_CHAIN | ||
TOOL_CHAIN = x86_64-unknown-linux-gnu | ||
endif | ||
build: format | ||
cargo clippy | ||
cargo build --target=$(TOOL_CHAIN) --release | ||
|
||
# Build documentation for the library | ||
.PHONY: doc | ||
doc: | ||
cargo fmt --check | ||
cargo doc --no-deps --open | ||
cargo doc --no-deps | ||
|
||
# Run all tests (no coverage) | ||
.PHONY: test | ||
test: | ||
ifndef KMS_KEY_ID | ||
$(error KMS_KEY_ID is not set) | ||
endif | ||
cargo fmt | ||
cargo test --lib --tests | ||
test: format check-env | ||
cargo test | ||
|
||
# Clean up | ||
.PHONY: clean | ||
clean: | ||
cargo clean | ||
|
||
# ==== Directives for developers ==== | ||
|
||
# Run unit and integration tests and measure coverage. | ||
# Additional flags can be passed with LLVM_COV_ARGS | ||
.PHONY: test-coverage | ||
test-coverage: | ||
cargo llvm-cov $(ARGS) | ||
test-coverage: check-env | ||
cargo llvm-cov $(LLVM_COV_ARGS) | ||
|
||
.PHONY: test-doc | ||
test-doc: | ||
ifndef KMS_KEY_ID | ||
$(error KMS_KEY_ID is not set) | ||
endif | ||
# Run only documentation tests (shorthand for developers) | ||
.PHONY: doc-test | ||
doc-test: format check-env | ||
cargo test --doc | ||
|
||
# Run only unit tests (shorthand for developers) | ||
.PHONY: unit-test | ||
unit-test: | ||
unit-test: format | ||
cargo test --lib | ||
|
||
.PHONY: integration-tests | ||
# Run only integration tests (shorthand for developers) | ||
.PHONY: integration-test | ||
integration-test: format check-env | ||
cargo test --tests | ||
|
||
# ==== Helper directives ==== | ||
|
||
# Format codebase | ||
.PHONY: format | ||
format: | ||
cargo fmt | ||
|
||
# Downloads and decodes the public key from KMS | ||
.PHONY: fetch-public-key | ||
PUBLIC_KEY_FILE_PATH = ./tests/data/pub-key | ||
PUBLIC_KEY_FILE_PEM = $(PUBLIC_KEY_FILE_PATH).pem | ||
PUBLIC_KEY_FILE_DER = $(PUBLIC_KEY_FILE_PATH).der | ||
fetch-public-key: check-env | ||
@aws kms get-public-key \ | ||
--region $(AWS_REGION) \ | ||
--key-id $(KMS_KEY_ID) \ | ||
--output text \ | ||
--query PublicKey > $(PUBLIC_KEY_FILE_PEM) || \ | ||
(echo "Failed to fetch public key" && exit 1) | ||
@cat $(PUBLIC_KEY_FILE_PEM) | base64 -d > $(PUBLIC_KEY_FILE_DER) | ||
@echo "Public key saved to $(PUBLIC_KEY_FILE_PEM) and decoded to $(PUBLIC_KEY_FILE_DER)" | ||
|
||
# Check if the environment variables are set and STS token is valid | ||
.PHONY: check-env | ||
check-env: | ||
ifndef KMS_KEY_ID | ||
$(error KMS_KEY_ID is not set) | ||
endif | ||
integration-test: | ||
cargo test --tests | ||
|
||
.PHONY: clean | ||
clean: | ||
cargo clean | ||
ifndef AWS_REGION | ||
$(error AWS_REGION is not set) | ||
endif | ||
@aws --version &> /dev/null || (echo "AWS CLI not installed" && exit 1) | ||
@aws sts get-caller-identity &> /dev/null || \ | ||
(echo "AWS CLI could not assume role. Did the STS token expire?" && exit 1) | ||
@echo "Environment variables are set and the STS token is valid" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters