Tom*_*s.R 9 git-checkout github-actions
我正在尝试将存储库从 GitHub 克隆到远程服务器。
我使用appleboy/ssh-action GitHub 操作的解决方案有效,但我被告知使用actions/checkout@v2 GitHub 操作也可以实现相同的效果。我尝试将- use: value 更改为actions/checkout@V2 ` 但代码不起作用。
我找不到任何有关如何使用actions/checkout@v2进行操作的模板。任何建议将不胜感激。
name: deploy to a server on push
on:
push:
branches: [ master ]
jobs:
deploy-to-server:
runs-on: ubuntu-latest
steps:
- uses: appleboy/ssh-action@master
with:
host: 123.132.123.132
username: tomas
key: ${{ secrets.PRIVATE_KEY }}
port: 59666
script:
git clone https://github.com/Tomas-R/website.git
Run Code Online (Sandbox Code Playgroud)
正如文档actions/checkout@v2所说
此操作会检出 $GITHUB_WORKSPACE 下的存储库,以便您的工作流程可以访问它。
steps:
- name: Checkout the repo
uses: actions/checkout@v2
with:
# This will create a directory named `my-repo` and copy the repo contents to it
# so that you can easily upload it to your remote server
path: my-repo
Run Code Online (Sandbox Code Playgroud)
要将这个签出的存储库复制到远程服务器,您可以使用scp如下命令。
# Runs a set of commands using the runners shell
- name: Upload repo to remote server
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add - <<< "${{ secrets.PRIVATE_KEY }}"
scp -o StrictHostKeyChecking=no -r -P 59666 my-repo tomas@123.132.123.132:/target/directory
Run Code Online (Sandbox Code Playgroud)
通过使用上面的命令我们,
ssh-agent并将其绑定到已知位置。my-repo到远程服务器上的目标目录。这样,私钥就永远不会被写入磁盘/被暴露。
还有另一种更简单的方法可以scp使用“通过 ssh 复制GitHub”操作来运行。
- name: Copy folder content recursively to remote
uses: garygrossgarten/github-action-scp@release
with:
local: my-repo
remote: ~/target/directory
host: 123.132.123.132
port: 59666
username: tomas
privateKey: ${{secrets.PRIVATE_KEY}}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13672 次 |
| 最近记录: |