feat(test): integration tests #160
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Continuous Integration | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
jobs: | |
test: | |
name: Build and test | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres:13 | |
env: | |
POSTGRES_PASSWORD: postgres | |
ports: | |
- 5432:5432 | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Elixir | |
uses: erlef/setup-beam@v1 | |
with: | |
elixir-version: "1.17.2" | |
otp-version: "26" | |
- name: Restore dependencies cache | |
uses: actions/cache@v3 | |
with: | |
path: deps | |
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} | |
restore-keys: ${{ runner.os }}-mix- | |
- name: Install dependencies | |
run: mix deps.get | |
- name: Run tests | |
run: mix test | |
env: | |
MIX_ENV: test | |
- name: Run test coverage | |
run: mix coveralls.json | |
env: | |
MIX_ENV: test | |
- name: Upload coverage report | |
uses: actions/upload-artifact@v3 | |
with: | |
name: coverage-report | |
path: cover/excoveralls.json | |
- name: Check formatting | |
run: mix format --check-formatted | |
- name: Run Credo | |
run: mix credo --ignore todo,aliasusage | |
- name: Check for security vulnerabilities | |
run: mix sobelow --config | |
- name: Install rust | |
uses: Swatinem/rust-cache@v2 | |
with: | |
shared-key: "cache" | |
save-if: false | |
- name: Setup db | |
run: mix ecto.setup | |
env: | |
MIX_ENV: test | |
- name: Integration tests | |
run: |- | |
cd integration-tests | |
touch .env | |
cargo run & | |
BTCD_AND_LND_SERVERS_PID=$! | |
# Wait until the nodes are running by checking if the the env var are exported | |
while [[ -z "${LND_URL}" ]]; do sleep 5 && source .env; done | |
cd .. | |
# mix doesn't behave when run in background, so we use `erlang -detached` instead | |
# but the `$!` thing won't work coz the app is run in another thread, | |
# so we write the actual pid in a file and later read it to kill it | |
elixir --erl "-detached" -e "File.write! 'pid', :os.getpid" -S mix phx.server | |
cd integration-tests | |
# Wait until the mix is finished compiling | |
until curl http://localhost:4000; do sleep 5; done; | |
cargo test | |
cat ../pid | xargs kill | |
kill $BTCD_AND_LND_SERVERS_PID | |
env: | |
MIX_ENV: dev | |