Bubinga
Bubinga

Reputation: 703

Github Actions .Net Setup Transfer

I have a CI workflow on github that is meant to copy and deploy my code to a remote server. However, when I adjust a single file, it copies over every single file, not just the ones that changed. My workflow is as follows:

name: CI

on:
  workflow_dispatch:
  push:
    branches:
    - release    

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: '5.0.x'
    - name: Dotnet Publish
      run: dotnet publish . -c Release -o deploy
    - name: Copy via ssh
      uses: garygrossgarten/github-action-scp@release
      with:
        local: /home/runner/work/Repo-Name/Project-Name/deploy/
        remote: ${{ secrets.REMOTE_TARGET }}
        host: ${{ secrets.REMOTE_HOST }}
        username: ${{ secrets.REMOTE_USER }}
        privateKey: ${{ secrets.REMOTE_SSH_KEY }}
    - name: Run SSH command
      uses: garygrossgarten/github-action-ssh@release
      with:
        command: sudo systemctl restart project-name
        host: ${{ secrets.REMOTE_HOST }}
        username: ${{ secrets.REMOTE_USER }}
        privateKey: ${{ secrets.REMOTE_SSH_KEY }}

I've seen ways to get only the changed files from the github repo, but not how to get the changed files after a publish. If it helps, the extra stuff that rarely changes is roughly split between Dependency packages, and JS files. With ~400 files to copy, removing those two sets alone would bring me down to only ~30 files.

Upvotes: 0

Views: 835

Answers (2)

Bubinga
Bubinga

Reputation: 703

    steps:
    - uses: actions/checkout@v1
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: '5.0.x'
    - name: Dotnet Publish
      run: dotnet publish . -c Release -o deploy
    - name: Copy files via ssh rsync
      uses: trendyminds/github-actions-rsync@master
      with:
        RSYNC_OPTIONS: -avzr --delete --exclude node_modules --exclude '.git*'
        RSYNC_TARGET: ${{ secrets.REMOTE_TARGET }}
        RSYNC_SOURCE: /deploy/
      env:
        SSH_PRIVATE_KEY: ${{ secrets.REMOTE_SSH_KEY }}
        SSH_USERNAME: ${{ secrets.REMOTE_USER }}
        SSH_HOSTNAME: ${{ secrets.REMOTE_HOST }}   
    - name: Run SSH command
      uses: garygrossgarten/github-action-ssh@release
      with:
        command: sudo systemctl restart project-name
        host: ${{ secrets.REMOTE_HOST }}
        username: ${{ secrets.REMOTE_USER }}
        privateKey: ${{ secrets.REMOTE_SSH_KEY }}

I ended up using this action which is at least 15x faster than what I had previously.

Upvotes: 0

Rajesh Goyal
Rajesh Goyal

Reputation: 149

You should consider using https://github.com/easingthemes/ssh-deploy GitHub Actions. This action deploys code with rsync over ssh.

Example usage in workflow

name: Node CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Install Node.js
      uses: actions/setup-node@v1
      with:
        node-version: '10.x'
    - name: Install npm dependencies
      run: npm install
    - name: Run build task
      run: npm run build --if-present
    - name: Deploy to Server
      uses: easingthemes/[email protected]
      env:
          SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }}
          ARGS: "-rltgoDzvO --delete"
          SOURCE: "dist/"
          REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
          REMOTE_USER: ${{ secrets.REMOTE_USER }}
          TARGET: ${{ secrets.REMOTE_TARGET }}

Upvotes: 1

Related Questions