towerops/.forgejo/workflows/test.yml
Graham McIntire 5e0ac897f3
fix: add full OpenSSL 1.1 packages to CI for ubuntu-20.04 compatibility
- Added openssl and libssl1.1 packages alongside libssl-dev
- Fixes 'libcrypto.so.1.1: cannot open shared object file' error
- Required for Erlang crypto library on ubuntu-20.04 runners
2026-03-07 12:32:49 -06:00

190 lines
5 KiB
YAML

name: Tests
on:
push:
branches:
- main
pull_request:
branches:
- main
- production
env:
MIX_ENV: test
jobs:
test-exunit:
name: ExUnit Tests
runs-on: ubuntu-latest
services:
postgres:
image: timescale/timescaledb:latest-pg16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: towerops_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: https://github.com/actions/checkout@v4
- name: Set up Elixir
uses: https://github.com/erlef/setup-beam@v1
with:
version-type: strict
elixir-version: '1.18.1'
otp-version: '27.2'
- name: Cache deps
uses: https://github.com/actions/cache@v4
with:
path: deps
key: ${{ runner.os }}-deps-${{ hashFiles('mix.lock') }}
restore-keys: ${{ runner.os }}-deps-
- name: Cache _build
uses: https://github.com/actions/cache@v4
with:
path: _build
key: ${{ runner.os }}-build-${{ hashFiles('lib/**/*.ex') }}-${{ hashFiles('mix.lock') }}
restore-keys: ${{ runner.os }}-build-
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y openssl libssl1.1 libssl-dev libsnmp-dev snmp-mibs-downloader postgresql-client
- name: Install dependencies
run: mix deps.get
- name: Check formatting
run: mix format --check-formatted
- name: Compile (warnings as errors)
run: mix compile --warnings-as-errors
- name: Run tests with coverage
run: mix test --cover
- name: Run Credo
run: mix credo --strict
- name: Upload coverage reports
if: always()
uses: https://github.com/actions/upload-artifact@v4
with:
name: coverage-report
path: cover/
retention-days: 7
test-e2e:
name: E2E Tests
runs-on: ubuntu-latest
needs: test-exunit
services:
postgres:
image: timescale/timescaledb:latest-pg16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: towerops_dev
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: https://github.com/actions/checkout@v4
- name: Set up Elixir
uses: https://github.com/erlef/setup-beam@v1
with:
version-type: strict
elixir-version: '1.18.1'
otp-version: '27.2'
- name: Set up Node.js
uses: https://github.com/actions/setup-node@v4
with:
node-version: '20'
- name: Cache deps
uses: https://github.com/actions/cache@v4
with:
path: deps
key: ${{ runner.os }}-deps-${{ hashFiles('mix.lock') }}
restore-keys: ${{ runner.os }}-deps-
- name: Cache _build
uses: https://github.com/actions/cache@v4
with:
path: _build
key: ${{ runner.os }}-build-${{ hashFiles('lib/**/*.ex') }}-${{ hashFiles('mix.lock') }}
restore-keys: ${{ runner.os }}-build-
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y openssl libssl1.1 libssl-dev libsnmp-dev snmp-mibs-downloader postgresql-client
- name: Install Elixir dependencies
run: mix deps.get
env:
MIX_ENV: dev
- name: Setup database
run: mix ecto.setup
env:
MIX_ENV: dev
DATABASE_HOST: postgres
DATABASE_PORT: 5432
- name: Start Phoenix server in background
run: mix phx.server &
env:
MIX_ENV: dev
DATABASE_HOST: postgres
DATABASE_PORT: 5432
SECRET_KEY_BASE: dev_secret_key_base_for_testing_only_min_64_chars_required_here
PHX_HOST: localhost
- name: Wait for Phoenix to start
run: |
timeout 60 bash -c 'until curl -f http://localhost:4000/health; do sleep 2; done'
- name: Install Playwright dependencies
working-directory: e2e
run: |
npm ci
npx playwright install --with-deps
- name: Run e2e tests
working-directory: e2e
run: npm test
env:
CI: true
- name: Upload test results
if: failure()
uses: https://github.com/actions/upload-artifact@v4
with:
name: playwright-report
path: e2e/playwright-report/
retention-days: 7
- name: Upload screenshots on failure
if: failure()
uses: https://github.com/actions/upload-artifact@v4
with:
name: playwright-screenshots
path: e2e/test-results/
retention-days: 7