towerops/.forgejo/workflows/pr-tests.yaml
Graham McIntire e54ee75513 Rewrite protobuf encoding/decoding in pure Gleam with integrated validation (#104)
Replace the protobuf hex package (agent.pb.ex) and hand-written validator
(validator.ex) with a pure Gleam implementation: wire format primitives,
all 23 message types, encode/decode functions, and validation merged into
decode. Thin Elixir wrappers in agent.ex preserve the existing struct API.

- Wire format: varint, length-delimited, double (IEEE 754 via FFI), tag encode/decode
- Types: all proto3 message types as Gleam custom types with enums and oneof
- Decode: field-level parsing with integrated validation (UUID, IP, hostname, limits)
- Encode: proto3 default omission, bytes_tree concatenation, map/repeated fields
- Wrappers: Elixir structs with encode/decode delegating to Gleam, enum atom conversion
- Remove {:protobuf, "~> 0.12"} dependency

Reviewed-on: graham/towerops-web#104
2026-03-21 16:08:40 -05:00

113 lines
3.1 KiB
YAML

name: Pull Request Tests
on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
- production
concurrency:
group: pr-tests-${{ github.event.pull_request.number }}
cancel-in-progress: true
env:
MIX_ENV: test
jobs:
test-exunit:
name: Run ExUnit Tests
runs-on: ubuntu-22.04
# Skip if PR is already merged
if: github.event.pull_request.merged == false
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 Gleam
run: |
curl -fsSL https://github.com/gleam-lang/gleam/releases/download/v1.15.2/gleam-v1.15.2-x86_64-unknown-linux-musl.tar.gz \
| sudo tar xz -C /usr/local/bin/
gleam --version
- name: Install mix_gleam archive
run: mix archive.install hex mix_gleam --force
- name: Install dependencies
run: mix deps.get
- name: Compile C NIF
run: make -C c_src
- name: Compile (warnings as errors)
run: mix compile --warnings-as-errors
- name: Lint Gleam (glinter)
run: |
output=$(gleam run -m glinter 2>&1) || true
echo "$output"
if echo "$output" | grep -qE '\([1-9][0-9]* errors?,'; then
echo "::error::Gleam lint errors found"
exit 1
fi
- 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