build: node install condition #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: EC2 Command Execution | |
on: [push] | |
jobs: | |
execute-command: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Node.js 18 | |
uses: actions/setup-node@v2 | |
with: | |
node-version: 18 | |
- name: Execute commands on EC2 | |
env: | |
HOST: ${{ secrets.HOST }} | |
USERNAME: ${{ secrets.USERNAME }} | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
run: | | |
mkdir -p ~/.ssh | |
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
ssh-keyscan -H "$HOST" >> ~/.ssh/known_hosts | |
ssh -o StrictHostKeyChecking=no $USERNAME@$HOST << EOF | |
INSTALLED_NODE_VERSION=$(node -v | grep -oP 'v\K\d+') | |
REQUIRED_NODE_MAJOR_VERSION=18 | |
if [ -z "$INSTALLED_NODE_VERSION" ] || [ "$INSTALLED_NODE_VERSION" -lt "$REQUIRED_NODE_MAJOR_VERSION" ]; then | |
echo "Node.js version is below 18. Installing Node.js 18..." | |
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - | |
sudo apt-get install -y nodejs | |
else | |
echo "Node.js version is $INSTALLED_NODE_VERSION. No need to install." | |
fi | |
cd ~/frappe-bench/apps/erpnext | |
git pull | |
node -v | |
cd ~/frappe-bench | |
sudo kill -9 \$(sudo lsof -t -i:8000) | |
sudo kill -9 \$(sudo lsof -t -i:11000) | |
sudo kill -9 \$(sudo lsof -t -i:13000) | |
screen | |
bench start | |
EOF |