I'm trying to implement a GitHub action that will SCP my repo files to a server on a push to the master branch. I have a similar setup working on Bitbucket Pipelines, but now that I'm learning to do this with GitHub actions, I'm not having any luck.
My project is a simple Node.js app, where I would like to simply scp all the files to the server, then I will run a post-scp script to npm i once the new files are copied to the server. Just want to keep things simple while I'm learning.
I'm using the scp-files GitHub Action. Here is my file:
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/'
This action is able to complete the Set up job and Build appleboy/scp-action@master. But it errors out when it runs appleboy/scp-action@master. This is the error I receive:
tar: empty archive
exit status 1
tar all files into /tmp/320558105/i2yG360Zje.tar
##[error]Docker run failed with exit code 1
I'm not quite sure what I am doing wrong. Even if I change the source: './*' to a sample folder (i.e. source: app), it still gives me the same error.
Update
If I change the source: './*' to source: '.', that seems to do the trick in terms of no more GitHub action errors:
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.
================================================
Unfortunately, upon verifying the files on the server, no changes have been made to it. Any ideas why that is?
Hope this helps!
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With