如何使用GitHub操作SCP回购文件



我正在尝试实现一个GitHub操作,该操作将把我的回购文件SCP到推送到主分支的服务器上。我在Bitbucket Pipelines上也有类似的设置,但现在我正在学习用GitHub操作来做这件事,我运气不好。

我的项目是一个简单的Node.js应用程序,我想简单地将所有文件scp到服务器,然后在新文件复制到服务器后,我将运行一个后scp脚本到npm i。我只是想在学习的时候保持简单。

我正在使用scp文件GitHub Action。这是我的文件:

name: Deploy to production
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
deploy:
name: SCP files to server
runs-on: ubuntu-latest
steps:
- name: SCP files via ssh key
uses: appleboy/scp-action@master
env:
USERNAME: ${{ secrets.USERNAME }}
HOST: ${{ secrets.HOST }}
KEY: ${{ secrets.SSH_DEPLOYMENT_KEY }}
with:
source: './*'
target: '/home/ubuntu/flatbread/'

该动作能够完成Set up jobBuild appleboy/scp-action@master。但它在运行appleboy/scp-action@master时出错。这是我收到的错误:

tar: empty archive
exit status 1
tar all files into /tmp/320558105/i2yG360Zje.tar
##[error]Docker run failed with exit code 1

我不太清楚我做错了什么。即使我将source: './*'更改为示例文件夹(即source: app(,它仍然会给我同样的错误。


更新

如果我将source: './*'更改为source: '.',那么似乎就不会再有GitHub操作错误了:

tar all files into /tmp/719605837/1uYygkf4Vn.tar
scp file to server.
create folder /home/***/flatbread/
untar file 1uYygkf4Vn.tar
remove file 1uYygkf4Vn.tar
================================================
Successfully executed transfer data to all host.
================================================

不幸的是,在验证服务器上的文件后,没有对其进行任何更改。有什么想法吗?

希望这能有所帮助!

  • 首先在您的repo外部创建一个文件夹
  • 然后将所有回购内容复制到其中
  • 然后你把它涂上焦油
  • 上载到服务器
name: CI
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
mkdir ../build
cp -TR . ../build
tar -cvf deploy.tar ../build/
- name: copy file via ssh password
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
source: "deploy.tar"
target: "destination/folder"

相关内容

  • 没有找到相关文章

最新更新