From 6cd4f0cace8607947c1e20c77a39ed09f7259069 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 9 Apr 2023 18:10:17 +0800 Subject: [PATCH] ci: add automated deployment for changed files (#105) - Add a new job `changes` to the `ci.yml` file - Copy changed files to a server in the `changes` job - Add a YAML code block to the `README.md` file fix https://github.com/appleboy/scp-action/issues/73 --- .github/workflows/ci.yml | 24 ++++++++++++++++++++++++ README.md | 28 ++++++++++++++++++++++++++++ tests/a.txt | 1 + tests/b.txt | 1 + tests/c.txt | 2 ++ tests/d.txt | 2 ++ 6 files changed, 58 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 56839fd..516a8ab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -113,3 +113,27 @@ jobs: port: ${{ secrets.PORT }} source: distfiles/* target: test + + changes: + name: test changed-files + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v35 + with: + since_last_remote_commit: true + separator: "," + + - name: copy file to server + uses: ./ + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.KEY }} + port: ${{ secrets.PORT }} + source: ${{ steps.changed-files.outputs.all_changed_files }} + target: test diff --git a/README.md b/README.md index 55b1d3d..9692c1d 100644 --- a/README.md +++ b/README.md @@ -251,6 +251,34 @@ Remove the specified number of leading path elements: strip_components: 1 ``` +Only copy files that are newer than the corresponding destination files: + +```yaml + changes: + name: test changed-files + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v35 + with: + since_last_remote_commit: true + separator: "," + + - name: copy file to server + uses: appleboy/scp-action@master + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.KEY }} + port: ${{ secrets.PORT }} + source: ${{ steps.changed-files.outputs.all_changed_files }} + target: test +``` + Old target structure: ```sh diff --git a/tests/a.txt b/tests/a.txt index 257cc56..4f6c252 100644 --- a/tests/a.txt +++ b/tests/a.txt @@ -1 +1,2 @@ foo +foobar diff --git a/tests/b.txt b/tests/b.txt index 5716ca5..c494264 100644 --- a/tests/b.txt +++ b/tests/b.txt @@ -1 +1,2 @@ bar +foobar diff --git a/tests/c.txt b/tests/c.txt index f2ad6c7..06cab46 100644 --- a/tests/c.txt +++ b/tests/c.txt @@ -1 +1,3 @@ c +foobar +test1234 diff --git a/tests/d.txt b/tests/d.txt index 4bcfe98..13a80d9 100644 --- a/tests/d.txt +++ b/tests/d.txt @@ -1 +1,3 @@ d +foobar +foobar