ci: add ExUnit test workflow for pull requests

This commit is contained in:
Graham McIntire 2026-03-15 16:41:35 -05:00
parent acf70b3bee
commit 9fffa28b00
No known key found for this signature in database

View file

@ -0,0 +1,85 @@
name: Pull Request Tests
on:
pull_request:
branches:
- main
- production
env:
MIX_ENV: test
jobs:
test-exunit:
name: Run ExUnit Tests
runs-on: ubuntu-22.04
env:
DATABASE_URL: ecto://postgres:postgres@postgres/towerops_test
services:
postgres:
image: timescale/timescaledb:latest-pg17
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 Mix
uses: https://github.com/actions/cache@v4
with:
path: ~/.mix
key: ${{ runner.os }}-mix-1.18.1-27.2
restore-keys: ${{ runner.os }}-mix-
- 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 libssl-dev libsnmp-dev snmp-mibs-downloader postgresql-client
- name: Install dependencies
run: mix deps.get
- name: Compile (warnings as errors)
run: mix compile --warnings-as-errors
- name: Run tests
run: mix test
- name: Test summary
if: always()
run: |
if [ ${{ job.status }} == 'success' ]; then
echo "### ✅ All tests passed" >> $GITHUB_STEP_SUMMARY
else
echo "### ❌ Tests failed" >> $GITHUB_STEP_SUMMARY
fi