diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5dd7bef --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,71 @@ +name: Release CLI + +on: + push: + tags: + - "v*" + +permissions: + contents: write + +jobs: + test: + name: Lua tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Lua 5.1 + run: | + sudo apt-get update + sudo apt-get install -y lua5.1 + - name: Run tests + run: lua5.1 ./tests.lua --Linux + + package: + name: Package (${{ matrix.os_name }}) + runs-on: ${{ matrix.runner }} + needs: test + strategy: + matrix: + include: + - runner: ubuntu-latest + os_name: linux + - runner: macos-latest + os_name: macos + steps: + - uses: actions/checkout@v4 + - name: Install LuaJIT (Linux) + if: matrix.os_name == 'linux' + run: | + sudo apt-get update + sudo apt-get install -y luajit + - name: Install LuaJIT (macOS) + if: matrix.os_name == 'macos' + run: brew install luajit + - name: Build package + run: PROMETHEUS_BUNDLED_LUA="$(command -v luajit)" ./scripts/release/package.sh "${{ matrix.os_name }}" "${GITHUB_REF_NAME}" + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: prometheus-lua-${{ matrix.os_name }} + path: dist/prometheus-lua-${{ github.ref_name }}-${{ matrix.os_name }}.tar.gz + + publish: + name: Publish release + runs-on: ubuntu-latest + needs: package + steps: + - uses: actions/download-artifact@v4 + with: + path: dist + - name: Move release assets + run: | + mkdir -p dist/out + mv dist/prometheus-lua-linux/*.tar.gz dist/out/ + mv dist/prometheus-lua-macos/*.tar.gz dist/out/ + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ github.ref_name }} + files: dist/out/*.tar.gz + generate_release_notes: true diff --git a/.gitignore b/.gitignore index 8f202e6..1a3a7be 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ buildnotes.txt srlua.exe glue.exe build +dist # Web tooling node_modules diff --git a/README.md b/README.md index e2cf6c0..5ed4e22 100644 --- a/README.md +++ b/README.md @@ -53,21 +53,35 @@ Try the browser version first: Open Prometheus Web UI -### Local CLI usage -Clone the repository: +### Install CLI (Linux/macOS) + +Install latest release with one command: ```bash -git clone https://github.com/prometheus-lua/Prometheus.git -cd Prometheus +curl -fsSL https://raw.githubusercontent.com/prometheus-lua/Prometheus/master/install.sh | sh +``` + +Then use the CLI directly: + +```bash +prometheus-lua --version +prometheus-lua --preset Medium ./your_file.lua ``` -Alternatively, you can download the sources directly [here](https://github.com/prometheus-lua/Prometheus/archive/refs/heads/master.zip). +The release bundle includes a Lua runtime, so no separate Lua install is required for the packaged CLI. + +To update to the latest release: +```bash +prometheus-lua update +``` -To obfuscate a script, run: +### Local source usage ```bash -lua ./cli.lua --preset Medium ./your_file.lua +git clone https://github.com/prometheus-lua/Prometheus.git +cd Prometheus +./prometheus-lua --preset Medium ./your_file.lua ``` --- @@ -123,7 +137,8 @@ You can find the full documentation, including the getting started guide, here: ### Requirements -Prometheus requires **LuaJIT** or **Lua 5.1** in order to run. +Packaged CLI releases include a bundled Lua runtime. +For source usage, Prometheus requires **LuaJIT** or **Lua 5.1+**. Lua 5.1 binaries can be downloaded here: https://sourceforge.net/projects/luabinaries/files/5.1.5/Tools%20Executables/ diff --git a/doc/getting-started/installation.md b/doc/getting-started/installation.md index 197eea9..01bde29 100644 --- a/doc/getting-started/installation.md +++ b/doc/getting-started/installation.md @@ -1,11 +1,33 @@ # Installation -To install Prometheus, simply clone the Github Repository using: +## Linux and macOS (recommended) -```batch -git clone "https://github.com/levno-710/Prometheus.git" +Install the latest release: + +```bash +curl -fsSL https://raw.githubusercontent.com/prometheus-lua/Prometheus/master/install.sh | sh +``` + +Verify: + +```bash +prometheus-lua --version +``` + +Release bundles include a Lua runtime, so no separate Lua install is needed for installed CLI usage. + +Update later: + +```bash +prometheus-lua update ``` -Alternatively you can download the Sources [here](https://github.com/levno-710/Prometheus/archive/refs/heads/master.zip). +## From source + +```bash +git clone "https://github.com/prometheus-lua/Prometheus.git" +cd Prometheus +./prometheus-lua --preset Medium ./your_file.lua +``` -Prometheus also Requires LuaJIT or Lua51 in order to work. The Lua51 binaries can be downloaded [here](https://sourceforge.net/projects/luabinaries/files/5.1.5/Tools%20Executables/). +For source usage, Prometheus requires LuaJIT or Lua 5.1+. diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..c6e3fec --- /dev/null +++ b/install.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env sh +set -eu + +REPO="prometheus-lua/Prometheus" +INSTALL_BASE="${PROMETHEUS_LUA_HOME:-$HOME/.local/share/prometheus-lua}" +BIN_DIR="${PROMETHEUS_LUA_BIN:-$HOME/.local/bin}" + +need_cmd() { + if ! command -v "$1" >/dev/null 2>&1; then + echo "Missing required command: $1" >&2 + exit 1 + fi +} + +fetch() { + url="$1" + out="$2" + if command -v curl >/dev/null 2>&1; then + curl -fsSL "$url" -o "$out" + return + fi + if command -v wget >/dev/null 2>&1; then + wget -qO "$out" "$url" + return + fi + echo "Neither curl nor wget is installed." >&2 + exit 1 +} + +need_cmd tar +need_cmd uname +need_cmd mktemp +need_cmd grep +need_cmd sed + +OS_NAME="$(uname -s)" +case "$OS_NAME" in + Linux) OS="linux" ;; + Darwin) OS="macos" ;; + *) + echo "Unsupported operating system: $OS_NAME" >&2 + exit 1 + ;; +esac + +TMP_DIR="$(mktemp -d)" +trap 'rm -rf "$TMP_DIR"' EXIT INT TERM + +LATEST_JSON="$TMP_DIR/latest.json" +fetch "https://api.github.com/repos/$REPO/releases/latest" "$LATEST_JSON" + +TAG="$(grep '"tag_name":' "$LATEST_JSON" | sed -E 's/.*"([^"]+)".*/\1/' | head -n1)" +if [ -z "$TAG" ]; then + echo "Failed to resolve latest release tag." >&2 + exit 1 +fi + +ASSET="prometheus-lua-$TAG-$OS.tar.gz" +ASSET_URL="https://github.com/$REPO/releases/download/$TAG/$ASSET" +ARCHIVE_PATH="$TMP_DIR/$ASSET" + +fetch "$ASSET_URL" "$ARCHIVE_PATH" + +mkdir -p "$INSTALL_BASE" "$BIN_DIR" + +tar -xzf "$ARCHIVE_PATH" -C "$INSTALL_BASE" +TARGET_DIR="$INSTALL_BASE/prometheus-lua-$TAG-$OS" +if [ ! -d "$TARGET_DIR" ]; then + echo "Unexpected archive layout; missing $TARGET_DIR" >&2 + exit 1 +fi + +ln -sfn "$TARGET_DIR/prometheus-lua" "$BIN_DIR/prometheus-lua" +chmod +x "$TARGET_DIR/prometheus-lua" + +printf 'Installed prometheus-lua %s to %s\n' "$TAG" "$TARGET_DIR" +printf 'Linked command: %s/prometheus-lua\n' "$BIN_DIR" + +case ":$PATH:" in + *":$BIN_DIR:"*) + ;; + *) + printf 'Add %s to PATH, e.g.: export PATH="%s:$PATH"\n' "$BIN_DIR" "$BIN_DIR" + ;; +esac \ No newline at end of file diff --git a/prometheus-lua b/prometheus-lua new file mode 100755 index 0000000..5129993 --- /dev/null +++ b/prometheus-lua @@ -0,0 +1,27 @@ +#!/usr/bin/env sh +set -eu + +SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +BUNDLED_LUA="$SCRIPT_DIR/runtime/lua" + +: "${PROMETHEUS_LUA_VERSION:=dev}" +export PROMETHEUS_LUA_VERSION + +if [ -x "$BUNDLED_LUA" ]; then + exec "$BUNDLED_LUA" "$SCRIPT_DIR/cli.lua" "$@" +fi + +if command -v luajit >/dev/null 2>&1; then + exec luajit "$SCRIPT_DIR/cli.lua" "$@" +fi + +if command -v lua5.1 >/dev/null 2>&1; then + exec lua5.1 "$SCRIPT_DIR/cli.lua" "$@" +fi + +if command -v lua >/dev/null 2>&1; then + exec lua "$SCRIPT_DIR/cli.lua" "$@" +fi + +echo "No Lua runtime found. Reinstall with official installer or install Lua5.1/LuaJIT." >&2 +exit 1 diff --git a/scripts/release/package.sh b/scripts/release/package.sh new file mode 100755 index 0000000..e03b783 --- /dev/null +++ b/scripts/release/package.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env sh +set -eu + +if [ "${1:-}" = "" ]; then + echo "Usage: $0 [version]" >&2 + exit 1 +fi + +OS="$1" +VERSION="${2:-${GITHUB_REF_NAME:-}}" + +if [ -z "$VERSION" ]; then + VERSION="$(git describe --tags --abbrev=0 2>/dev/null || true)" +fi + +if [ -z "$VERSION" ]; then + echo "Version is required (pass as arg or run from a tagged commit)." >&2 + exit 1 +fi + +case "$OS" in + linux|macos) ;; + *) + echo "Unsupported OS '$OS'. Use linux or macos." >&2 + exit 1 + ;; +esac + +DIST_DIR="dist" +PKG_DIR="$DIST_DIR/prometheus-lua-$VERSION-$OS" +ARCHIVE="$DIST_DIR/prometheus-lua-$VERSION-$OS.tar.gz" + +rm -rf "$PKG_DIR" +mkdir -p "$PKG_DIR/src" +mkdir -p "$PKG_DIR/runtime" + +cp -R src/prometheus "$PKG_DIR/src/" +cp src/prometheus.lua "$PKG_DIR/src/" +cp src/logger.lua "$PKG_DIR/src/" +cp src/colors.lua "$PKG_DIR/src/" +cp src/highlightlua.lua "$PKG_DIR/src/" +cp src/presets.lua "$PKG_DIR/src/" +cp cli.lua "$PKG_DIR/" +cp LICENSE README.md "$PKG_DIR/" +cp prometheus-lua "$PKG_DIR/" + +RUNTIME_BIN="${PROMETHEUS_BUNDLED_LUA:-}" +if [ -z "$RUNTIME_BIN" ]; then + if command -v luajit >/dev/null 2>&1; then + RUNTIME_BIN="$(command -v luajit)" + elif command -v lua5.1 >/dev/null 2>&1; then + RUNTIME_BIN="$(command -v lua5.1)" + elif command -v lua >/dev/null 2>&1; then + RUNTIME_BIN="$(command -v lua)" + else + echo "No Lua runtime available to bundle. Install luajit/lua5.1 or set PROMETHEUS_BUNDLED_LUA." >&2 + exit 1 + fi +fi + +cp "$RUNTIME_BIN" "$PKG_DIR/runtime/lua" +chmod +x "$PKG_DIR/runtime/lua" + +# Inject release version into the packaged launcher without relying on git metadata at runtime. +sed -i.bak "s/PROMETHEUS_LUA_VERSION:=dev/PROMETHEUS_LUA_VERSION:=$VERSION/" "$PKG_DIR/prometheus-lua" +rm -f "$PKG_DIR/prometheus-lua.bak" +chmod +x "$PKG_DIR/prometheus-lua" + +mkdir -p "$DIST_DIR" +tar -czf "$ARCHIVE" -C "$DIST_DIR" "prometheus-lua-$VERSION-$OS" + +echo "Created $ARCHIVE" diff --git a/src/cli.lua b/src/cli.lua index 0502491..1628cdb 100644 --- a/src/cli.lua +++ b/src/cli.lua @@ -10,6 +10,82 @@ local function script_path() return str:match("(.*[/%\\])") end package.path = script_path() .. "?.lua;" .. package.path + +local INSTALL_SCRIPT_URL = "https://raw.githubusercontent.com/prometheus-lua/Prometheus/master/install.sh" + +local function run_shell(command) + local ok = os.execute(command) + if type(ok) == "number" then + return ok == 0 + end + if type(ok) == "boolean" then + return ok + end + return false +end + +local function get_version() + local version = os.getenv("PROMETHEUS_LUA_VERSION") + if version and version ~= "" then + return version + end + return "dev" +end + +local function print_help() + print("Prometheus Lua CLI") + print("Usage: prometheus-lua [command] [options] ") + print("") + print("Commands:") + print(" update Install latest release via installer script") + print(" --version, -v Print CLI version") + print("") + print("Obfuscation options:") + print(" --preset, --p Use preset (e.g. Minify, Medium, High)") + print(" --config, --c Use custom config Lua file") + print(" --out, --o Set output path") + print(" --Lua51 Force Lua 5.1 target") + print(" --LuaU Force LuaU target") + print(" --pretty Pretty print output") + print(" --nocolors Disable colored logs") + print(" --saveerrors Persist parser errors to file") +end + +local function run_update() + local command + if run_shell("command -v curl >/dev/null 2>&1") then + command = string.format("curl -fsSL '%s' | sh", INSTALL_SCRIPT_URL) + elseif run_shell("command -v wget >/dev/null 2>&1") then + command = string.format("wget -qO- '%s' | sh", INSTALL_SCRIPT_URL) + else + io.stderr:write("Neither curl nor wget was found. Please install one of them and retry.\n") + os.exit(1) + end + + print("Updating prometheus-lua using official installer") + if not run_shell(command) then + io.stderr:write("Update failed\n") + os.exit(1) + end + + print("Update completed") +end + +if arg[1] == "update" then + run_update() + os.exit(0) +end + +if arg[1] == "--version" or arg[1] == "-v" then + print(get_version()) + os.exit(0) +end + +if arg[1] == "--help" or arg[1] == "-h" or arg[1] == "help" then + print_help() + os.exit(0) +end + ---@diagnostic disable-next-line: different-requires local Prometheus = require("prometheus") Prometheus.Logger.logLevel = Prometheus.Logger.LogLevel.Info