Skip to content
Damian edited this page Mar 13, 2023 · 4 revisions

Continuous Integration/Deployment with muddler

There are two ways to set things up

  • Locally
    • For doing development on your computer
    • Removes and reinstalls your package in an open profile every time you build the package
  • On Github
    • For use with github workflows

Locally

If you want to automatically install your pkg in your local Mudlet with muddler you can set the outputFile key in the mfile to true, which causes muddler to write a .output file to the root of your project when it is done building. This file contains a simple json object with the package name and the file location.

Then install the Muddler.mpackage from the releases page in Mudlet which allows for reloading muddler packages when they are built. This is intended to be develop time only, which is to say things you want to have happen when testing the package which you don't necessarily want to happen on pkg removal/install on your users machine, such as test object setup or teardown, running test functions, etc. If using this I recommend adding .output to your .gitignore file as it will see some churn during development.

The most basic of these might look like this:

myCIhelper = myCIhelper or Muddler:new({
  path = "/home/demonnic/gitbox/MDK"
})

And is enough to cause Mudlet to uninstall and reinstall the MDK mpackage created when I run muddler in /home/demonnic/gitbox/MDK. If you're using this on windows, still use / as the path separator, IE "C:/Users/demonnic/gitbox/MDK"

All available options are:

  • path
    • the path to the muddler project. "/home/demonnic/gitbox/MDK" for example
  • watch
    • determines if it will start the watcher on instantiation, or can be checked to see if it is active
  • preremove
    • runs before pkg removal
    • function or codestring like tempTimer/etc
      • [[send("test")]]
      • function() send("test") end
  • postremove
    • like preremove, but after pkg removal
  • preinstall
    • like preremove, but before pkg install
  • postinstall
    • like preremove, but after pkg install

The actual helper for MDK I'm using right now is setup like this

local function killMDK()
  for pkgName, _ in pairs(package.loaded) do
    if pkgName:find("MDK") then
      debugc("Uncaching lua package " .. pkgName)
      package.loaded[pkgName] = nil
    end
  end
end
local function create_helper()
  if MDKhelper then MDKhelper:stop() end
  MDKhelper = Muddler:new({
    path = "/home/demonnic/gitbox/MDK",
    postremove = killMDK,
  })
end

if not MDKhelper then
  registerAnonymousEventHandler("sysLoadEvent", create_helper)
end

And the output in the error console

image

On Github

If you are hosting your project on github and want to build the package with muddler as part of your PR process, I provide a couple of github actions for working automatically building and testing your packages.

And here is my MDK workflow for example. It builds the mpackage with Muddler, uploads it as a build artifact for download, and runs unit tests.

name: CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/[email protected]

      - name: Muddle
        uses: demonnic/[email protected]

      - name: Upload MPackage
        uses: actions/[email protected]
        with:
          name: MDK-package
          path: build/tmp/

      - name: Run Busted tests
        uses: demonnic/[email protected]
        with:
          pretestPackage: ${{ github.workspace }}/build/MDK.mpackage
Clone this wiki locally