Skip to content

Commit f219b76

Browse files
committed
add install script for macos and linux
1 parent c1ba56a commit f219b76

8 files changed

Lines changed: 382 additions & 13 deletions

File tree

.github/workflows/release.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Release CLI
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
test:
13+
name: Lua tests
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Install Lua 5.1
18+
run: |
19+
sudo apt-get update
20+
sudo apt-get install -y lua5.1
21+
- name: Run tests
22+
run: lua5.1 ./tests.lua --Linux
23+
24+
package:
25+
name: Package (${{ matrix.os_name }})
26+
runs-on: ${{ matrix.runner }}
27+
needs: test
28+
strategy:
29+
matrix:
30+
include:
31+
- runner: ubuntu-latest
32+
os_name: linux
33+
- runner: macos-latest
34+
os_name: macos
35+
steps:
36+
- uses: actions/checkout@v4
37+
- name: Install LuaJIT (Linux)
38+
if: matrix.os_name == 'linux'
39+
run: |
40+
sudo apt-get update
41+
sudo apt-get install -y luajit
42+
- name: Install LuaJIT (macOS)
43+
if: matrix.os_name == 'macos'
44+
run: brew install luajit
45+
- name: Build package
46+
run: PROMETHEUS_BUNDLED_LUA="$(command -v luajit)" ./scripts/release/package.sh "${{ matrix.os_name }}" "${GITHUB_REF_NAME}"
47+
- name: Upload artifact
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: prometheus-lua-${{ matrix.os_name }}
51+
path: dist/prometheus-lua-${{ github.ref_name }}-${{ matrix.os_name }}.tar.gz
52+
53+
publish:
54+
name: Publish release
55+
runs-on: ubuntu-latest
56+
needs: package
57+
steps:
58+
- uses: actions/download-artifact@v4
59+
with:
60+
path: dist
61+
- name: Move release assets
62+
run: |
63+
mkdir -p dist/out
64+
mv dist/prometheus-lua-linux/*.tar.gz dist/out/
65+
mv dist/prometheus-lua-macos/*.tar.gz dist/out/
66+
- name: Create GitHub Release
67+
uses: softprops/action-gh-release@v2
68+
with:
69+
tag_name: ${{ github.ref_name }}
70+
files: dist/out/*.tar.gz
71+
generate_release_notes: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ buildnotes.txt
1010
srlua.exe
1111
glue.exe
1212
build
13+
dist
1314

1415
# Web tooling
1516
node_modules

README.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,35 @@ Try the browser version first:
5353
<img src="https://img.shields.io/badge/Prometheus%20Web-Open-0F766E?style=for-the-badge&logo=github&logoColor=white" alt="Open Prometheus Web UI" />
5454
</a>
5555

56-
### Local CLI usage
57-
Clone the repository:
56+
### Install CLI (Linux/macOS)
57+
58+
Install latest release with one command:
5859

5960
```bash
60-
git clone https://github.com/prometheus-lua/Prometheus.git
61-
cd Prometheus
61+
curl -fsSL https://raw.githubusercontent.com/prometheus-lua/Prometheus/master/install.sh | sh
62+
```
63+
64+
Then use the CLI directly:
65+
66+
```bash
67+
prometheus-lua --version
68+
prometheus-lua --preset Medium ./your_file.lua
6269
```
6370

64-
Alternatively, you can download the sources directly [here](https://github.com/prometheus-lua/Prometheus/archive/refs/heads/master.zip).
71+
The release bundle includes a Lua runtime, so no separate Lua install is required for the packaged CLI.
72+
73+
To update to the latest release:
6574

75+
```bash
76+
prometheus-lua update
77+
```
6678

67-
To obfuscate a script, run:
79+
### Local source usage
6880

6981
```bash
70-
lua ./cli.lua --preset Medium ./your_file.lua
82+
git clone https://github.com/prometheus-lua/Prometheus.git
83+
cd Prometheus
84+
./prometheus-lua --preset Medium ./your_file.lua
7185
```
7286

7387
---
@@ -123,7 +137,8 @@ You can find the full documentation, including the getting started guide, here:
123137

124138
### Requirements
125139

126-
Prometheus requires **LuaJIT** or **Lua 5.1** in order to run.
140+
Packaged CLI releases include a bundled Lua runtime.
141+
For source usage, Prometheus requires **LuaJIT** or **Lua 5.1+**.
127142

128143
Lua 5.1 binaries can be downloaded here:
129144
https://sourceforge.net/projects/luabinaries/files/5.1.5/Tools%20Executables/
Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
11
# Installation
22

3-
To install Prometheus, simply clone the Github Repository using:
3+
## Linux and macOS (recommended)
44

5-
```batch
6-
git clone "https://github.com/levno-710/Prometheus.git"
5+
Install the latest release:
6+
7+
```bash
8+
curl -fsSL https://raw.githubusercontent.com/prometheus-lua/Prometheus/master/install.sh | sh
9+
```
10+
11+
Verify:
12+
13+
```bash
14+
prometheus-lua --version
15+
```
16+
17+
Release bundles include a Lua runtime, so no separate Lua install is needed for installed CLI usage.
18+
19+
Update later:
20+
21+
```bash
22+
prometheus-lua update
723
```
824

9-
Alternatively you can download the Sources [here](https://github.com/levno-710/Prometheus/archive/refs/heads/master.zip).
25+
## From source
26+
27+
```bash
28+
git clone "https://github.com/prometheus-lua/Prometheus.git"
29+
cd Prometheus
30+
./prometheus-lua --preset Medium ./your_file.lua
31+
```
1032

11-
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/).
33+
For source usage, Prometheus requires LuaJIT or Lua 5.1+.

install.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env sh
2+
set -eu
3+
4+
REPO="prometheus-lua/Prometheus"
5+
INSTALL_BASE="${PROMETHEUS_LUA_HOME:-$HOME/.local/share/prometheus-lua}"
6+
BIN_DIR="${PROMETHEUS_LUA_BIN:-$HOME/.local/bin}"
7+
8+
need_cmd() {
9+
if ! command -v "$1" >/dev/null 2>&1; then
10+
echo "Missing required command: $1" >&2
11+
exit 1
12+
fi
13+
}
14+
15+
fetch() {
16+
url="$1"
17+
out="$2"
18+
if command -v curl >/dev/null 2>&1; then
19+
curl -fsSL "$url" -o "$out"
20+
return
21+
fi
22+
if command -v wget >/dev/null 2>&1; then
23+
wget -qO "$out" "$url"
24+
return
25+
fi
26+
echo "Neither curl nor wget is installed." >&2
27+
exit 1
28+
}
29+
30+
need_cmd tar
31+
need_cmd uname
32+
need_cmd mktemp
33+
need_cmd grep
34+
need_cmd sed
35+
36+
OS_NAME="$(uname -s)"
37+
case "$OS_NAME" in
38+
Linux) OS="linux" ;;
39+
Darwin) OS="macos" ;;
40+
*)
41+
echo "Unsupported operating system: $OS_NAME" >&2
42+
exit 1
43+
;;
44+
esac
45+
46+
TMP_DIR="$(mktemp -d)"
47+
trap 'rm -rf "$TMP_DIR"' EXIT INT TERM
48+
49+
LATEST_JSON="$TMP_DIR/latest.json"
50+
fetch "https://api.github.com/repos/$REPO/releases/latest" "$LATEST_JSON"
51+
52+
TAG="$(grep '"tag_name":' "$LATEST_JSON" | sed -E 's/.*"([^"]+)".*/\1/' | head -n1)"
53+
if [ -z "$TAG" ]; then
54+
echo "Failed to resolve latest release tag." >&2
55+
exit 1
56+
fi
57+
58+
ASSET="prometheus-lua-$TAG-$OS.tar.gz"
59+
ASSET_URL="https://github.com/$REPO/releases/download/$TAG/$ASSET"
60+
ARCHIVE_PATH="$TMP_DIR/$ASSET"
61+
62+
fetch "$ASSET_URL" "$ARCHIVE_PATH"
63+
64+
mkdir -p "$INSTALL_BASE" "$BIN_DIR"
65+
66+
tar -xzf "$ARCHIVE_PATH" -C "$INSTALL_BASE"
67+
TARGET_DIR="$INSTALL_BASE/prometheus-lua-$TAG-$OS"
68+
if [ ! -d "$TARGET_DIR" ]; then
69+
echo "Unexpected archive layout; missing $TARGET_DIR" >&2
70+
exit 1
71+
fi
72+
73+
ln -sfn "$TARGET_DIR/prometheus-lua" "$BIN_DIR/prometheus-lua"
74+
chmod +x "$TARGET_DIR/prometheus-lua"
75+
76+
printf 'Installed prometheus-lua %s to %s\n' "$TAG" "$TARGET_DIR"
77+
printf 'Linked command: %s/prometheus-lua\n' "$BIN_DIR"
78+
79+
case ":$PATH:" in
80+
*":$BIN_DIR:"*)
81+
;;
82+
*)
83+
printf 'Add %s to PATH, e.g.: export PATH="%s:$PATH"\n' "$BIN_DIR" "$BIN_DIR"
84+
;;
85+
esac

prometheus-lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env sh
2+
set -eu
3+
4+
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
5+
BUNDLED_LUA="$SCRIPT_DIR/runtime/lua"
6+
7+
: "${PROMETHEUS_LUA_VERSION:=dev}"
8+
export PROMETHEUS_LUA_VERSION
9+
10+
if [ -x "$BUNDLED_LUA" ]; then
11+
exec "$BUNDLED_LUA" "$SCRIPT_DIR/cli.lua" "$@"
12+
fi
13+
14+
if command -v luajit >/dev/null 2>&1; then
15+
exec luajit "$SCRIPT_DIR/cli.lua" "$@"
16+
fi
17+
18+
if command -v lua5.1 >/dev/null 2>&1; then
19+
exec lua5.1 "$SCRIPT_DIR/cli.lua" "$@"
20+
fi
21+
22+
if command -v lua >/dev/null 2>&1; then
23+
exec lua "$SCRIPT_DIR/cli.lua" "$@"
24+
fi
25+
26+
echo "No Lua runtime found. Reinstall with official installer or install Lua5.1/LuaJIT." >&2
27+
exit 1

scripts/release/package.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env sh
2+
set -eu
3+
4+
if [ "${1:-}" = "" ]; then
5+
echo "Usage: $0 <linux|macos> [version]" >&2
6+
exit 1
7+
fi
8+
9+
OS="$1"
10+
VERSION="${2:-${GITHUB_REF_NAME:-}}"
11+
12+
if [ -z "$VERSION" ]; then
13+
VERSION="$(git describe --tags --abbrev=0 2>/dev/null || true)"
14+
fi
15+
16+
if [ -z "$VERSION" ]; then
17+
echo "Version is required (pass as arg or run from a tagged commit)." >&2
18+
exit 1
19+
fi
20+
21+
case "$OS" in
22+
linux|macos) ;;
23+
*)
24+
echo "Unsupported OS '$OS'. Use linux or macos." >&2
25+
exit 1
26+
;;
27+
esac
28+
29+
DIST_DIR="dist"
30+
PKG_DIR="$DIST_DIR/prometheus-lua-$VERSION-$OS"
31+
ARCHIVE="$DIST_DIR/prometheus-lua-$VERSION-$OS.tar.gz"
32+
33+
rm -rf "$PKG_DIR"
34+
mkdir -p "$PKG_DIR/src"
35+
mkdir -p "$PKG_DIR/runtime"
36+
37+
cp -R src/prometheus "$PKG_DIR/src/"
38+
cp src/prometheus.lua "$PKG_DIR/src/"
39+
cp src/logger.lua "$PKG_DIR/src/"
40+
cp src/colors.lua "$PKG_DIR/src/"
41+
cp src/highlightlua.lua "$PKG_DIR/src/"
42+
cp src/presets.lua "$PKG_DIR/src/"
43+
cp cli.lua "$PKG_DIR/"
44+
cp LICENSE README.md "$PKG_DIR/"
45+
cp prometheus-lua "$PKG_DIR/"
46+
47+
RUNTIME_BIN="${PROMETHEUS_BUNDLED_LUA:-}"
48+
if [ -z "$RUNTIME_BIN" ]; then
49+
if command -v luajit >/dev/null 2>&1; then
50+
RUNTIME_BIN="$(command -v luajit)"
51+
elif command -v lua5.1 >/dev/null 2>&1; then
52+
RUNTIME_BIN="$(command -v lua5.1)"
53+
elif command -v lua >/dev/null 2>&1; then
54+
RUNTIME_BIN="$(command -v lua)"
55+
else
56+
echo "No Lua runtime available to bundle. Install luajit/lua5.1 or set PROMETHEUS_BUNDLED_LUA." >&2
57+
exit 1
58+
fi
59+
fi
60+
61+
cp "$RUNTIME_BIN" "$PKG_DIR/runtime/lua"
62+
chmod +x "$PKG_DIR/runtime/lua"
63+
64+
# Inject release version into the packaged launcher without relying on git metadata at runtime.
65+
sed -i.bak "s/PROMETHEUS_LUA_VERSION:=dev/PROMETHEUS_LUA_VERSION:=$VERSION/" "$PKG_DIR/prometheus-lua"
66+
rm -f "$PKG_DIR/prometheus-lua.bak"
67+
chmod +x "$PKG_DIR/prometheus-lua"
68+
69+
mkdir -p "$DIST_DIR"
70+
tar -czf "$ARCHIVE" -C "$DIST_DIR" "prometheus-lua-$VERSION-$OS"
71+
72+
echo "Created $ARCHIVE"

0 commit comments

Comments
 (0)