Adds Forgejo Actions CI/CD workflows: Production deployment (.forgejo/workflows/production.yml): - Runs on push to 'production' branch - Test gates (must pass before deploy): * All ExUnit tests with coverage * All e2e Playwright tests - Only deploys if both test suites pass - Builds Docker image - Pushes to git.mcintire.me registry - Updates k8s/deployment.yaml with new image tag - FluxCD auto-applies changes Main branch testing (.forgejo/workflows/test.yml): - Runs on push to 'main' or pull requests - Runs ExUnit tests with coverage - Runs e2e tests - No deployment (staging still via Dokku) Updated CLAUDE.md with CI/CD pipeline documentation.
190 lines
4.7 KiB
YAML
190 lines
4.7 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: actions/checkout@v4
|
|
|
|
- name: Set up Elixir
|
|
uses: erlef/setup-beam@v1
|
|
with:
|
|
version-type: strict
|
|
elixir-version: '1.18.1'
|
|
otp-version: '27.2'
|
|
|
|
- name: Cache deps
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: deps
|
|
key: ${{ runner.os }}-deps-${{ hashFiles('mix.lock') }}
|
|
restore-keys: ${{ runner.os }}-deps-
|
|
|
|
- name: Cache _build
|
|
uses: 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 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: 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: actions/checkout@v4
|
|
|
|
- name: Set up Elixir
|
|
uses: erlef/setup-beam@v1
|
|
with:
|
|
version-type: strict
|
|
elixir-version: '1.18.1'
|
|
otp-version: '27.2'
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20'
|
|
|
|
- name: Cache deps
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: deps
|
|
key: ${{ runner.os }}-deps-${{ hashFiles('mix.lock') }}
|
|
restore-keys: ${{ runner.os }}-deps-
|
|
|
|
- name: Cache _build
|
|
uses: 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 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: actions/upload-artifact@v4
|
|
with:
|
|
name: playwright-report
|
|
path: e2e/playwright-report/
|
|
retention-days: 7
|
|
|
|
- name: Upload screenshots on failure
|
|
if: failure()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: playwright-screenshots
|
|
path: e2e/test-results/
|
|
retention-days: 7
|