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 2e191eb
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 127 deletions.
5 changes: 0 additions & 5 deletions .cargo/config.toml

This file was deleted.

103 changes: 24 additions & 79 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ on:
branches:
- "**"
- "!main"
tags:
- "v*.*.*"

jobs:
test:

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

Expand All @@ -32,18 +29,13 @@ jobs:
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-${{ runner.arch }}-cargo
target/
key: ${{ runner.os }}-${{ runner.arch }}-build-cross

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

- run: nix develop -c make test
- run: nix develop .#cross -c make build-cross

build:
# Build and push to cachix
build-flake:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -56,28 +48,10 @@ jobs:
with:
name: novops
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'

- uses: actions/cache@v3
with:
path: |
build/cache
key: ${{ runner.os }}-${{ runner.arch }}-podman

- run: nix develop -c make build-image build-binary

- name: Upload built artifacts
uses: actions/upload-artifact@v3
with:
name: novops-build
if-no-files-found: error
path: |
build/novops
build/novops.zip
build/novops.zip.sha256sum
build/image.tar
- run: nix build --json | jq -r '.[].outputs | to_entries[].value' | cachix push novops

# Build and push to cachix
build-flake:
test-cargo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -90,51 +64,22 @@ jobs:
with:
name: novops
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'

- 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:
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: actions/cache@v3
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"
- name: check novops loaded values
run: env | grep MY_APP_HOST

- name: novops run and check var
run: |
build/novops run -c tests/.novops.plain-strings.yml -e dev -- sh -c "env | grep DOG_PATH"
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
57 changes: 14 additions & 43 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,38 +1,20 @@
# 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
# 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-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 +24,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 Expand Up @@ -101,17 +86,3 @@ release-artifacts:
gh release upload ${GITHUB_REF_NAME} \
build/novops-${RUNNER_ARCH}-${RUNNER_OS}.zip \
build/novops-${RUNNER_ARCH}-${RUNNER_OS}.zip.sha256sum

#
# Cross build
#

# Build all cross targets
# Use different target dir to avoid glibc version error
# See https://github.com/cross-rs/cross/issues/724
.PHONY: cross-build
cross-build:
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
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 2e191eb

Please sign in to comment.