ci: deploy from source checkout on vps
This commit is contained in:
parent
28c19308c1
commit
38219e98ce
54
.github/workflows/deploy.yml
vendored
54
.github/workflows/deploy.yml
vendored
@ -69,20 +69,11 @@ jobs:
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
PACKAGE="${PLUGIN_NAME}@${VERSION}"
|
PACKAGE="${PLUGIN_NAME}@${VERSION}"
|
||||||
ref="${GITHUB_REF_NAME:-release/v${VERSION}}"
|
ref="${GITHUB_REF_NAME:-release/v${VERSION}}"
|
||||||
github_spec="git+${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git#${ref}"
|
repo_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
|
||||||
if npm pack "${github_spec}" --dry-run >/dev/null 2>&1; then
|
echo "::notice::Installing ${PACKAGE} from source repo ${repo_url} ref ${ref}"
|
||||||
echo "::notice::Installing ${PACKAGE} from ${github_spec}"
|
echo "source=source" >> "$GITHUB_OUTPUT"
|
||||||
echo "source=github" >> "$GITHUB_OUTPUT"
|
echo "install_ref=${ref}" >> "$GITHUB_OUTPUT"
|
||||||
echo "install_spec=${github_spec}" >> "$GITHUB_OUTPUT"
|
echo "install_spec=${repo_url}" >> "$GITHUB_OUTPUT"
|
||||||
elif npm view "${PACKAGE}" version >/dev/null 2>&1; then
|
|
||||||
PUBLISHED="$(npm view "${PACKAGE}" version)"
|
|
||||||
echo "::warning::Could not package ${github_spec}; falling back to npm ${PLUGIN_NAME}@${PUBLISHED}"
|
|
||||||
echo "source=npm" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "install_spec=${PACKAGE}" >> "$GITHUB_OUTPUT"
|
|
||||||
else
|
|
||||||
echo "::error::Could not package ${github_spec}, and ${PACKAGE} is not published to npm."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Configure SSH key
|
- name: Configure SSH key
|
||||||
env:
|
env:
|
||||||
@ -111,22 +102,25 @@ jobs:
|
|||||||
VERSION: ${{ steps.version.outputs.value }}
|
VERSION: ${{ steps.version.outputs.value }}
|
||||||
INSTALL_SPEC: ${{ steps.install.outputs.install_spec }}
|
INSTALL_SPEC: ${{ steps.install.outputs.install_spec }}
|
||||||
INSTALL_SOURCE: ${{ steps.install.outputs.source }}
|
INSTALL_SOURCE: ${{ steps.install.outputs.source }}
|
||||||
|
INSTALL_REF: ${{ steps.install.outputs.install_ref }}
|
||||||
FORCE: ${{ inputs.force || 'false' }}
|
FORCE: ${{ inputs.force || 'false' }}
|
||||||
run: |
|
run: |
|
||||||
ssh -i ~/.ssh/openclaw_ed25519 -o BatchMode=yes -o ServerAliveInterval=30 \
|
ssh -i ~/.ssh/openclaw_ed25519 -o BatchMode=yes -o ServerAliveInterval=30 \
|
||||||
"${SSH_HOST}" bash -s -- "${PLUGIN_NAME}" "${VERSION}" "${INSTALL_SPEC}" "${INSTALL_SOURCE}" "${FORCE}" <<'REMOTE'
|
"${SSH_HOST}" bash -s -- "${PLUGIN_NAME}" "${VERSION}" "${INSTALL_SPEC}" "${INSTALL_SOURCE}" "${INSTALL_REF}" "${FORCE}" <<'REMOTE'
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
PLUGIN_NAME="$1"
|
PLUGIN_NAME="$1"
|
||||||
VERSION="$2"
|
VERSION="$2"
|
||||||
INSTALL_SPEC="$3"
|
INSTALL_SPEC="$3"
|
||||||
INSTALL_SOURCE="$4"
|
INSTALL_SOURCE="$4"
|
||||||
FORCE="$5"
|
INSTALL_REF="$5"
|
||||||
|
FORCE="$6"
|
||||||
PACKAGE="${PLUGIN_NAME}@${VERSION}"
|
PACKAGE="${PLUGIN_NAME}@${VERSION}"
|
||||||
STATE_DIR="/tmp/openclaw-deploy"
|
STATE_DIR="/tmp/openclaw-deploy"
|
||||||
mkdir -p "${STATE_DIR}"
|
mkdir -p "${STATE_DIR}"
|
||||||
|
|
||||||
echo "==> Installing ${PACKAGE} from ${INSTALL_SOURCE} on $(hostname) (force=${FORCE})"
|
echo "==> Installing ${PACKAGE} from ${INSTALL_SOURCE} on $(hostname) (force=${FORCE})"
|
||||||
echo "==> Install spec: ${INSTALL_SPEC}"
|
echo "==> Install spec: ${INSTALL_SPEC}"
|
||||||
|
echo "==> Install ref: ${INSTALL_REF}"
|
||||||
|
|
||||||
get_installed_version() {
|
get_installed_version() {
|
||||||
node -e '
|
node -e '
|
||||||
@ -173,13 +167,31 @@ jobs:
|
|||||||
trap rollback ERR
|
trap rollback ERR
|
||||||
|
|
||||||
install_plugin() {
|
install_plugin() {
|
||||||
if [ "${INSTALL_SOURCE}" = "github" ]; then
|
global_root="$(npm root -g)"
|
||||||
|
global_target="${global_root}/${PLUGIN_NAME}"
|
||||||
|
if [ -e "${global_target}" ] && [ ! -d "${global_target}" ]; then
|
||||||
|
echo "::remote-warning::Removing invalid global package path ${global_target}"
|
||||||
|
rm -f "${global_target}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${INSTALL_SOURCE}" = "source" ]; then
|
||||||
|
SOURCE_DIR="${STATE_DIR}/source/${PLUGIN_NAME}"
|
||||||
|
rm -rf "${SOURCE_DIR}"
|
||||||
|
mkdir -p "${SOURCE_DIR}"
|
||||||
|
git -C "${SOURCE_DIR}" init
|
||||||
|
git -C "${SOURCE_DIR}" remote add origin "${INSTALL_SPEC}"
|
||||||
|
git -C "${SOURCE_DIR}" fetch --depth 1 origin "${INSTALL_REF}"
|
||||||
|
git -C "${SOURCE_DIR}" checkout --detach FETCH_HEAD
|
||||||
|
if command -v corepack >/dev/null 2>&1; then
|
||||||
|
corepack enable
|
||||||
|
corepack prepare pnpm@10.28.2 --activate
|
||||||
|
fi
|
||||||
|
pnpm --dir "${SOURCE_DIR}" install --frozen-lockfile
|
||||||
|
pnpm --dir "${SOURCE_DIR}" build
|
||||||
|
npm install -g "${SOURCE_DIR}"
|
||||||
|
elif [ "${INSTALL_SOURCE}" = "github" ]; then
|
||||||
global_root="$(npm root -g)"
|
global_root="$(npm root -g)"
|
||||||
global_target="${global_root}/${PLUGIN_NAME}"
|
global_target="${global_root}/${PLUGIN_NAME}"
|
||||||
if [ -e "${global_target}" ] && [ ! -d "${global_target}" ]; then
|
|
||||||
echo "::remote-warning::Removing invalid global package path ${global_target}"
|
|
||||||
rm -f "${global_target}"
|
|
||||||
fi
|
|
||||||
npm install -g "${INSTALL_SPEC}"
|
npm install -g "${INSTALL_SPEC}"
|
||||||
elif command -v openclaw >/dev/null 2>&1; then
|
elif command -v openclaw >/dev/null 2>&1; then
|
||||||
openclaw plugins install "${INSTALL_SPEC}" \
|
openclaw plugins install "${INSTALL_SPEC}" \
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user