Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
435 views
in Technique[技术] by (71.8m points)

Github Actions copy only changed files after .Net publish

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.

question from:https://stackoverflow.com/questions/65856453/github-actions-copy-only-changed-files-after-net-publish

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
    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 5x faster than what I had previously.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...