feat: add nvm setup script for CI runners
All checks were successful
poll-upstream / check (push) Successful in 1s
All checks were successful
poll-upstream / check (push) Successful in 1s
Installs nvm, Node.js LTS, and creates a stable symlink at ~/.nvm/default_bin for the systemd PATH so actions/checkout@v4 can find node without sourcing .bashrc. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
54
script/setup/nvm.sh
Executable file
54
script/setup/nvm.sh
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env bash
|
||||
# Set up nvm and a stable default Node.js for a gitea_runner user on a CI runner.
|
||||
#
|
||||
# Usage: ./script/setup/nvm.sh <runner-host>
|
||||
#
|
||||
# This script:
|
||||
# 1. Installs nvm for the gitea_runner user (if not already present)
|
||||
# 2. Installs the current Node.js LTS version
|
||||
# 3. Creates a stable symlink at ~/.nvm/default_bin pointing to the
|
||||
# default node binary directory
|
||||
# 4. Prints the systemd Environment line needed for the runner unit
|
||||
#
|
||||
# After running, add the following to the runner's systemd unit
|
||||
# (/etc/systemd/system/gitea-action-runner.service):
|
||||
#
|
||||
# Environment=PATH=/var/lib/gitea_runner/.nvm/default_bin:/usr/local/sbin:/usr/local/bin:/usr/bin
|
||||
#
|
||||
# Then: sudo systemctl daemon-reload && sudo systemctl restart gitea-action-runner
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
runner_host="${1:?usage: $0 <runner-host>}"
|
||||
runner_user="gitea_runner"
|
||||
|
||||
echo "installing nvm on ${runner_host} for ${runner_user}..."
|
||||
ssh "${runner_host}" "sudo -u ${runner_user} bash -c '
|
||||
export NVM_DIR=\"\${HOME}/.nvm\"
|
||||
if [ -s \"\${NVM_DIR}/nvm.sh\" ]; then
|
||||
echo \"nvm already installed at \${NVM_DIR}\"
|
||||
else
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
|
||||
fi
|
||||
'"
|
||||
|
||||
echo "installing Node.js LTS and creating stable symlink..."
|
||||
ssh "${runner_host}" "sudo -u ${runner_user} bash -c '
|
||||
export NVM_DIR=\"\${HOME}/.nvm\"
|
||||
. \"\${NVM_DIR}/nvm.sh\"
|
||||
nvm install --lts
|
||||
nvm alias default lts/*
|
||||
ln -sfn \"\$(dirname \"\$(nvm which default)\")\" \"\${NVM_DIR}/default_bin\"
|
||||
echo \"node: \$(node --version)\"
|
||||
echo \"symlink: \$(readlink -f \"\${NVM_DIR}/default_bin\")\"
|
||||
'"
|
||||
|
||||
echo ""
|
||||
echo "add the following to /etc/systemd/system/gitea-action-runner.service on ${runner_host}:"
|
||||
echo ""
|
||||
echo " Environment=PATH=/var/lib/${runner_user}/.nvm/default_bin:/usr/local/sbin:/usr/local/bin:/usr/bin"
|
||||
echo ""
|
||||
echo "then run:"
|
||||
echo " ssh ${runner_host} 'sudo systemctl daemon-reload && sudo systemctl restart gitea-action-runner'"
|
||||
echo ""
|
||||
echo "also add 'nvm' to the runner's labels in /etc/act_runner/config.yml"
|
||||
Reference in New Issue
Block a user