From 154888af0f0f73c9e49020a1ef33e2ef46889999 Mon Sep 17 00:00:00 2001 From: Brian Petersen Date: Thu, 12 Mar 2026 12:55:22 -0600 Subject: [PATCH] Adds CI/CD --- .github/workflows/ci.yml | 36 ++++++++++++++++ .github/workflows/release.yml | 77 +++++++++++++++++++++++++++++++++++ .tool-versions | 2 + README.md | 19 +++++++++ mix.exs | 21 +++++++--- mix.lock | 1 + 6 files changed, 150 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml create mode 100644 .tool-versions diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..dd79dc5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,36 @@ +name: CI + +on: + pull_request: + +jobs: + test: + name: Build and test + runs-on: ubuntu-latest + env: + MIX_ENV: test + LIBWBXML_FORCE_BUILD: true + + steps: + - name: Checkout repository + uses: actions/checkout@v6 + + - name: Set up Elixir and Erlang + uses: erlef/setup-beam@v1 + with: + version-file: .tool-versions + version-type: strict + + - name: Install native dependencies + run: | + sudo apt-get update + sudo apt-get install -y pkg-config libexpat1-dev + + - name: Install dependencies + run: mix deps.get + + - name: Run tests + run: mix test --warnings-as-errors + + - name: Check formatting + run: mix format --check-formatted diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..71b900f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,77 @@ +name: Release + +on: + push: + tags: + - v* + +jobs: + release-linux: + name: Release linux + runs-on: ubuntu-latest + + env: + MIX_ENV: prod + + steps: + - name: Checkout repository + uses: actions/checkout@v6 + + - name: Set up Elixir and Erlang + uses: erlef/setup-beam@v1 + with: + version-file: .tool-versions + version-type: strict + + - name: Install system dependecies + run: | + sudo apt-get update + sudo apt-get install -y build-essential automake autoconf pkg-config bc m4 unzip zip \ + libexpat1-dev + + - name: Install dependencies + run: mix deps.get + + - name: Create precompiled library + run: | + export ELIXIR_MAKE_CACHE_DIR=$(pwd)/cache + mkdir -p "${ELIXIR_MAKE_CACHE_DIR}" + mix elixir_make.precompile + + - name: Publish release artifacts + if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v2 + with: + files: cache/*.tar.gz + + release-macos: + name: Release macos + runs-on: macos-latest + + env: + MIX_ENV: prod + + steps: + - name: Checkout repository + uses: actions/checkout@v6 + + - name: Set up Elixir and Erlang + uses: erlef/setup-beam@v1 + with: + version-file: .tool-versions + version-type: strict + + - name: Install dependencies + run: mix deps.get + + - name: Create precompiled library + run: | + export ELIXIR_MAKE_CACHE_DIR=$(pwd)/cache + mkdir -p "${ELIXIR_MAKE_CACHE_DIR}" + mix elixir_make.precompile + + - name: Publish release artifacts + if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v2 + with: + files: cache/*.tar.gz diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..9d3c199 --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +elixir 1.19.4-otp-28 +erlang 28.3 diff --git a/README.md b/README.md index f69ccca..dc6cf2c 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,16 @@ The upstream `libwbxml` sources are vendored in `vendor/libwbxml/` and currently pinned to `libwbxml-0.11.10` (`e58b1f19f11dbadff53e5b486b8c4b16639a656a`). See `vendor/libwbxml/VENDORED_VERSION` for the pinned source metadata. +When release artifacts are available, `libwbxml` will prefer downloading a +precompiled NIF for the current target. Set `LIBWBXML_FORCE_BUILD=true` to skip +artifact download and force a local build from the vendored sources. + ## Compiler task * `mix compile` - builds native artefacts through `elixir_make` * `mix clean` - removes artefacts and the native build directory +* `MIX_ENV=prod mix elixir_make.precompile` - builds release tarballs for the + configured targets The task runs automatically when the dependency is compiled; you almost never need to invoke it manually. @@ -45,6 +51,19 @@ does **not** attempt to validate the *semantics* of the C library itself - we trust the upstream test-suite for that - only that our build & FFI plumbing is correct. +## Release workflow + +Create and push a version tag to trigger the release pipeline: + +```sh +git tag vX.Y.Z +git push origin vX.Y.Z +``` + +Pushing a `v*` tag automatically runs `.github/workflows/release.yml`, which +builds the precompiled artifacts, creates or updates the corresponding GitHub +Release, and uploads the generated tarballs. + ## License MIT for the Elixir wrapper. libwbxml itself is LGPL-2.1. diff --git a/mix.exs b/mix.exs index 843e0ba..2ed0038 100644 --- a/mix.exs +++ b/mix.exs @@ -1,15 +1,22 @@ defmodule Libwbxml.MixProject do use Mix.Project + @version "0.1.0" + @source_url "https://github.com/Jump-App/libwbxml" + def project do [ app: :libwbxml, - version: "0.1.0", - elixir: "~> 1.18", + version: @version, + elixir: "~> 1.19", elixirc_paths: ["lib"], start_permanent: Mix.env() == :prod, compilers: [:elixir_make] ++ Mix.compilers(), make_clean: ["clean"], + make_force_build: System.get_env("LIBWBXML_FORCE_BUILD") == "true", + make_precompiler: {:nif, CCPrecompiler}, + make_precompiler_filename: "wbxml_nif", + make_precompiler_url: "#{@source_url}/releases/download/v#{@version}/@{artefact_filename}", package: package(), deps: deps() ] @@ -17,7 +24,8 @@ defmodule Libwbxml.MixProject do defp deps do [ - {:elixir_make, "~> 0.9.0", runtime: false} + {:elixir_make, "~> 0.9.0", runtime: false}, + {:cc_precompiler, "~> 0.1", runtime: false} ] end @@ -25,12 +33,13 @@ defmodule Libwbxml.MixProject do [ files: [ "lib", - "vendor", "native", + "vendor", "Makefile", - "mix.exs" + "mix.exs", + "README.md" ], - maintainers: ["Carson Call"], + maintainers: ["Jump AI"], licenses: ["MIT"] ] end diff --git a/mix.lock b/mix.lock index 2962cda..d499a24 100644 --- a/mix.lock +++ b/mix.lock @@ -1,4 +1,5 @@ %{ + "cc_precompiler": {:hex, :cc_precompiler, "0.1.11", "8c844d0b9fb98a3edea067f94f616b3f6b29b959b6b3bf25fee94ffe34364768", [:mix], [{:elixir_make, "~> 0.7", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "3427232caf0835f94680e5bcf082408a70b48ad68a5f5c0b02a3bea9f3a075b9"}, "elixir_cmake": {:hex, :elixir_cmake, "0.8.0", "675a8d0b401096dee01dd5b1108e86e5f399db01c3e34edc0f92034bf38d8764", [:mix], [], "hexpm", "afd87e2ed89dc02eb3efc4e9025a0b79c8322bea8a5f6d9abc6063ca696a67f8"}, "elixir_make": {:hex, :elixir_make, "0.9.0", "6484b3cd8c0cee58f09f05ecaf1a140a8c97670671a6a0e7ab4dc326c3109726", [:mix], [], "hexpm", "db23d4fd8b757462ad02f8aa73431a426fe6671c80b200d9710caf3d1dd0ffdb"}, }