Skip to content

Commit

Permalink
chore: cli test script and simpler CI config
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreBeucher committed Feb 18, 2024
1 parent d229b98 commit 54148f2
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 102 deletions.
101 changes: 28 additions & 73 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,10 @@ on:
branches:
- "**"
- "!main"
tags:
- "v*.*.*"

jobs:

test:
runs-on: ubuntu-latest
if: " ! startsWith(github.event.ref, 'refs/tags/v')"
steps:
- uses: actions/checkout@v3

- uses: cachix/install-nix-action@v20
with:
nix_path: nixpkgs=channel:nixos-unstable

- uses: cachix/cachix-action@v12
with:
name: novops
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'

- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-${{ runner.arch }}-cargo

- uses: actions/cache@v3
with:
path: |
~/.local/share/containers/storage/
key: ${{ runner.os }}-${{ runner.arch }}-podman

- run: nix develop -c make test

build:
build-cross:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -63,7 +28,7 @@ jobs:
build/cache
key: ${{ runner.os }}-${{ runner.arch }}-podman

- run: nix develop -c make build-image build-binary
- run: nix develop .#cross -c make build-cross

- name: Upload built artifacts
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -93,48 +58,38 @@ jobs:

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

# Some end-user CLI test
# Which cannot be tested easily with unit tests
test-novops-cli:
test-cargo:
runs-on: ubuntu-latest
if: " ! startsWith(github.event.ref, 'refs/tags/v')"
needs: build
steps:
- uses: actions/checkout@v3

- name: download novops artifacts
uses: actions/download-artifact@v3
- uses: cachix/install-nix-action@v20
with:
name: novops-build
path: build

- name: novops load
run: |
ls -al build
chmod +x build/novops
build/novops load -c tests/.novops.plain-strings.yml -s .envrc -e dev
cat .envrc >> "$GITHUB_ENV"
nix_path: nixpkgs=channel:nixos-unstable

- name: check novops loaded values
run: env | grep MY_APP_HOST
- uses: cachix/cachix-action@v12
with:
name: novops
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'

- name: novops run and check var
run: |
build/novops run -c tests/.novops.plain-strings.yml -e dev -- sh -c "env | grep DOG_PATH"
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-${{ runner.arch }}-cargo

- name: novops run with builtin env variables
run: |
export NOVOPS_CONFIG=tests/.novops.plain-strings.yml
export NOVOPS_ENVIRONMENT=dev
build/novops run -- sh -c "env | grep DOG_PATH"
- uses: actions/cache@v3
with:
path: |
~/.local/share/containers/storage/
key: ${{ runner.os }}-${{ runner.arch }}-podman

- name: novops list environments
run: |
build/novops list environments -c tests/.novops.multi-env.yml | grep preprod
# json format should return "preprod" with quotes
build/novops list environments -c tests/.novops.multi-env.yml -o json | grep '"preprod"'
- name: novops list outputs
run: |
build/novops list outputs -e dev -c tests/.novops.multi-env.yml | grep MY_APP_HOST
build/novops list outputs -e dev -c tests/.novops.multi-env.yml -o json | grep '"MY_APP_HOST"'
# Plain cargo tests
- run: nix develop -c make test

# Additional CLI-based tests
- run: nix develop -c make test
39 changes: 10 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,38 +1,16 @@
# Build via cross
# Note it requires the .#cross nix development shell
#
# Keep cache under build/cache via bind mounts
# (instead of BuildKit cache mount which is harder to cache)
.PHONY: build-cache-dir
build-cache-dir:
mkdir -p build build/cache build/cache/cargo-target build/cache/cargo-reg

.PHONY: build-image
build-image: build-cache-dir
podman build \
-v ${PWD}/build/cache/cargo-target:/build/target \
-v ${PWD}/build/cache/cargo-reg:/root/.cargo/registry \
-t novops:local \
.
podman save novops:local -o build/image.tar --format=oci-archive

.PHONY: build-binary
build-binary: build-cache-dir
podman build \
-v ${PWD}/build/cache/cargo-target:/build/target \
-v ${PWD}/build/cache/cargo-reg:/root/.cargo/registry \
-o type=local,dest=build \
.

zip -j build/novops.zip build/novops
sha256sum build/novops.zip > build/novops.zip.sha256sum
.PHONY: build-cross
build-cross:
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-docker test-doc test-clippy test-cargo
test: test-docker test-doc test-clippy test-cargo test-cli

.PHONY: test-docker
test-docker:
Expand All @@ -42,6 +20,9 @@ test-docker:
test-cargo:
cargo test

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

.PHONY: test-clippy
test-clippy:
cargo clippy -- -D warnings
Expand Down
33 changes: 33 additions & 0 deletions tests/cli/test-usage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh
#
# Test CLI to ensure it's not broken
# Cargo tests ensure most features are OK but not CLI usage itself
# Here we tests all main commands and options are working and using properly internal code
#

set -ex

novops_test_cmd="cargo run --"
novops_test_dir="/tmp/novops-cli-test"
rm -rf $novops_test_dir
mkdir -p $novops_test_dir

# load
$novops_test_cmd load -c tests/.novops.plain-strings.yml -s $novops_test_dir/test.envrc -e dev
cat $novops_test_dir/test.envrc | grep "^export MY_APP_HOST='localhost'$"
$novops_test_cmd load -c tests/.novops.plain-strings.yml -s $novops_test_dir/test.dotenv -e dev -f dotenv
cat $novops_test_dir/test.dotenv | grep "^MY_APP_HOST='localhost'$"

# run
$novops_test_cmd run -c tests/.novops.plain-strings.yml -e dev -- sh -c "env | grep DOG_PATH"

# env vars
export NOVOPS_CONFIG=tests/.novops.plain-strings.yml
export NOVOPS_ENVIRONMENT=dev
$novops_test_cmd run -- sh -c "env | grep DOG_PATH"

# list
$novops_test_cmd list environments -c tests/.novops.multi-env.yml | grep preprod
$novops_test_cmd list environments -c tests/.novops.multi-env.yml -o json | grep '"preprod"'
$novops_test_cmd list outputs -e dev -c tests/.novops.multi-env.yml | grep MY_APP_HOST
$novops_test_cmd list outputs -e dev -c tests/.novops.multi-env.yml -o json | grep '"MY_APP_HOST"'

0 comments on commit 54148f2

Please sign in to comment.