Skip to content

Commit

Permalink
refactor: rewrite Makefile as Taskfile (except release)
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreBeucher committed Jul 4, 2024
1 parent 31ffd43 commit 9979e2e
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 78 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ tests/
.novops.yml
README.md
Makefile
Taskfile.yml
docs/
build/cache
10 changes: 7 additions & 3 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ jobs:
target/
key: ${{ runner.os }}-${{ runner.arch }}-build-cross

- run: nix develop .#cross -c make build-cross
- run: nix develop .#cross -c task build-cross-linux

# Can't include darwin targets as not possible to use it on CI directly for now
# since it requires custom Docker images which can't be published as per Apple licenses
# - run: nix develop .#cross -c task build-cross-macos

# Build and push to cachix
build-flake:
Expand All @@ -51,7 +55,7 @@ jobs:

- run: nix build --json | jq -r '.[].outputs | to_entries[].value' | cachix push novops

test-cargo:
test-all:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -82,4 +86,4 @@ jobs:
key: ${{ runner.os }}-${{ runner.arch }}-podman

# Run various tests
- run: nix develop -c make test
- run: nix develop -c task test-all
2 changes: 1 addition & 1 deletion .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Setup Pages # Useful? Not sure
uses: actions/configure-pages@v3

- run: nix develop -c make doc
- run: nix develop -c task doc

- name: Upload mdBook artifact
uses: actions/upload-pages-artifact@v1
Expand Down
132 changes: 66 additions & 66 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
# Build all cross targets
# Use different target dir to avoid glibc version error
# See https://github.com/cross-rs/cross/issues/724
.PHONY: build-cross
build-cross:
# Can't include darwin targets as not possible to use it on CI directly
# cross build --target x86_64-apple-darwin --target-dir target/cross/x86_64-apple-darwin
# cross build --target aarch64-apple-darwin --target-dir target/cross/aarch64-apple-darwin
cross build --target x86_64-unknown-linux-musl --target-dir target/cross/x86_64-unknown-linux-musl
cross build --target aarch64-unknown-linux-musl --target-dir target/cross/aarch64-unknown-linux-musl

.PHONY: build-nix
build-nix:
nix build -o build/nix

.PHONY: test
test: test-prepare test-doc test-clippy test-cargo test-cli test-install test-teardown

.PHONY: test-setup-pulumi
test-setup-pulumi:
pulumi -C tests/setup/pulumi/aws/ -s test up -yrf

.PHONY: test-prepare
test-prepare:
tests/scripts/test-docker-prepare.sh

.PHONY: test-teardown
test-teardown:
tests/scripts/test-docker-teardown.sh

.PHONY: test-cargo
test-cargo:
cargo test

test-cli:
tests/cli/test-usage.sh

.PHONY: test-clippy
test-clippy:
cargo clippy -- -D warnings

# Fails if doc is not up to date with current code
.PHONY: test-doc
test-doc: doc
git diff --exit-code docs/schema/config-schema.json

.PHONY: test-install
test-install:
tests/install/test-install.sh

# Build doc with mdBook and json-schema-for-humans
# See:
# - https://github.com/actions/starter-workflows/blob/main/pages/mdbook.yml
# - https://coveooss.github.io/json-schema-for-humans/#/
.PHONY: doc
doc:
mdbook build ./docs/
cargo run -- schema > docs/schema/config-schema.json
generate-schema-doc --config footer_show_time=false --config link_to_reused_ref=false --config expand_buttons=true docs/schema/config-schema.json docs/book/config/schema.html

doc-serve:
(cd docs/ && mdbook serve -o)

# Clean caches and temporary directories
clean:
echo "todo"
# # Build all cross targets
# # Use different target dir to avoid glibc version error
# # See https://github.com/cross-rs/cross/issues/724
# .PHONY: build-cross
# build-cross:
# # Can't include darwin targets as not possible to use it on CI directly
# # cross build --target x86_64-apple-darwin --target-dir target/cross/x86_64-apple-darwin
# # cross build --target aarch64-apple-darwin --target-dir target/cross/aarch64-apple-darwin
# cross build --target x86_64-unknown-linux-musl --target-dir target/cross/x86_64-unknown-linux-musl
# cross build --target aarch64-unknown-linux-musl --target-dir target/cross/aarch64-unknown-linux-musl

# .PHONY: build-nix
# build-nix:
# nix build -o build/nix

# .PHONY: test
# test: test-prepare test-doc test-clippy test-cargo test-cli test-install test-teardown

# .PHONY: test-setup-pulumi
# test-setup-pulumi:
# pulumi -C tests/setup/pulumi/aws/ -s test up -yrf

# .PHONY: test-prepare
# test-prepare:
# tests/scripts/test-docker-prepare.sh

# .PHONY: test-teardown
# test-teardown:
# tests/scripts/test-docker-teardown.sh

# .PHONY: test-cargo
# test-cargo:
# cargo test

# test-cli:
# tests/cli/test-usage.sh

# .PHONY: test-clippy
# test-clippy:
# cargo clippy -- -D warnings

# # Fails if doc is not up to date with current code
# .PHONY: test-doc
# test-doc: doc
# git diff --exit-code docs/schema/config-schema.json

# .PHONY: test-install
# test-install:
# tests/install/test-install.sh

# # Build doc with mdBook and json-schema-for-humans
# # See:
# # - https://github.com/actions/starter-workflows/blob/main/pages/mdbook.yml
# # - https://coveooss.github.io/json-schema-for-humans/#/
# .PHONY: doc
# doc:
# mdbook build ./docs/
# cargo run -- schema > docs/schema/config-schema.json
# generate-schema-doc --config footer_show_time=false --config link_to_reused_ref=false --config expand_buttons=true docs/schema/config-schema.json docs/book/config/schema.html

# doc-serve:
# (cd docs/ && mdbook serve -o)

# # Clean caches and temporary directories
# clean:
# echo "todo"


#
Expand Down
177 changes: 177 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
version: '3'

tasks:

#
# Build and docs
#

build-cross:
cmds:
- task: build-cross-linux
- task: build-cross-macos

build-cross-linux:
cmds:
- cross build --target x86_64-unknown-linux-musl --target-dir target/cross/x86_64-unknown-linux-musl
- cross build --target aarch64-unknown-linux-musl --target-dir target/cross/aarch64-unknown-linux-musl

build-cross-macos:
cmds:
- cross build --target x86_64-apple-darwin --target-dir target/cross/x86_64-apple-darwin
- cross build --target aarch64-apple-darwin --target-dir target/cross/aarch64-apple-darwin

build-nix:
desc: "Build using Nix"
cmds:
- nix build -o build/nix

doc:
desc: Build documentation
cmds:
- mdbook build ./docs/
- cargo run -- schema > docs/schema/config-schema.json
- generate-schema-doc --config footer_show_time=false --config link_to_reused_ref=false --config expand_buttons=true docs/schema/config-schema.json docs/book/config/schema.html

doc-serve:
desc: Serve documentation
cmds:
- (cd docs/ && mdbook serve -o)

#
# Tests
#

test-all:
cmds:
- task: test-cargo
- task: test-non-cargo

test-non-cargo:
cmds:
- task: test-doc
- task: test-clippy
- task: test-cli
- task: test-install

test-cargo:
cmds:
- task: test-cargo-setup
- task: test-cargo-run
- task: test-cargo-teardown

test-cargo-setup:
cmds:
- task: test-cargo-setup-containers
- task: test-cargo-setup-k8s
- task: test-cargo-setup-vault
- task: test-cargo-setup-azure
- task: test-cargo-setup-gcp
- task: test-cargo-setup-aws

test-cargo-teardown:
- kind delete cluster -n novops-auth-test
- docker compose -f "tests/setup/docker-compose.yml" down -v

# These stacks can be deleted safely as resources are within ephemeral containers
- pulumi -C "tests/setup/pulumi/vault" -s test stack rm -yf || true
- pulumi -C "tests/setup/pulumi/aws" -s test stack rm -yf || true

# These stacks MUSt be deleted properly as they manage real Cloud resources
- pulumi -C "tests/setup/pulumi/azure" -s test down -yrf
- pulumi -C "tests/setup/pulumi/gcp" -s test down -yrf

test-cargo-setup-containers:
cmd: docker compose -f "tests/setup/docker-compose.yml" up -d

test-cargo-setup-k8s:
cmds:
- |-
if ! kind get clusters | grep -q 'novops-auth-test'; then
kind create cluster -n novops-auth-test
docker network connect novops-test novops-auth-test-control-plane
else
echo "Kind cluster already exists, skipping."
fi
- kind get kubeconfig --name novops-auth-test > "tests/setup/k8s/kubeconfig"
- kind get kubeconfig --name novops-auth-test | yq '.clusters[0].cluster["certificate-authority-data"]' -r | base64 -d > "tests/setup/k8s/ca.pem"

# `select -c` creates stack if it does not exists
test-cargo-setup-vault:
cmds:
- pulumi -C "tests/setup/pulumi/vault" -s test stack select -c
- pulumi -C "tests/setup/pulumi/vault" -s test up -yfr

test-cargo-setup-azure:
cmds:
- pulumi -C "tests/setup/pulumi/azure" -s test stack select -c
- pulumi -C "tests/setup/pulumi/azure" -s test up -yfr

test-cargo-setup-gcp:
cmds:
- pulumi -C "tests/setup/pulumi/gcp" -s test stack select -c
- pulumi -C "tests/setup/pulumi/gcp" -s test up -yfr

test-cargo-setup-aws:
cmds:
- pulumi -C "tests/setup/pulumi/aws" -s test stack select -c
- pulumi -C "tests/setup/pulumi/aws" -s test up -yfr

test-setup-pulumi:
cmds:
- pulumi -C tests/setup/pulumi/aws/ -s test up -yrf

test-cargo-run:
cmd: cargo test

test-cli:
cmds:
- tests/cli/test-usage.sh

test-clippy:
cmds:
- cargo clippy -- -D warnings

test-doc:
cmds:
- task: doc
- git diff --exit-code docs/schema/config-schema.json

test-install:
cmds:
- tests/install/test-install.sh

#
# Release
#

# docker-publish:
# desc: Publish Docker image
# env:
# DOCKER_REPOSITORY: docker://docker.io/crafteo/novops
# GITHUB_REF_NAME: local
# cmds:
# - podman load -i build/image.tar
# - podman push novops:local ${DOCKER_REPOSITORY}:${GITHUB_REF_NAME}
# - podman push novops:local ${DOCKER_REPOSITORY}:latest

# release-tag:
# desc: Create a release tag
# cmds:
# - npx release-please github-release --repo-url https://github.com/PierreBeucher/novops --token=${GITHUB_TOKEN}

# release-pr:
# desc: Create a release PR
# cmds:
# - npx release-please release-pr --repo-url https://github.com/PierreBeucher/novops --token=${GITHUB_TOKEN}

# release-artifacts:
# desc: Publish artifacts on GitHub release
# env:
# RUNNER_ARCH: X64
# RUNNER_OS: Linux
# GITHUB_REF_NAME: local
# cmds:
# - cp build/novops.zip build/novops-${RUNNER_ARCH}-${RUNNER_OS}.zip
# - cp build/novops.zip.sha256sum build/novops-${RUNNER_ARCH}-${RUNNER_OS}.zip.sha256sum
# - gh release upload ${GITHUB_REF_NAME} build/novops-${RUNNER_ARCH}-${RUNNER_OS}.zip build/novops-${RUNNER_ARCH}-${RUNNER_OS}.zip.sha256sum
14 changes: 7 additions & 7 deletions docs/src/contributing/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cargo build -j 6
Novops is built for multiple platforms using `cross`:

```sh
make cross
make build-cross
```

For Darwin (macOS), you must build Darwin Cross image yourself (Apple does not allow distribution of macOS SDK required for cross-compilation, but you can download it yourself and package Cross image):
Expand Down Expand Up @@ -68,11 +68,11 @@ Integration tests are run when possible with real services, falling back to emul
- Azure: `--dry-run` mode

```sh
# Run Compose stack and run tests
make test
# Setup containers and infrastructure and run all tests
# See Taskfile.yml for details and fine-grained tasks
task test-all
# Alternatively, run Docker stack and specific tests
make test-docker
# Run Cargo with debug
RUST_LOG=novops=debug cargo test --test test_aws -- --nocapture
```

Expand All @@ -86,10 +86,10 @@ Doc is published from `main` branch by CI

```sh
# Build doc
make doc
task doc
# Serve at locahost:3000
make doc-serve
tasl doc-serve
```

## Release
Expand Down
Loading

0 comments on commit 9979e2e

Please sign in to comment.