Skip to content

Commit

Permalink
Revert #4072 - don't use earthly for running integration tests (#5817)
Browse files Browse the repository at this point in the history
* Revert "Ability to run Github Action code locally (#4072)"

This reverts commit b2d9137.

* give development_workflow test more time to start server

* add simple script to run integration tests locally

* run integration tests with more versions

* do not duplicate integration test code
  • Loading branch information
SteffenDE committed May 27, 2024
1 parent 5684564 commit 69685f7
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 102 deletions.
48 changes: 37 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- elixir: 1.14.5
otp: 25.3

- elixir: 1.16.0
- elixir: 1.16.2
otp: 26.2
lint: true
installer: true
Expand Down Expand Up @@ -106,18 +106,44 @@ jobs:
integration-test-elixir:
runs-on: ubuntu-latest
env:
FORCE_COLOR: 1

strategy:
fail-fast: false
matrix:
include:
- elixir: 1.14.0
otp: 24.3.4
# look for correct alpine image here: https://hub.docker.com/r/hexpm/elixir/tags
- elixir: 1.14.5
otp: 25.3.2.12
suffix: "alpine-3.19.1"

- elixir: 1.16.2
otp: 26.2.5
suffix: "alpine-3.19.1"

container:
image: hexpm/elixir:${{ matrix.elixir }}-erlang-${{ matrix.otp }}-${{ matrix.suffix }}
env:
ELIXIR_ASSERT_TIMEOUT: 10000
services:
postgres:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: postgres
mysql:
image: mysql
ports:
- 3306:3306
env:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
mssql:
image: mcr.microsoft.com/mssql/server:2019-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: some!Password
ports:
- 1433:1433
steps:
- uses: actions/checkout@v4
- name: Download released earth
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.5.16/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
- name: Execute tests
run: earthly -P --build-arg ELIXIR=${{ matrix.elixir }} --build-arg OTP=${{ matrix.otp }} +integration-test
- uses: actions/[email protected]
- name: Run test script
run: ./integration_test/test.sh
69 changes: 0 additions & 69 deletions Earthfile

This file was deleted.

20 changes: 1 addition & 19 deletions integration_test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,7 @@ This allows all tests to be run with the following command

$ mix test --include database


## Alternative ways to run the integration tests

Phoenix uses Earthly as part of the CI process. It is possible to use earthly to test changes to integration tests locally. It is also possible to run the CI process locally, which is helpful when debugging CI failures.

[Installation Instructions](https://docs.earthly.dev/installation)

To run integration tests against all supported Elixir and OTP versions:

$ earthly -P +all-integration-test


To test a specific version:

$ earthly -P --build-arg ELIXIR=1.11.2 --build-arg OTP=21.3.8.18 +integration-test

To run the entire CI process locally, including unit and integration tests:

$ earthly -P +all
Or alternatively, with docker and docker compose installed, you can just run `./docker.sh`.

## How tests are written

Expand Down
35 changes: 35 additions & 0 deletions integration_test/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env sh -e

# adapt with versions from .github/versions/ci.yml if necessary;
# you can also override these with environment variables
ELIXIR="${ELIXIR:-1.16.2}"
ERLANG="${ERLANG:-26.2.5}"
SUFFIX="${SUFFIX:-alpine-3.19.1}"

# Get the directory of the script
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")

# Get the parent directory
PARENT_DIR=$(dirname "$SCRIPT_DIR")

# Check if docker-compose is available
if command -v docker-compose &> /dev/null
then
COMPOSE_CMD="docker-compose"
elif docker compose version &> /dev/null
then
COMPOSE_CMD="docker compose"
else
echo "Error: Neither docker-compose nor the docker compose plugin is available."
exit 1
fi

# Start databases
$COMPOSE_CMD up -d

# Run test script in container
docker run --rm --network=integration_test_default \
-w $PARENT_DIR -v $PARENT_DIR:$PARENT_DIR \
-it hexpm/elixir:$ELIXIR-erlang-$ERLANG-$SUFFIX sh integration_test/test.sh

$COMPOSE_CMD down
22 changes: 22 additions & 0 deletions integration_test/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh -e

mix local.rebar --force
mix local.hex --force

# Install Dependencies
apk add --no-progress --update git socat make gcc libc-dev

# Set up local proxies
socat TCP-LISTEN:5432,fork TCP-CONNECT:postgres:5432&
socat TCP-LISTEN:3306,fork TCP-CONNECT:mysql:3306&
socat TCP-LISTEN:1433,fork TCP-CONNECT:mssql:1433&

# Run installer tests
echo "Running installer tests"
cd installer
mix test

echo "Running integration tests"
cd ../integration_test
mix deps.get
mix test --include database
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithNoOptionsTest do
end)

:inets.start()
{:ok, response} = request_with_retries("http://localhost:4000")
{:ok, response} = request_with_retries("http://localhost:4000", 20)
assert response.status_code == 200
assert response.body =~ "PhxBlog"

Expand All @@ -68,7 +68,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithNoOptionsTest do
)
end

defp request_with_retries(url, retries \\ 10)
defp request_with_retries(url, retries)

defp request_with_retries(_url, 0), do: {:error, :out_of_retries}

Expand All @@ -85,7 +85,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithNoOptionsTest do
}}

{:error, {:failed_connect, _}} ->
Process.sleep(1_000)
Process.sleep(5_000)
request_with_retries(url, retries - 1)

{:error, reason} ->
Expand Down

0 comments on commit 69685f7

Please sign in to comment.