Skip to content

Commit

Permalink
cli
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Jul 31, 2023
1 parent 144fa5a commit c09729e
Show file tree
Hide file tree
Showing 25 changed files with 390 additions and 210 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ set -euo pipefail
# External users should use `source_url` to load this file
source_env ./direnvrc

use devenv
use devenv
8 changes: 4 additions & 4 deletions .github/workflows/buildtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ jobs:
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: |
nix profile remove '.*'
nix profile install --accept-flake-config . "nixpkgs#gawk"
nix profile install --accept-flake-config .
- name: Disable package aliases
run: |
mkdir -p ~/.config/nixpkgs
echo '{ allowAliases = false; }' > ~/.config/nixpkgs/config.nix
- run: devenv shell devenv-test-example ${{ matrix.example }}
- run: devenv test ${{ matrix.example }}
direnv:
name: direnv (${{ join(matrix.os) }})
needs: build
Expand All @@ -92,15 +92,15 @@ jobs:
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: |
mv ./examples/simple/devenv.yaml ./examples/simple/devenv.yaml.orig
awk '
nix run nixpkgs#gawk -- '
{ print }
/^inputs:$/ {
print " devenv:";
print " url: path:../../src/modules";
}
' ./examples/simple/devenv.yaml.orig > ./examples/simple/devenv.yaml
nix profile remove '.*'
nix profile install . 'nixpkgs#direnv' nix profile install --accept-flake-config
nix profile install . 'nixpkgs#direnv'
mkdir -p ~/.config/direnv/
cat > ~/.config/direnv/direnv.toml << 'EOF'
[global]
Expand Down
43 changes: 3 additions & 40 deletions devenv.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{ inputs, pkgs, lib, config, ... }:

{
env = {
DEVENV_NIX = inputs.nix.packages.${pkgs.stdenv.system}.nix;
};
env.DEVENV_NIX = inputs.nix.packages.${pkgs.stdenv.system}.nix;

packages = [
pkgs.cairo
Expand Down Expand Up @@ -82,43 +80,6 @@
popd
rm -rf "$tmp"
'';
scripts.devenv-test-all-examples.exec = ''
for dir in $(ls examples); do
devenv-test-example $dir
done
'';
scripts.devenv-test-example.exec = ''
# execute all trap_ function on exit
trap 'eval $(declare -F | grep -o "trap_[^ ]*" | tr "\n" ";")' EXIT
set -e
example="$PWD/examples/$1"
pushd $example
mv devenv.yaml devenv.yaml.orig
awk '
{ print }
/^inputs:$/ {
print " devenv:";
print " url: path:../../src/modules";
}
' devenv.yaml.orig > devenv.yaml
trap_restore_yaml() {
mv "$example/devenv.yaml.orig" "$example/devenv.yaml"
}
devenv ci
if [ -f .test.sh ]; then
trap_restore_local() {
rm "$example/devenv.local.nix"
rm -rf "$example/.devenv"
}
# coreutils-full provides timeout on darwin
echo "{ pkgs, ... }: { packages = [ pkgs.coreutils-full ]; }" > devenv.local.nix
devenv shell ./.test.sh
else
devenv shell ls
fi
popd
'';
scripts."devenv-generate-doc-options".exec = ''
set -e
options=$(nix build --impure --extra-experimental-features 'flakes nix-command' --show-trace --print-out-paths --no-link '.#devenv-docs-options')
Expand Down Expand Up @@ -162,4 +123,6 @@
MD033 = false;
MD034 = false;
};

tests = config.lib.mkTests [ "devenv" ] ./examples;
}
6 changes: 1 addition & 5 deletions examples/clickhouse/.test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
#!/bin/sh
set -ex
pkill clickhouse
devenv up&
timeout 20 bash -c 'until echo > /dev/tcp/localhost/9000; do sleep 0.5; done'
clickhouse-client --query "SELECT 1"
clickhouse-client --query "SELECT 1"
4 changes: 0 additions & 4 deletions examples/mailpit/.test.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/bin/sh
set -ex

devenv up &
DEVENV_PID=$!
trap "pkill -P $DEVENV_PID" EXIT

timeout 20 bash -c 'until echo > /dev/tcp/localhost/1025; do sleep 0.5; done'

sendmail john@example.com <<EOF
Expand Down
7 changes: 1 addition & 6 deletions examples/minio/.test.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#!/bin/sh
set -ex

devenv up &
DEVENV_PID=$!
trap "pkill -P $DEVENV_PID" EXIT

timeout 20 bash -c 'until echo > /dev/tcp/localhost/9000; do sleep 0.5; done'

mc admin info local
mc admin info local
7 changes: 1 addition & 6 deletions examples/mysql/.test.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#!/bin/sh
set -ex

devenv up &
DEVENV_PID=$!
trap "pkill -P $DEVENV_PID" EXIT

timeout 60 bash -c 'until MYSQL_PWD="" mysql -u root test_database < /dev/null; do sleep 0.5; done'
timeout 60 bash -c 'until MYSQL_PWD="" mysql -u root test_database < /dev/null; do sleep 0.5; done'
4 changes: 0 additions & 4 deletions examples/postgres/.test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
#!/bin/sh
set -ex

devenv up &

timeout 20 bash -c 'until psql -h /tmp -c "SELECT 1" mydb 2>/dev/null; do sleep 0.5; done'
1 change: 0 additions & 1 deletion examples/rubyonrails/.test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/sh
set -ex
rails new blog -d=postgresql
devenv up&
timeout 20 bash -c 'until echo > /dev/tcp/localhost/5100; do sleep 0.5; done'
(cd blog && rails db:create)
curl -s http://localhost:5100/ | grep "version"
1 change: 0 additions & 1 deletion examples/rust/.test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/sh
set -ex
cargo --version
rustc --version
Expand Down
11 changes: 1 addition & 10 deletions examples/temporal/.test.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#!/bin/sh
set -x

# Start the services in the background and store the PID
echo "Starting temporal service..."
devenv up &
DEVENV_PID=$!

export TEMPORAL_ADDRESS=127.0.0.1:17233

# temporal status and store its exit status
Expand Down Expand Up @@ -34,9 +29,5 @@ echo "Startup complete..."
temporal operator cluster system
echo "$TEMPORAL_OUTPUT"

# Clean up by terminating all spawned processes
pkill -P $DEVENV_PID
wait $DEVENV_PID&>/dev/null

# Exit the script
exit $TEMPORAL_EXIT_STATUS
exit $TEMPORAL_EXIT_STATUS
9 changes: 0 additions & 9 deletions examples/vault/.test.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#!/bin/sh
set -x

# Start the services in the background and store the PID
echo "Starting vault service..."
devenv up&
DEVENV_PID=$!

# vault status and store its exit status
check_vault_status() {
echo "Waiting for service to become available..."
Expand All @@ -29,9 +24,5 @@ echo "Startup complete..."
vault version
echo "$VAULT_OUTPUT"

# Clean up by terminating all spawned processes
pkill -P $DEVENV_PID
wait $DEVENV_PID &> /dev/null

# Exit the script
exit $VAULT_EXIT_STATUS
Loading

0 comments on commit c09729e

Please sign in to comment.