Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: fix failing tests #1248

Merged
merged 21 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions .github/workflows/buildtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
echo "bin=$bin" >> $GITHUB_OUTPUT
- name: Run tests
run: ./result/bin/devenv test

tests:
needs: build
strategy:
Expand All @@ -48,27 +49,34 @@ jobs:
with:
name: devenv
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: |
- name: Build devenv
run: |
nix build
export PATH=$PWD/result/bin:$PATH
devenv shell devenv-test-cli
devenv-run-tests tests
echo "$PWD/result/bin" >> $GITHUB_PATH
- name: Run devenv-test-cli
run: devenv shell devenv-test-cli
- name: Run tests
run: devenv-run-tests tests

pin:
needs: build
if: startsWith(github.ref, 'refs/tags/v')
uses: ./.github/workflows/pin.yml
secrets: inherit

generate-examples:
runs-on: [self-hosted, linux, X64]
outputs:
examples: ${{ steps.set-examples.outputs.examples }}
steps:
- name: Checkout base repo
uses: actions/checkout@v4
- id: set-examples
- name: Fetch examples to run
id: set-examples
run: |
json=$(nix shell nixpkgs#tree -c tree -J -L 1 examples | nix shell nixpkgs#jq -c jq -c '[.[0].contents[] | .name]')
echo "examples=$json" >> $GITHUB_OUTPUT

examples:
name: ${{ matrix.example }} (${{ join(matrix.os) }})
needs: [generate-examples, build]
Expand All @@ -89,9 +97,13 @@ jobs:
with:
name: devenv
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: |
- name: Build devenv
run: |
nix build
PATH=$PWD/result/bin:$PATH devenv-run-tests --only ${{ matrix.example }} examples
echo "$PWD/result/bin" >> $GITHUB_PATH
- name: Run examples
run: devenv-run-tests --only ${{ matrix.example }} examples

direnv:
name: direnv (${{ join(matrix.os) }})
needs: build
Expand All @@ -109,6 +121,10 @@ jobs:
with:
name: devenv
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Build devenv
run: |
nix build
echo "$PWD/result/bin" >> $GITHUB_PATH
- run: |
mkdir -p ~/.config/direnv/
cat > ~/.config/direnv/direnv.toml << 'EOF'
Expand All @@ -117,13 +133,11 @@ jobs:
EOF

devenv_dir=$PWD
export PATH=$PWD/result/bin:$PATH
nix build

tmp="$(mktemp -d)"
pushd "$tmp"
nix shell nixpkgs#direnv -c devenv --override-input devenv path:$devenv_dir?dir=src/modules init
popd

fish-zsh:
name: zsh/fish (${{ join(matrix.os) }})
needs: build
Expand All @@ -141,7 +155,9 @@ jobs:
with:
name: devenv
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix build
- run: |
- name: Build devenv
run: nix build
- name: Test devenv in fish and zsh
run: |
nix shell nixpkgs#zsh -c zsh -c "./result/bin/devenv version"
nix shell nixpkgs#fish -c fish -c "./result/bin/devenv version"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Running ``devenv init`` generates ``devenv.nix``:
# https://devenv.sh/tests/
enterTest = ''
echo "Running tests"
git --version | grep "2.42.0"
git --version | grep --color=auto "${pkgs.git.version}"
'';

# https://devenv.sh/languages/
Expand All @@ -43,7 +43,7 @@ Running ``devenv init`` generates ``devenv.nix``:
pre-commit.hooks.shellcheck.enable = true;

# https://devenv.sh/processes/
processes.ping.exec = "ping example.com";
processes.ping.exec = "ping localhost";
}

```
Expand Down
38 changes: 26 additions & 12 deletions devenv-run-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,6 @@ fn run_tests_in_directory(args: &Args) -> Result<Vec<TestResult>, Box<dyn std::e
}
}

println!(" Running {}", dir_name);
// if .setup.sh exists, run it
let setup_script = path.join(".setup.sh");
if setup_script.exists() {
println!(" Running .setup.sh");
let _ = std::process::Command::new("bash")
.arg(".setup.sh")
.current_dir(path)
.status()?;
}

let mut config = devenv::config::Config::load_from(path)?;
for input in args.override_input.chunks_exact(2) {
config.add_input(&input[0].clone(), &input[1].clone(), &[]);
Expand All @@ -104,10 +93,35 @@ fn run_tests_in_directory(args: &Args) -> Result<Vec<TestResult>, Box<dyn std::e
devenv_dotfile: Some(tmpdir.path().to_path_buf()),
..Default::default()
};

let mut devenv = Devenv::new(options);
devenv.create_directories()?;

// A script to patch files in the working directory before the shell.
let patch_script = ".patch.sh";
let patch_script_path = path.join(patch_script);

// A script to run inside the shell before the test.
let setup_script = ".setup.sh";
let setup_script_path = path.join(setup_script);

println!(" Running {}", dir_name);

// Run .patch.sh if it exists
if patch_script_path.exists() {
println!(" Running {patch_script}");
let _ = std::process::Command::new("bash")
.arg("./.patch.sh")
.current_dir(path)
.status()?;
}

// Run .setup.sh if it exists
if setup_script_path.exists() {
println!(" Running {setup_script}");
devenv.shell(&Some(format!("./{setup_script}")), &[], false)?;
}

// TODO: wait for processes to shut down before exiting
let status = devenv.test();
let result = TestResult {
name: dir_name.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion devenv/init/devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# https://devenv.sh/tests/
enterTest = ''
echo "Running tests"
git --version | grep "2.42.0"
git --version | grep --color=auto "${pkgs.git.version}"
'';

# https://devenv.sh/pre-commit-hooks/
Expand Down
12 changes: 6 additions & 6 deletions docs/processes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Starting with a simple example:
{
processes = {
silly-example.exec = "while true; do echo hello && sleep 1; done";
ping.exec = "ping example.com";
ping.exec = "ping localhost";
};
}
```
Expand All @@ -23,14 +23,14 @@ Starting processes ...
20:37:44 system | ping.1 started (pid=4094686)
20:37:44 system | silly-example.1 started (pid=4094688)
20:37:44 silly-example.1 | hello
20:37:44 ping.1 | PING example.com (93.184.216.34) 56(84) bytes of data.
20:37:44 ping.1 | 64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=1 ttl=55 time=125 ms
20:37:44 ping.1 | PING localhost (127.0.0.1) 56 bytes of data.
20:37:44 ping.1 | 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.127 ms
20:37:45 silly-example.1 | hello
20:37:45 ping.1 | 64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=2 ttl=55 time=125 ms
20:37:45 ping.1 | 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.257 ms
20:37:46 silly-example.1 | hello
20:37:46 ping.1 | 64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=3 ttl=55 time=125 ms
20:37:46 ping.1 | 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.242 ms
20:37:47 silly-example.1 | hello
20:37:47 ping.1 | 64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=4 ttl=55 time=125 ms
20:37:47 ping.1 | 64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.249 ms
...
```

Expand Down
4 changes: 2 additions & 2 deletions examples/opentelemetry-collector/devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
receivers = {
otlp = {
protocols = {
grpc = { };
http = { };
grpc.endpoint = "localhost:4317";
http.endpoint = "localhost:4318";
};
};
};
Expand Down
15 changes: 15 additions & 0 deletions examples/phoenix/.setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -ex

mix local.hex --force
mix local.rebar --force
mix archive.install --force hex phx_new

if [ ! -d "hello" ]; then
echo y | mix phx.new --install hello
sed -i -e "s/hostname: \"localhost\"/socket_dir: System.get_env(\"PGHOST\")/" ./hello/config/dev.exs
fi

pushd hello
mix deps.get
popd
23 changes: 8 additions & 15 deletions examples/phoenix/devenv.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{ pkgs, lib, ... }:

# Install Phoenix dependencies:

# mix local.hex
# mix local.rebar
# mix archive.install hex phx_new
#
# Follow the instructions from https://hexdocs.pm/phoenix/up_and_running.html
# Run `mix phx.new hello --install` to create a new Phoenix project
{
packages = [
pkgs.git
Expand All @@ -16,19 +24,4 @@
};

processes.phoenix.exec = "cd hello && mix phx.server";

enterShell = ''
mix local.hex --force
mix local.rebar --force
mix archive.install --force hex phx_new

if [ ! -d "hello" ]; then
# guard against multiple invocation of "enterShell"
mkdir hello

echo y | mix phx.new --install hello
sed -i.bak -e "s/hostname: \"localhost\"/socket_dir: System.get_env(\"PGHOST\")/" \
./hello/config/dev.exs && rm ./hello/config/dev.exs.bak
fi
'';
}
2 changes: 1 addition & 1 deletion examples/python-django/devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ in
# dotenv.enable = true;

env = {
DATABASE_URL = "postgres://${db_user}@${config.env.PGHOST}/${db_name}";
DATABASE_URL = "postgres://${db_user}@/${db_name}?host=${config.env.PGHOST}";
DEBUG = true;
SECRET_KEY = "supersecret";
STATIC_ROOT = config.devenv.state + "/static";
Expand Down
12 changes: 12 additions & 0 deletions examples/rubyonrails/.setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -ex

gem install rails

if [ ! -d "blog" ]; then
rails new blog --database=postgresql --force
fi

pushd blog
bundle
popd
9 changes: 5 additions & 4 deletions examples/rubyonrails/.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
set -ex

pushd blog
wait_for_port 3000
rails db:create
curl -s http://localhost:3000/ | grep "version"
rails db:create
popd

wait_for_port 3000
curl -s http://localhost:3000/ | grep "version"

# make sure puma was compiled with ssl
ruby -rpuma -e 'exit 1 unless Puma.ssl?'
ruby -rpuma -e 'exit 1 unless Puma.ssl?'
16 changes: 8 additions & 8 deletions examples/rubyonrails/devenv.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{ pkgs, lib, ... }:

# Create a new Rails project:
#
# gem install rails
# rails new blog --database=postgresql --force
# cd blog
# bundle
{
languages.ruby.enable = true;
languages.ruby.version = "3.2.2";
Expand All @@ -9,20 +15,14 @@
pkgs.libyaml
pkgs.git
pkgs.curl
pkgs.redis
];

services.postgres.enable = true;

processes.rails.exec = "rails server";
processes.rails.exec = "cd blog && rails server";

enterShell = ''
if [ ! -d "blog" ]; then
gem install rails
rails new blog --database=postgresql --force
fi
export PATH="$DEVENV_ROOT/blog/bin:$PATH"
pushd blog
bundle
popd
'';
}
6 changes: 5 additions & 1 deletion examples/rust-wasm-cross/devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
};

pre-commit.hooks = {
clippy.enable = true;
clippy = {
enable = true;
settings.offline = false;
extraPackages = [ pkgs.openssl ];
};
rustfmt.enable = true;
};

Expand Down
2 changes: 1 addition & 1 deletion examples/simple/devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# pre-commit.hooks.shellcheck.enable = true;

# https://devenv.sh/processes/
# processes.ping.exec = "ping example.com";
# processes.ping.exec = "ping localhost";

# See full reference at https://devenv.sh/reference/options/
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ echo " languages.standardml.enable = lib.mkForce (!pkgs.stdenv.isAarch64);" >>
# https://github.com/NixOS/nixpkgs/issues/297019
echo " languages.purescript.enable = lib.mkForce (!pkgs.stdenv.isAarch64);" >> devenv.local.nix
echo " android.enable = lib.mkForce (pkgs.stdenv.isLinux && !pkgs.stdenv.isAarch64);" >> devenv.local.nix
# Doesn't build on macOS. Check nixpkgs
# Doesn't support arm.
echo " languages.odin.enable = lib.mkForce (!(pkgs.stdenv.isDarwin || (pkgs.stdenv.isLinux && pkgs.stdenv.isAarch64)));" >> devenv.local.nix
echo "}" >> devenv.local.nix
Loading
Loading