我想用GitHub actions去做CI/CD,主要做的事情很簡單,只有gut push和npm install,但卻不盡人意,在actions讀取到執行npm install的時候,會出現npm command not found,我想原因是出在我的VPS設定上面,我們就一起來看下面解Bug的過程吧。
本系列所分享的bug實在太雷所以分2篇寫解法,分別是我在網路上找到鄉民寫的類似問題的解法,以及後期我自行去挖掘真相後自己的解法
https://github.com/animetosho/Nyuu/issues/14
$ which npm
which指令会在环境变量$PATH设置的目录里查找符合条件的文件。所以echo $PATH也可以從~/.bashrc環境變數中拿到一樣的絕對路徑
/usr/bin/env: ‘node’: No such file or directory
原因是因為在OS上Debian呼叫"nodejs"替代"node",而Ubuntu相反,所以我們在VPS下指令做軟連結讓nodejs=node
$ ln -s /usr/bin/nodejs /usr/bin/node
得到同樣錯誤訊息:
/usr/bin/env: ‘node’: No such file or directory
$ sudo apt-get install nodejs-legacy
跑出錯誤訊息:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package nodejs-legacy is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
nodejs
E: Package 'nodejs-legacy' has no installation candidate
提示我們把nodejs-legacy改成nodejs
sudo apt-get install nodejs
name: CI
on: [push]
jobs:
build:
runs-on: self-hosted
strategy:
matrix:
node-version: [10.15.3]
steps:
- uses: actions/checkout@v2
- name: decrypt
run: |
gpg --quiet --batch --yes --decrypt --passphrase="$PASSPHRASE" \
--output $HOME/secrets/key google_compute_engine.gpg
env:
PASSPHRASE: ${{ secrets.PASSPHRASE }}
- name: chmod
run: chmod 600 $HOME/secrets/key
- name: ssh
run: ssh -o StrictHostKeyChecking=no -i $HOME/secrets/key zen_master@35.187.152.88 "cd postmark-side-project/;git pull;sudo /home/zen_master/.nvm/versions/node/v10.15.3/bin/npm install"