我正在尝试实现一个 GitHub 操作,将我的存储库文件 SCP 发送到服务器并推送到主分支。我在 Bitbucket Pipelines 上有类似的设置,但现在我正在学习使用 GitHub 操作来完成此操作,我没有任何运气。
我的项目是一个简单的 Node.js 应用程序,我想简单地将所有文件 scp 到服务器,然后在新文件复制到服务器后,我将运行一个 post-scp 脚本到
npm i
。只是想在学习时让事情变得简单。
我正在使用scp-files 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 job
和Build 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.
================================================
不幸的是,在验证服务器上的文件后,没有对其进行任何更改。有什么想法吗?
希望这有帮助!
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"
uses: actions/checkout@v4