我正在尝试使用以下步骤编写 github 操作工作流:
/saver
文件夹main
分支中提取更新我当前的代码是这样的
name: Deploy app
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-20.04
steps:
- name: Deploy to Digital Ocean
uses: appleboy/ssh-action@master
with:
host: ${{secrets.SSH_HOST}}
key: ${{secrets.SSH_KEY}}
username: ${{secrets.SSH_USERNAME}}
passphrase: ${{secrets.SSH_PASSPHRASE}}
script: |
cd saver
mkdir test #just to check if it connects and creates folder
- name: Checkout
uses: actions/checkout@v3
with:
ref: main
- name: Pull changes
run: git pull
- name: Install client dependencies
run: npm run client:prodinstall
- name: Build client
run: npm run client:build
- name: Install server dependencies
run: npm run server:prodinstall
- name: Install server dependencies
run: npm run server:build
正如我在日志中看到的那样,成功登录到 Digital ocean。在服务器上我看到文件夹
test
。但是 git pull 不起作用。我明白了
Run git pull
Already up to date.
但是如果我自己导航到 DO 服务器并运行 git pull 我会得到新的更改。
怎么了?
更新:
当前配置
name: Deploy app
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Executing remote ssh commands using password
uses: appleboy/[email protected]
env:
SSH_KEY: ${{ secrets.SSH_KEY }}
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
script: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa
host='github.com'
hosts="$(dig +short "$host" | grep -v '\.$' | sed -z 's|\n|,|g')$host"
ssh-keyscan -H "$hosts" > ~/.ssh/known_hosts
cd project_name
git pull origin main
pm2 restart project_name
- name: Install
run: npm run build
cat .ssh/id_rsa.pub
并把它放在https://github.com/settings/keysnano .ssh/authorized_keys
chmod 700 .ssh/authorized_keys
cat .ssh/id_rsa
当我推送 repo 时,我得到这个错误
ssh: handshake failed: ssh: unable to authenticate, attempted methods [none], no supported methods remain
如何通过 ssh 运行它?
您需要在
git pull
运行的命令中包含您的 appleboy/ssh-action@master
。
这意味着该动作的
script
部分应该包括一个cd /path/to/repository
和git pull
。
对于 SSH URL,这意味着您需要将私钥复制到 GitHub 秘密(例如:
SSH_PRIVATE_KEY
)并将其设置为工作流程文件中的环境变量。- name: Executing remote ssh commands using password
uses: appleboy/[email protected]
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
port: ${{ secrets.PORT }}
script: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
host='github.com'
hosts="$(dig +short "$host" | grep -v '\.$' | sed -z 's|\n|,|g')$host"
ssh-keyscan -H "$hosts" > ~/.ssh/known_hosts
git pull origin main