|
| 1 | +#!/bin/bash |
| 2 | +# actrun - ActionForge graph runner |
| 3 | +# |
| 4 | +# This script is deployed at: |
| 5 | +# https://www.actionforge.dev/actrun.sh |
| 6 | +# |
| 7 | +# This script is deployed from: |
| 8 | +# https://github.com/actionforge/actrun-cli/blob/main/actrun.sh |
| 9 | +# |
| 10 | +# Usage: |
| 11 | +# curl -fsSL https://www.actionforge.dev/actrun.sh | bash -s -- <file.act> [options] |
| 12 | +# curl -fsSL https://www.actionforge.dev/actrun.sh | bash -s -- <shared-url> [options] |
| 13 | +# |
| 14 | +# Examples: |
| 15 | +# curl -fsSL https://www.actionforge.dev/actrun.sh | bash -s -- hello-world.act |
| 16 | +# curl -fsSL https://www.actionforge.dev/actrun.sh | bash -s -- workflow.act --verbose |
| 17 | +# curl -fsSL https://www.actionforge.dev/actrun.sh | bash -s -- https://app.actionforge.dev/shared/wispy-paper-a49c664e.act |
| 18 | +# curl -fsSL https://www.actionforge.dev/actrun.sh | bash -s -- --help |
| 19 | +# |
| 20 | +set -e |
| 21 | + |
| 22 | +DOWNLOAD_BASE="https://www.actionforge.dev/download" |
| 23 | +API_URL="https://app.actionforge.dev/api/v2/releases/list" |
| 24 | +SHARE_API_URL="https://app.actionforge.dev/api/v2/share/graph/read" |
| 25 | +CACHE_DIR="${HOME}/.cache/actrun" |
| 26 | + |
| 27 | +# Detect OS |
| 28 | +case "$(uname -s)" in |
| 29 | + Linux*) OS="linux" ;; |
| 30 | + Darwin*) OS="macos" ;; |
| 31 | + MINGW*|MSYS*|CYGWIN*) OS="windows" ;; |
| 32 | + *) echo "❌ Unsupported OS: $(uname -s)" >&2; exit 1 ;; |
| 33 | +esac |
| 34 | + |
| 35 | +# Detect architecture |
| 36 | +case "$(uname -m)" in |
| 37 | + x86_64|amd64) ARCH="x64" ;; |
| 38 | + arm64|aarch64) ARCH="arm64" ;; |
| 39 | + *) echo "❌ Unsupported architecture: $(uname -m)" >&2; exit 1 ;; |
| 40 | +esac |
| 41 | + |
| 42 | +# Get latest version from API (find highest version, excluding prereleases) |
| 43 | +VERSION=$(curl -fsSL "$API_URL" | \ |
| 44 | + grep -o '"version":"v[0-9]*\.[0-9]*\.[0-9]*"' | \ |
| 45 | + cut -d'"' -f4 | sort -uV | tail -1) |
| 46 | + |
| 47 | +if [ -z "$VERSION" ]; then |
| 48 | + echo "❌ Failed to fetch latest version" >&2 |
| 49 | + exit 1 |
| 50 | +fi |
| 51 | + |
| 52 | +# Check cache |
| 53 | +CACHE_VERSION_DIR="$CACHE_DIR/$VERSION" |
| 54 | +if [ "$OS" = "windows" ]; then |
| 55 | + CACHED_BINARY="$CACHE_VERSION_DIR/actrun.exe" |
| 56 | +else |
| 57 | + CACHED_BINARY="$CACHE_VERSION_DIR/actrun" |
| 58 | +fi |
| 59 | + |
| 60 | +if [ -x "$CACHED_BINARY" ]; then |
| 61 | + echo "✅ Using cached actrun $VERSION" |
| 62 | + |
| 63 | + # Process shared URL if first argument matches the pattern |
| 64 | + if [ $# -gt 0 ] && [[ "$1" =~ ^https://app\.actionforge\.dev/shared/([a-zA-Z0-9_-]+\.act)$ ]]; then |
| 65 | + share_id="${BASH_REMATCH[1]}" |
| 66 | + echo "🔗 Fetching shared graph: $share_id" |
| 67 | + |
| 68 | + graph_tmp=$(mktemp -t "actrun-shared-XXXXXX.act") |
| 69 | + trap "rm -f '$graph_tmp'" EXIT |
| 70 | + |
| 71 | + if ! curl -fsSL "${SHARE_API_URL}?id=${share_id}" -o "$graph_tmp"; then |
| 72 | + echo "❌ Failed to fetch shared graph: $share_id" >&2 |
| 73 | + exit 1 |
| 74 | + fi |
| 75 | + |
| 76 | + shift |
| 77 | + exec "$CACHED_BINARY" "$graph_tmp" "$@" |
| 78 | + fi |
| 79 | + |
| 80 | + exec "$CACHED_BINARY" "$@" |
| 81 | +fi |
| 82 | + |
| 83 | +# Determine file extension |
| 84 | +case "$OS" in |
| 85 | + linux) EXT="tar.gz" ;; |
| 86 | + windows) EXT="zip" ;; |
| 87 | + macos) EXT="pkg" ;; |
| 88 | +esac |
| 89 | + |
| 90 | +FILENAME="actrun-${VERSION}.cli-${ARCH}-${OS}.${EXT}" |
| 91 | +URL="${DOWNLOAD_BASE}/${FILENAME}" |
| 92 | + |
| 93 | +echo "⬇️ Downloading $FILENAME..." |
| 94 | + |
| 95 | +TMP_DIR=$(mktemp -d) |
| 96 | +cleanup() { |
| 97 | + rm -rf "$TMP_DIR" |
| 98 | +} |
| 99 | +trap cleanup EXIT |
| 100 | + |
| 101 | +curl -fsSL "$URL" -o "$TMP_DIR/$FILENAME" |
| 102 | + |
| 103 | +echo "📦 Unpacking..." |
| 104 | + |
| 105 | +# Extract and find binary |
| 106 | +case "$OS" in |
| 107 | + linux) |
| 108 | + tar -xzf "$TMP_DIR/$FILENAME" -C "$TMP_DIR" |
| 109 | + BINARY="$TMP_DIR/actrun" |
| 110 | + ;; |
| 111 | + windows) |
| 112 | + unzip -q "$TMP_DIR/$FILENAME" -d "$TMP_DIR" |
| 113 | + BINARY="$TMP_DIR/actrun.exe" |
| 114 | + ;; |
| 115 | + macos) |
| 116 | + pkgutil --expand-full "$TMP_DIR/$FILENAME" "$TMP_DIR/pkg_expanded" |
| 117 | + BINARY=$(find "$TMP_DIR/pkg_expanded" -name "actrun" -type f -perm +111 2>/dev/null | head -1) |
| 118 | + if [ -z "$BINARY" ]; then |
| 119 | + BINARY=$(find "$TMP_DIR/pkg_expanded" -name "actrun" -type f | head -1) |
| 120 | + fi |
| 121 | + ;; |
| 122 | +esac |
| 123 | + |
| 124 | +if [ ! -f "$BINARY" ]; then |
| 125 | + echo "❌ Failed to find actrun binary" >&2 |
| 126 | + exit 1 |
| 127 | +fi |
| 128 | + |
| 129 | +# Cache the binary |
| 130 | +mkdir -p "$CACHE_VERSION_DIR" |
| 131 | +cp "$BINARY" "$CACHED_BINARY" |
| 132 | +chmod +x "$CACHED_BINARY" |
| 133 | + |
| 134 | +echo "✅ Unpacked actrun $VERSION" |
| 135 | + |
| 136 | +# Process shared URL if first argument matches the pattern |
| 137 | +if [ $# -gt 0 ] && [[ "$1" =~ ^https://app\.actionforge\.dev/shared/([a-zA-Z0-9_-]+\.act)$ ]]; then |
| 138 | + share_id="${BASH_REMATCH[1]}" |
| 139 | + echo "🔗 Fetching shared graph: $share_id" |
| 140 | + |
| 141 | + graph_tmp=$(mktemp -t "actrun-shared-XXXXXX.act") |
| 142 | + trap "rm -rf '$TMP_DIR'; rm -f '$graph_tmp'" EXIT |
| 143 | + |
| 144 | + if ! curl -fsSL "${SHARE_API_URL}?id=${share_id}" -o "$graph_tmp"; then |
| 145 | + echo "❌ Failed to fetch shared graph: $share_id" >&2 |
| 146 | + exit 1 |
| 147 | + fi |
| 148 | + |
| 149 | + shift |
| 150 | + exec "$CACHED_BINARY" "$graph_tmp" "$@" |
| 151 | +fi |
| 152 | + |
| 153 | +exec "$CACHED_BINARY" "$@" |
0 commit comments