From 4bada152192aaeaa24e7c5d47cd733b40f6aa7fb Mon Sep 17 00:00:00 2001 From: Mika Cohen Date: Wed, 17 Sep 2025 12:24:09 -0600 Subject: [PATCH 01/11] fix: Update for Elixir 1.19.0-rc.0 and OTP 28 compatibility - Move regex patterns from module attributes to functions to avoid Elixir 1.19 compilation errors with pattern injection - Fix struct update syntax deprecation warnings by using map syntax - Update flake.nix to use OTP 28.1 (latest) with Elixir 1.19.0-rc.0 - Add ab-av1 and mediainfo packages to development environment - Convert GitHub Actions to use NixOS runner with aggressive caching - Add local CI testing script for development workflow Fixes compilation errors: - ArgumentError: cannot inject attribute @patterns into function/macro - Deprecation warnings for struct update syntax in Elixir 1.19 --- .github/workflows/elixir.yml | 88 +++++++++++++----------- flake.nix | 18 +++-- lib/reencodarr/ab_av1/output_parser.ex | 61 ++++++++-------- lib/reencodarr/ab_av1/progress_parser.ex | 34 ++++----- lib/reencodarr/dashboard_state.ex | 6 +- 5 files changed, 108 insertions(+), 99 deletions(-) diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index a7bcf279..a40c2f26 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -11,74 +11,80 @@ permissions: jobs: build: - name: Build and test - runs-on: ubuntu-22.04 + runs-on: nixos-latest steps: - uses: actions/checkout@v4 - - name: Set up Elixir - uses: erlef/setup-beam@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0 - with: - elixir-version: '1.18.3' # [Required] Define the Elixir version - otp-version: '27.3.4' # [Required] Define the Erlang/OTP version - - - name: Install and cache apt packages - uses: awalsh128/cache-apt-pkgs-action@v1 + - name: Cache Nix store + uses: actions/cache@v4 with: - packages: fd-find ffmpeg zstd mediainfo - version: 1.0 + path: /nix/store + key: ${{ runner.os }}-nix-store-${{ hashFiles('flake.nix', 'flake.lock') }} + restore-keys: | + ${{ runner.os }}-nix-store- - - name: Cache ab-av1 binary - id: cache-ab-av1 + - name: Cache flake inputs uses: actions/cache@v4 with: - path: /usr/local/bin/ab-av1 - key: ab-av1-v0.10.1 - - - name: Install ab-av1 - if: steps.cache-ab-av1.outputs.cache-hit != 'true' - run: | - # Install ab-av1 from GitHub releases - wget -O /tmp/ab-av1.tar.zst https://github.com/alexheretic/ab-av1/releases/download/v0.10.1/ab-av1-v0.10.1-x86_64-unknown-linux-musl.tar.zst - cd /tmp && zstd -d ab-av1.tar.zst && tar -xf ab-av1.tar - sudo mv ab-av1 /usr/local/bin/ab-av1 - sudo chmod +x /usr/local/bin/ab-av1 + path: ~/.cache/nix + key: ${{ runner.os }}-nix-cache-${{ hashFiles('flake.lock') }} + restore-keys: | + ${{ runner.os }}-nix-cache- - - name: Restore dependencies cache + - name: Cache Mix dependencies uses: actions/cache@v4 with: - path: deps - key: ${{ runner.os }}-mix-deps-${{ hashFiles('**/mix.lock') }} - restore-keys: ${{ runner.os }}-mix-deps- + path: | + deps + _build/dev/lib + key: ${{ runner.os }}-nixos-mix-${{ hashFiles('mix.lock') }} + restore-keys: | + ${{ runner.os }}-nixos-mix- - - name: Restore build cache + - name: Cache Mix build artifacts uses: actions/cache@v4 with: path: _build - key: ${{ runner.os }}-mix-build-${{ hashFiles('**/mix.lock') }}-${{ hashFiles('**/*.ex') }}-${{ hashFiles('**/*.exs') }} + key: ${{ runner.os }}-nixos-build-${{ hashFiles('mix.lock') }}-${{ hashFiles('lib/**/*.ex', 'test/**/*.exs', 'config/**/*.exs') }} restore-keys: | - ${{ runner.os }}-mix-build-${{ hashFiles('**/mix.lock') }}- - ${{ runner.os }}-mix-build- + ${{ runner.os }}-nixos-build-${{ hashFiles('mix.lock') }}- + ${{ runner.os }}-nixos-build- + + - name: Setup Nix Binary Cache + run: | + echo "extra-substituters = https://cache.nixos.org https://nix-community.cachix.org" | sudo tee -a /etc/nix/nix.conf + echo "extra-trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" | sudo tee -a /etc/nix/nix.conf + sudo systemctl reload nix-daemon || true + + - name: Verify environment + run: | + nix develop --command bash -c " + echo 'Elixir version:' && elixir --version + echo 'Erlang version:' && erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell + echo 'ab-av1 version:' && ab-av1 --version + echo 'mediainfo version:' && mediainfo --version + echo 'ffmpeg version:' && ffmpeg -version | head -1 + " - name: Install dependencies - run: mix deps.get + run: nix develop --command mix deps.get - - name: Compile dependencies - run: mix deps.compile + - name: Compile dependencies + run: nix develop --command mix deps.compile - - name: Set MIX_ENV to test + - name: Set test environment run: echo "MIX_ENV=test" >> $GITHUB_ENV - name: Compile project - run: mix compile --warnings-as-errors + run: nix develop --command mix compile --warnings-as-errors - name: Check formatting - run: mix format --check-formatted + run: nix develop --command mix format --check-formatted - name: Run Credo - run: mix credo --strict + run: nix develop --command mix credo --strict - name: Run tests - run: mix test + run: nix develop --command mix test diff --git a/flake.nix b/flake.nix index 92e77fa7..e47b2bb5 100644 --- a/flake.nix +++ b/flake.nix @@ -14,15 +14,8 @@ system: let pkgs = import nixpkgs {inherit system;}; lib = pkgs.lib; - # current is 28.0.2 - erlang = pkgs.erlang; - # erlang = pkgs.erlang.override { - # version = "28.0.2"; - # src = pkgs.fetchurl { - # url = "https://github.com/erlang/otp/releases/download/OTP-${erlang.version}/otp_src_${erlang.version}.tar.gz"; - # sha256 = "sha256-zkPciimta8G22/yX8FPS6FC0pMKQ7KBlBY1rM85HbbU="; - # }; - # }; + # Use latest OTP 28.1 with Elixir 1.19.0-rc.0 for cutting-edge features + erlang = pkgs.erlang_28; beamPackages = pkgs.beam.packagesWith erlang; elixir = beamPackages.elixir.override { erlang = erlang; @@ -67,7 +60,7 @@ nativeBuildInputs = [ erlang - pkgs.elixir + elixir beamPackages.ex_doc beamPackages.hex beamPackages.rebar @@ -86,6 +79,11 @@ pkgs.gnupg pkgs.pinentry pkgs.pinentry-curses + # Video processing tools for CI/dev + pkgs.ab-av1 + pkgs.mediainfo + # GitHub Actions local testing + pkgs.act ] ++ lib.optional pkgs.stdenv.isLinux pkgs.libnotify ++ lib.optional pkgs.stdenv.isLinux pkgs.inotify-tools diff --git a/lib/reencodarr/ab_av1/output_parser.ex b/lib/reencodarr/ab_av1/output_parser.ex index 98483a2e..41551d08 100644 --- a/lib/reencodarr/ab_av1/output_parser.ex +++ b/lib/reencodarr/ab_av1/output_parser.ex @@ -8,30 +8,6 @@ defmodule Reencodarr.AbAv1.OutputParser do alias Reencodarr.Core.Parsers - # Pattern definitions - @patterns %{ - encoding_sample: - ~r/encoding\ssample\s(?\d+)\/(?\d+)\scrf\s(?\d+(?:\.\d+)?)/, - simple_vmaf: - ~r/(?:\[(?[^\]]+)\].*?)?crf\s(?\d+(?:\.\d+)?)\sVMAF\s(?\d+\.\d+)\s\((?\d+)%\)/, - sample_vmaf: - ~r/sample\s(?\d+)\/(?\d+)\scrf\s(?\d+(?:\.\d+)?)\sVMAF\s(?\d+\.\d+)\s\((?\d+)%\)/, - dash_vmaf: ~r/^-\scrf\s(?\d+(?:\.\d+)?)\sVMAF\s(?\d+\.\d+)\s\((?\d+)%\)/, - eta_vmaf: - ~r/crf\s(?\d+(?:\.\d+)?)\sVMAF\s(?\d+\.\d+)\spredicted\svideo\sstream\ssize\s(?\d+\.?\d*)\s(?\w+)\s\((?\d+)%\)\staking\s(?