feat(release): add portable packaging and release workflow

This commit is contained in:
Andrew Emelyaneko
2026-10-31 23:40:20 +03:00
parent 0e297dc523
commit 61bd3e856d
5 changed files with 222 additions and 1 deletions
+48
View File
@@ -0,0 +1,48 @@
name: Release Candidates
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
version:
description: "Package version (without leading v)"
required: true
default: "0.1.0"
jobs:
linux-package:
runs-on: docker
steps:
- name: Checkout code
env:
CI_TOKEN: ${{ secrets.CI_TOKEN }}
run: |
git clone "http://${CI_TOKEN}@10.8.0.52:8080/andrew/plagin_tokens.git" src
cd src
- name: Setup Bun
run: |
bun --version || true
- name: Verify
working-directory: src/plagin_tokens
run: |
bun install
bun test
bun run typecheck
- name: Build source, Linux and source packages
working-directory: src/plagin_tokens
run: |
VERSION=${{ github.event.inputs.version || '0.1.0' }} ./release/package.sh
# macOS package needs a self-hosted macOS runner with label "macos".
macos-package:
if: false
runs-on: [macos, self-hosted]
steps:
- name: Build DMG
run: |
echo "Enable when a self-hosted macOS runner is available."
+2
View File
@@ -2,3 +2,5 @@ node_modules/
dist/
*.log
.DS_Store
_release/
+2 -1
View File
@@ -8,7 +8,8 @@
"scripts": {
"test": "bun test",
"typecheck": "tsc --noEmit",
"build": "bun build src/plugin.ts --target bun --outfile dist/plugin.js && cp -r src/overlay dist/overlay"
"build": "bun build src/plugin.ts --target bun --outfile dist/plugin.js && cp -r src/overlay dist/overlay",
"release": "bash release/package.sh"
},
"devDependencies": {
"@opencode-ai/plugin": "1.18.32",
+7
View File
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail
TARGET="$HOME/.config/opencode/plugins/plagin-tokens.ts"
mkdir -p "$(dirname "$TARGET")"
ln -sfn /opt/plagin-tokens/src/plugin.ts "$TARGET"
echo "Installed opencode plugin: $TARGET -> /opt/plagin-tokens/src/plugin.ts"
+163
View File
@@ -0,0 +1,163 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
REPO_ROOT="$(git -C "$ROOT" rev-parse --show-toplevel)"
PLUGIN_DIR="$REPO_ROOT/plagin_tokens"
VERSION="${VERSION:-}"
if [[ -z "${VERSION}" ]]; then
VERSION="$(sed -n 's/.*"version":[[:space:]]*"\([^"]*\)".*/\1/p' "$PLUGIN_DIR/package.json" | head -n 1)"
fi
if [[ -z "${VERSION}" ]]; then
echo "Could not determine package version" >&2
exit 1
fi
OS_NAME="$(uname -s)"
RELEASE_DIR="$PLUGIN_DIR/_release/$VERSION"
BASE_NAME="plagin-tokens-${VERSION}"
DEB_NAME="plagin-tokens_${VERSION}_all.deb"
ARCHIVE_NAME="${BASE_NAME}.tar.gz"
DMG_NAME="${BASE_NAME}.dmg"
rm -rf "$RELEASE_DIR"
mkdir -p "$RELEASE_DIR"
echo "Verifying TypeScript/Bun..."
(cd "$PLUGIN_DIR" && bun install --frozen-lockfile >/dev/null 2>&1 || bun install)
(cd "$PLUGIN_DIR" && bun test && bun run typecheck)
echo "Preparing source staging directory..."
SOURCE_STAGE="$RELEASE_DIR/${BASE_NAME}"
SOURCE_TMP="$RELEASE_DIR/.source-tree"
rm -rf "$SOURCE_TMP" "$SOURCE_STAGE"
mkdir -p "$SOURCE_TMP" "$SOURCE_STAGE"
git -C "$REPO_ROOT" archive --format=tar HEAD -- plagin_tokens \
| tar -C "$SOURCE_TMP" -xf -
if [[ ! -d "$SOURCE_TMP/plagin_tokens" ]]; then
echo "Expected plagin_tokens directory not found in git archive" >&2
exit 1
fi
mv "$SOURCE_TMP/plagin_tokens"/* "$SOURCE_STAGE"/
rm -rf "$SOURCE_TMP"
mkdir -p "$SOURCE_STAGE/release"
install -m 0755 "$ROOT/release/install-opencode-plugin.sh" "$SOURCE_STAGE/release/"
echo "Building ${ARCHIVE_NAME}..."
tar -C "$RELEASE_DIR" -czf "$RELEASE_DIR/$ARCHIVE_NAME" "$(basename "$SOURCE_STAGE")"
# Create a Debian-compatible all-architecture package wrapper.
echo "Building ${DEB_NAME}..."
DEB_ROOT="$RELEASE_DIR/deb/plagin-tokens_${VERSION}_all"
rm -rf "$DEB_ROOT"
mkdir -p "$DEB_ROOT/DEBIAN"
mkdir -p "$DEB_ROOT/opt/plagin-tokens"
mkdir -p "$DEB_ROOT/usr/local/bin"
mkdir -p "$DEB_ROOT/usr/share/doc/plagin-tokens"
mkdir -p "$DEB_ROOT/etc/skel/.config/opencode/plugins"
cp -R "$SOURCE_STAGE"/. "$DEB_ROOT/opt/plagin-tokens/"
install -m 0755 "$ROOT/release/install-opencode-plugin.sh" "$DEB_ROOT/usr/local/bin/plagin-tokens-install"
install -m 0644 "$PLUGIN_DIR/README.md" "$DEB_ROOT/usr/share/doc/plagin-tokens/README.md"
ln -sf /opt/plagin-tokens/src/plugin.ts \
"$DEB_ROOT/etc/skel/.config/opencode/plugins/plagin-tokens.ts"
INSTALLED_SIZE_KB="$(du -sk "$DEB_ROOT" | cut -f1)"
cat > "$DEB_ROOT/DEBIAN/control" <<EOF
Package: plagin-tokens
Version: ${VERSION}
Section: utils
Priority: optional
Architecture: all
Maintainer: Andrew Emelyanenko <andrew@gitea.andre-y-ru.ru>
Installed-Size: ${INSTALLED_SIZE_KB}
Homepage: https://gitea.andre-y-ru.ru/andrew/plagin_tokens
Description: Live token speed indicator for opencode web
This plugin tracks opencode's streaming responses, exposes token throughput
via a local HTTP server, and provides a floating macOS HUD and static
overlay. Run plagin-tokens-install after package installation.
EOF
cat > "$DEB_ROOT/DEBIAN/postinst" <<'EOF'
#!/bin/sh
set -e
chmod 0755 /usr/local/bin/plagin-tokens-install
echo "plagin-tokens is installed; run plagin-tokens-install as a normal user."
EOF
chmod 0755 "$DEB_ROOT/DEBIAN/postinst"
printf '%s\n' '2.0' > "$RELEASE_DIR/debian-binary"
cat > "$RELEASE_DIR/control-file-list.txt" <<'EOF'
control
postinst
EOF
# Build control archive.
tar -C "$DEB_ROOT/DEBIAN" -czf "$RELEASE_DIR/control.tar.gz" control postinst
# Build a deterministic-ish data archive excluding DEBIAN.
(cd "$DEB_ROOT" && find . -path './DEBIAN' -prune -o -type f -print -o -type l -print | sort -u > "$RELEASE_DIR/data-file-list.txt")
tar -C "$DEB_ROOT" -czf "$RELEASE_DIR/data.tar.gz" -T "$RELEASE_DIR/data-file-list.txt"
ar rc "$RELEASE_DIR/$DEB_NAME" \
"$RELEASE_DIR/debian-binary" \
"$RELEASE_DIR/control.tar.gz" \
"$RELEASE_DIR/data.tar.gz"
# macOS-specific package imaging.
if [[ "$OS_NAME" == "Darwin" ]]; then
echo "Building ${DMG_NAME}..."
DMG_ROOT="$RELEASE_DIR/dmg"
rm -rf "$DMG_ROOT"
mkdir -p "$DMG_ROOT/plagin-tokens"
cp -R "$SOURCE_STAGE"/. "$DMG_ROOT/plagin-tokens/"
cat > "$DMG_ROOT/INSTALL.command" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
SOURCE_DIR="$ROOT/plagin-tokens"
OPT_TARGET="/opt/plagin-tokens"
USER_CONFIG="$HOME/.config/opencode/plugins"
TARGET="$USER_CONFIG/plagin-tokens.ts"
if [[ ! -d "$SOURCE_DIR" ]]; then
echo "plagin-tokens source directory is not found in the mounted image" >&2
exit 1
fi
if [[ ! -d "$OPT_TARGET" ]]; then
sudo mkdir -p "/opt"
sudo rm -rf "$OPT_TARGET"
sudo cp -R "$SOURCE_DIR" "$OPT_TARGET"
else
sudo rm -rf "$OPT_TARGET"
sudo cp -R "$SOURCE_DIR" "$OPT_TARGET"
fi
mkdir -p "$USER_CONFIG"
rm -f "$TARGET"
ln -s "$OPT_TARGET/src/plugin.ts" "$TARGET"
echo "Installed OpenCode plugin at:"
echo " $TARGET -> $OPT_TARGET/src/plugin.ts"
echo "Restart opencode to load the plugin."
EOF
chmod 0755 "$DMG_ROOT/INSTALL.command"
rm -f "$RELEASE_DIR/$DMG_NAME"
hdiutil create \
-srcfolder "$DMG_ROOT" \
-volname "plagin-tokens-${VERSION}" \
-format UDZO \
-fs HFS+ \
"$RELEASE_DIR/$DMG_NAME" >/dev/null
fi
echo "Products:"
find "$RELEASE_DIR" -maxdepth 1 -type f -name 'plagin-tokens*' -print